HomeРазвлеченияRelated VideosMore From: m1xolyd1an

Programming a simple bitcoin trading bot with bitfinex API

322 ratings | 42229 views
Vid doesn't start until 17:15 minute mark! Building Bitcoin Websites Book: https://www.amazon.com/Building-Bitcoin-Websites-Beginners-Development/dp/153494544X BTC: 1NPrfWgJfkANmd1jt88A141PjhiarT8d9U Github: https://github.com/coinables/Bitfinex-API-PHP Why watch the game when you can learn to build a bitcoin web app instead?
Html code for embedding videos on your blog
Text Comments (62)
Kalli Lopitole (3 months ago)
atomatic strategy didnt work specially on exchange with big volume like bitfinex
BitTube MaSTeR (6 months ago)
this will applicable for other trading exchange api like bittrex api?
m1xolyd1an (6 months ago)
Different but similar, there are already bittrex libraries built so you don't have to do it manually like this you can go straight to providing credentials and making it calls.
WhiteSiroi (1 year ago)
OMG, thank you so much. It works perfectly.
Dang hoang (1 year ago)
Investing in binary/Forex trade can be so frustrating when you make the wrong person your account manager and investing in binary/Forex trade can also be damn sweet when you make the right person who knows and also have all it takes to be an account manager the manager of your account and the right person is Mr Williams the trade master, am making more money than i have ever made with his strategy since i made him my account manager i have no cause to regret.
Dang hoang (1 year ago)
Contact him today and i assure you of recovering all your lost [email protected]
Ilan Naftali (1 year ago)
I can't get the public market data from bitfinex, I get error 500 that says that I can't access the info I want on the server when calling the ticker, from js or php... Do you have the same issue ? How do you go around, thanks.
Albert Ryan Banez (1 year ago)
So how long did it take you to get 0 dollar??? :))
ZadrelPro (1 year ago)
Great tutorial :) I have a question for you. I am currently using "https://api.bitfinex.com/v1/pubticker/IOTBTC" to get the ticker info for IOTBTC. I am also using the same command to get Ticker info for many of the other coin pairs. if I want info on many coins I end up sending many requests to the site,. Bitfinex has a limited number of requests it will accept. My Question: Is there a way, in php, to get the ticker info for every trade pair with one request sent to the website? my code looks like this right now $getIOTBTC = json_decode(file_get_contents("https://api.bitfinex.com/v1/pubticker/IOTBTC"), true); $bidIOTBTC = $getIOTBTC['bid']; $askIOTBTC = $getIOTBTC['ask']; would I maybe have to adjust the return json from the finex.php script? I was thinking just adding more fields $ccc... but I dont know enough to know if that will work return json_decode($ccc, true); or if there are any other solutions to my problem, please share. Thanks
Ilan Naftali (1 year ago)
The bitfinex server won't even give me the infos once, how do you mange to get the datas?
Daniel Str. (1 year ago)
Hi +ZadrelPro sure, you only have to using something like the follow request with the Version 2: api.bitfinex.com/v2/tickers?symbols=tIOTBTC,tETHBTC... and so on. Then you can get all pairs with one request. ;)
Daniel Str. (1 year ago)
+m1xolyd1an nice video but i have one question regarding a new order. Do you know which is the right way to check if an order is completely and(!) successfully placed? I know there are some functions such order_status, past_trades and so on but i don't know which one is the right way. ^^ For example should i use the response of order_status and check if the original_amount matches the executed_amount or...? Big thanks for your work and i hope you can help me! :)
Zebra Trolling (1 year ago)
Thank you. I programmed the bot exactly as you said and it worked very well. Just placed a limit selling order on BTC successfully. Thanks again.
Jean-Francois Simard (1 year ago)
Hmm I bought 0.01 BTC last night. $150 Canadian.
Durotoye Oyerinde (1 year ago)
Hello Kyle, how are you? Please i noticed that placing an order only works for "exchange market" and doesn't work with "exchange limit". I have checked on the bitfinex api docs but using "exchange limit" doesn't place my order as is but gives "exchange market" instead. any thought?
Barış Çöpoğlu (1 year ago)
go drink some water dude
Sreekar Jogi (1 year ago)
i get the following error: Array ( [message] => Could not find a key matching the given X-BFX-APIKEY. )
m1xolyd1an (1 year ago)
Double check and make sure you have updated the config.php file with the correct apikey and secret.
Miguel Gomez (1 year ago)
I'm using the v2 of bitcoinaverage API, as follows: $getavg = json_decode(file_get_contents("https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD")); $avg = $getavg['ask']; // I know that avg is not avg, but I just wanted to point out the error But I'm getting the following error: Fatal error: Uncaught Error: Cannot use object of type stdClass as array The $ask = $getask['ask']; and $bid = $getask['bid']; from Bitfinex API are working correctly, the problem is with bitcoinaverage. I've tried: $getavg['ask'] and $getavg["ask"]
Olanrewaju Bello (1 year ago)
Interesting.... :)
22utoo (1 year ago)
Anyone actually have a winning bot?
Democracy Manifest (1 year ago)
Why would they? If i'm going to spend my time, writing, debugging, testing, back-testing, retesting, etc... building in support for different exchange API's, etc... that's not a small task.
Konrad Bach (1 year ago)
yeah, but noone will share it
kamal sharma (1 year ago)
sir this video help can we make bitfinax trading order form which through i do order from my website and automatic order on bitifinax website ???? for example this is trading website link https://www.bitfinex.com/trading after open this website link you will see demo button when you click demo button you can see order form on top left bar this type order form i want to make my website and do order automatic on https://www.bitfinex.com/trading/ please give suggestion sir
Igor Kroitor (2 years ago)
Hi, everyone! I am developing the ccxt cryptocurrency trading library, check it out on GitHub: https://github.com/kroitor/ccxt . With it you can access market data and trade bitcoin, ether and altcoins with more than 60 (!!!) cryptocurrency exchanges. It is used to connect and trade with crypto markets and payment processing services worldwide. It provides quick access to market data for storage, analysis, visualization, indicator development, trading strategy backtesting, bot programming, building trading algorithms on top of it, webshop integration and related software engineering. The codebase is in JavaScript / Python (2 and 3) / PHP. You can deploy it from PyPI, with npm (for Node.js) or by cloning the GitHub repository. The ccxt library is under heavy development right now, but already offers a quick-start for trading and technical analysis with many crypto exchange markets out of the box. It is intented to be used by coders, developers and financial analysts to build algotrading strategies on top of it. I am also a member of a developer team from Moscow. We are open to collaboration and available for hiring and outsourcing. Do not hesitate to contact me here on YouTube, or via GitHub if you have any questions. Your feedback, bug reports and feature requests are welcome!
Crazy Titch (1 year ago)
I love you
Retro Gamer (2 years ago)
great video haha
Jim O'Donnell (2 years ago)
I came across this vid several weeks ago as I was looking for ideas to improve my own automation. I realize it's a year and. a half old. It's still the best entry level tutorial on the topic I've seen. A few notes: 1. You are way too hard on yourself. This is a very technical hour-long demo that you have made extremely approachable for beginners. everybody typos. I have spent 10 years selling enterprise software and I would be happy to recommend you for a presales engineer role if you are ever interested. You are a natural. 2. The Denver Carolina game you were up against live was hugely disappointing. Most of the millions of viewers would have been better off joining your session and, given his lack of interest in falling on his own 4th quarter fumble, so might Cam Newton. 3. Variable names. yeah. Seriously? $data? Why not just $x, $xx, $xxx, ... you get the point. use a standard naming convention with a type prefix and meaningful purpose: $a_requesthdr, $s_nonce. 4. Speaking of nonce... speed counts. unfortunately php sucks in this regard. For nonce the key is you need an integer that is higher than the one passes in your last request. timestamps work great on solid servers in java or c++, but PHP is a little bitchy. microtime returns EITHER a microsecond precision string or a second precision float. To make it worse, if the server time is network base, there can be significant wobble in the system_time--like minutes. again, API is honey badger and doesn't have fucks to give about how you derive your nonce. also, again, for trading applications, speed matters. So define however many nonce variables you need as globals--at least one for each currency pair per exchange you are monitoring. for security, initialize these to a millisecond timestamp exactly as you have. thereafter, just increment them for each private request: $i_bitfin_ltc_nonce++ This is much faster and 100% reliable. Just remember to define the globals in your functions. I know globals suck, but as your frequency increases, you need to optimize. 5. Trading: Limit orders are cheaper but may not close. Market orders will close, but you likely won't get the price you planned on. Use limit fill or kill or implement your own order timeout. 6. Every API can provide you real time price aggregates from the public API. Ditch the third party service and interrogate the exchanges directly. 7. monitor latency and set a threshold. Coinbase/GDAX has flipped out dozens of times under high load in the past month. This occurred during the flash crash last week. If you'd placed a market order with 3 or 4 second latency, you might have awakened to see your expected $283 Ethereum sale filled at $0.14. Total bummer. If your heartbeat or price requests drop to a multiple of average latency, shut down. That's all I've got. Brilliant work!
Jim O'Donnell (1 year ago)
I don't think I really did. I mean, he's got everything you need to understand and test it here. I'm not a fan of the actual trading strategy--he'd have been buying this dip all the way down from 4600 to 3800 unless he ran out of cash. I generally monitor multiple exchanges for a difference in the price. If that is over about 3%, I place offsetting trades. That's been effective, although the number of bots in the space now means that the exchanges tend to be held to a pretty tight margin.
Eric Miller (1 year ago)
Have you found any other guides that you can point me to?
m1xolyd1an (2 years ago)
Jim O'Donnell thanks for the valuable feedback!
Durotoye Oyerinde (2 years ago)
Alright Kyle, I will be on the look out. Thank you in advance
m1xolyd1an (2 years ago)
Here you go! https://www.youtube.com/watch?v=K0lDTK3D-74
Durotoye Oyerinde (2 years ago)
Hello Kyle, your tutorial is so helpful and powerful. Can you pls put me through on how to adapt this to bittrex API. Thank you
m1xolyd1an (2 years ago)
+Durotoye Oyerinde thanks for the suggestion, I will try to do a video on bittrex soon
Ling talfi (2 years ago)
How much money do you make per day with such a bot?
Mestre Shao (2 years ago)
Olá, muito maneiro seu canal e quero pedir licença para compartilhar este meu vídeo de Coaching Financeiro. https://www.youtube.com/watch?v=tmdSjhjv5X8&t=21s https://www.youtube.com/watch?v=RxZxGhGiey8 Muita Abundância, Sucesso e Saúde.
Jim O'Donnell (2 years ago)
This is really great content! What I'd suggest you think about is opening accounts on multiple exchanges (not Bitfinex currently because you can't get money in there) and look for arbitrage opportunities that beat the fees. So, say, price of btc on GDAX is 1351.31 and on gemini is 1332.84. If there's money in both accounts, you can place nearly simultaneous sell on GDAX and buy on Gem. You'll need to use a bit of judgement, perhaps give up a couple pennies to ensure you close if you use limit orders (which you should). Your net gain will be the difference between the two exchanges less fees. Nice thing is, you need not just loop on BTC/USD. You can also monitor ETH/USD and ETH/BTC.
Jim O'Donnell (2 years ago)
Yas, I do this several times a day. It's a very common trading practice. I don't trade my entire balance, so it simply augments my longer term strategy. Admittedly, I have automated the process and opportunities are shorter-lived than before the Asian invasion on US exchanges last month, but a 2% arb will more than cover transaction and exchange fees. I initially felt that USD arbs were constructive because I started with ach deposits which are limited to small amounts, but it's easy enough after a few weeks in a volatile market to identify straight trades that convert paper gains. Also, I don't trade on margin, but I use margin accounts because they enable proper shorts. If your buy order is cash and your sell order is a short sell, you can set a pair of limit orders that is effectively market neutral and eliminates exchange taker fees. Since I'm not trading the whole balance in any exchange, I generally close my positions out end of day (flat is where it's at) and rebalance manually one time. I've put a spreadsheet that uses only open API calls (no account necessary) and demonstrates this here: http://discerniblyturgid.blogspot.com/2017/05/cryptocoin-arbitrage-excel-tool.html?m=1 cheers jim
Yas (2 years ago)
To be effective you'll have to send your btc between gdax and gemini and have the cost of blockchain fees and 30mn minimum to receive your tokens so it is useless...
Tine Pezdic (2 years ago)
Hello, very good video, but i have an error: Array ( [message] => Must specify a 'request' field in the payload that matches the URL path. ) what i'm doing wrong thanks for answer
Tine Pezdic (2 years ago)
thank you, i had a typing mistake.
m1xolyd1an (2 years ago)
+Tine Pezdic do you have a request parameter in your payload that matches the endpoints available? Like "/v1/order/new"
sbkyoutu (2 years ago)
Can I replace Bitfinex API with other one?
Jim O'Donnell (2 years ago)
All the exchanges provide public and private APIs as far as I have seen in at least REST and web socket. The calls are exchange specific, so you will need to build them to your exchange, but the basic operations are all there: public price and book, private balances, ordering, account transfers. Account security (roles) vary signigicantly and you want to understand this and ensure your trader cress are not authorized to transfer, but if you can understand how he's built the request payload you should be able to map pretty directly to your exchange's API. The nonce paradigm is consistent everywhere I've tried, so millisecond daytime or timestamp works. all the exchanges have sandbox endpoints, so you can test your code with test currency.
m1xolyd1an (2 years ago)
+sbkyoutu no sorry, it is specific to bitfinex.
oKuuma (2 years ago)
That's incredibly awesome. Thanks for showing. Did it work out for you yet?
Wagner-Otto Wutzke (2 years ago)
Hey, thx for sharing man! Great stuff for starters.
Ahmed Ali (2 years ago)
Hi Kyle , can u give us more examples for the functions in finex.php file ?
WhiteSiroi (1 year ago)
Ahmed Ali (2 years ago)
m1xolyd1an thanks i will check it if i want a special script for trading bitcoin website can u provide it ? can u send me ur email for more details
m1xolyd1an (2 years ago)
Ok I updated the readme on github with more examples. Let me know if that helps! https://github.com/coinables/Bitfinex-API-PHP/blob/features/README.md
Steve Skye (2 years ago)
Lots of information, thanks for the great video. :)
Canal Silence (2 years ago)
Hi, great video,i was looking for a simple bot that would keep my order at the top of the book, by addin 0,01 cent over the Highest Bid, is there a code for this somewhere? i traed at poloniex thanks
Atai Anand (3 years ago)
Thanks for this tutorial, I am now able to place and remove all types of orders! Could you please post some code on how to connect to Bitfinex' websocket in order to pull in trade information?
m1xolyd1an (3 years ago)
Websocket is better handled by real-time asynchronous langues like javascript or nodeJS. I did a video on websocket (https://www.youtube.com/watch?v=jEdfNG-eT8E). You can use the same examples in that video with bitfinex except change your request/subscribe to: someVariable.onopen = function(){ someVariable.send(JSON.stringify({"event":"subscribe", "channel":"trades", "pair":"BTCUSD"})); } For example here's a fiddle, https://jsfiddle.net/m98fd2bv/ I made that displays the latest trades.
Bennie DeWaal (3 years ago)
can you help me set mine up?
KoljaMineralka (1 year ago)
as I understand you need to train your bot. It's a good start though
Bennie DeWaal (3 years ago)
+m1xolyd1an can you explain better?
m1xolyd1an (3 years ago)
+Bennie DeWaal Not impossible, all it does is calculate if the current price is above or below the 24hr average. If it's above by at least $2 then it sells, expecting the price will return to the average; if it is below the average it does the opposite. WAMP would work to run the PHP, but you would need it to run automatically every 5 minutes or so using cron jobs, but since you're on windows perhaps the task scheduler would work (http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron)
Bennie DeWaal (3 years ago)
+m1xolyd1an sorry i just got back weight lifting. so you're saying that it's impossible for this bot to make money? dang. I have wamp installed, but why would wamp be relevant? the post you made on github is what i downloaded and tried to make money with
m1xolyd1an (3 years ago)
+Bennie DeWaal What part do you need help with? You will need to run a cron job so that the bot can run autonomously. Do you have a web server that runs PHP? It's unlikely that you would actually make money with this bot, it was more of a demonstration/tutorial on how to use Bitfinex's API in PHP.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.