Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Discussion
    3
    3
    1783
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      PiSquared last edited by

      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!!

      1 Reply Last reply Reply Quote 0
      • 黄光裕
        黄光裕 last edited by

        No one has ever met such a good question? How to solve this problem?

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators last edited by

          You probably want to ask in this thread, where the CCXT development was discussed

          • https://community.backtrader.com/topic/623/anyone-use-backtrader-to-do-live-trading-on-bitcoin-exchange
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors