For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
How to send orders to Binance
-
Re: Anyone use backtrader to do live trading on Bitcoin exchange?
Hi guys,
Does anyone know how to send buy orders to Binance successfully?
Streaming prices from Binance works like a charm but for some reason Binance does not seem to do anything with my private API, required for sending orders.
My code:
cerebro = bt.Cerebro() broker_config = { 'apiKey': '*******************', 'secret': '*******************', 'nonce': lambda: str(int(time.time() * 1000)) } broker = bt.brokers.CCXTBroker(exchange='binance', currency='USDT', config=broker_config) cerebro.setbroker(broker) hist_start_date = datetime.utcnow() - timedelta(minutes=3) feed = bt.feeds.CCXT(exchange='binance', symbol='ETH/USDT', name='eth_usdt_min', timeframe=bt.TimeFrame.Minutes, fromdate=hist_start_date, compression=1, ohlcv_limit=99999 # required to make calls to binance exchange work ) cerebro = bt.Cerebro() cerebro.adddata(feed) cerebro.addstrategy(strategy=TestStrategy, **params) backtest = cerebro.run()
Running this code with a very simpe TestStrategy that contains a self.buy() returns this:
START ***** NEXT: 2018-03-29 08:32:00 Symbol: eth_usdt_min Open: 415.71 High: 415.98 Low: 415.09 Close: 415.09 Volume: 89.91961 Minute 3 ***** NEXT: 2018-03-29 08:33:00 Symbol: eth_usdt_min Open: 415.57 High: 415.71 Low: 415.57 Close: 415.71 Volume: 4.61725 Minute 4 2018-03-29 - 08:33:00, BUY! -- 0.002405523080993962 2018-03-29 - 08:34:00, ORDER SUBMITTED 2018-03-29 - 08:34:00, ORDER ACCEPTED 2018-03-29 - 08:34:00, ORDER COMPLETED
However, when I go to Binance I do not see any order executed.
It looks like there something wrong in these lines of code:
broker = bt.brokers.CCXTBroker(exchange='binance', currency='USDT', config=broker_config) cerebro.setbroker(broker)
Any suggestions how to send orders to Binance successfully?
Thanks!!
-
No one has ever met such a good question? How to solve this problem?
-
You probably want to ask in this thread, where the CCXT development was discussed