Dave-Vallance / bt-ccxt-store

Fork of Ed Bartosh's CCXT Store Work
MIT License
423 stars 187 forks source link

ccxt_order price data returns zero #18

Open tuncbb opened 5 years ago

tuncbb commented 5 years ago

I tried the fork for binance exchange. ccxt_order price info returns zero. Thus, backtrader's order.executed.price method returns zero.

Starting Portfolio Value: 0.00034142
Base strategy initialized
DELAYED
LIVE
LIVE DATA - Ready to trade
Buy ordered: $0.02 True
{'_active': True,
 '_limitoffset': 0.0,
 '_plimit': None,
 'broker': None,
 'ccxt_order': {'amount': 0.013,
                'average': 0.021913846153846155,
                'cost': 0.00028488,
                'datetime': '2019-07-30T23:33:45.185Z',
                'fee': None,
                'filled': 0.013,
                'id': '445093341',
                'info': {'clientOrderId': 'Kp9arC7BR9UZsPTQDr3J9K',
                         'cummulativeQuoteQty': '0.00028488',
                         'executedQty': '0.01300000',
                         'icebergQty': '0.00000000',
                         'isWorking': True,
                         'orderId': 445093341,
                         'origQty': '0.01300000',
                         'price': '0.00000000',
                         'side': 'BUY',
                         'status': 'FILLED',
                         'stopPrice': '0.00000000',
                         'symbol': 'ETHBTC',
                         'time': 1564529625185,
                         'timeInForce': 'GTC',
                         'type': 'MARKET',
                         'updateTime': 1564529625185},
                'lastTradeTimestamp': None,
                'price': 0.021913846153846155,
                'remaining': 0.0,
                'side': 'buy',
                'status': 'closed',
                'symbol': 'ETH/BTC',
                'timestamp': 1564529625185,
                'trades': None,
                'type': 'market'},
 'comminfo': None,
 'created': <backtrader.order.OrderData object at 0x7f7d1826c160>,
 'data': <ccxtbt.ccxtfeed.CCXTFeed object at 0x7f7d06a752b0>,
 'dteos': 737250.9999999999,
 'exectype': 0,
 'executed': <backtrader.order.OrderData object at 0x7f7d076b8c50>,
 'info': AutoOrderedDict(),
 'ordtype': 0,
 'owner': <live_strategy.bt_bandtrader_v3_trend.Strategy object at 0x7f7d06ae5f98>,
 'p': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7f7d06a75518>,
 'params': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7f7d06a75518>,
 'position': 0,
 'ref': 1,
 'size': 0.013,
 'status': 4,
 'triggered': False}
BUY EXECUTED, Price: 0.00000000, Cost: 0.00000000, Comm 0.00000000 True

I guess this bug causes the issue below. "Position variables returns zero"

ENV=  production

Starting Portfolio Value: 0.00333707
DELAYED
LIVE
{'broker': None, '_plimit': None, 'owner': <strategies.basic_rsi.BasicRSI object at 0x7fdd939dfe80>, 'params': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7fdd939df400>, 'p': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7fdd939df400>, 'info': AutoOrderedDict(), 'ref': 1, '_limitoffset': 0.0, 'position': 0, 'exectype': 0, 'ccxt_order': {'fee': None, 'trades': None, 'datetime': '2019-07-20T20:23:28.948Z', 'lastTradeTimestamp': None, 'status': 'closed', 'info': {'executedQty': '0.12300000', 'icebergQty': '0.00000000', 'price': '0.00000000', 'origQty': '0.12300000', 'orderId': 436039847, 'isWorking': True, 'status': 'FILLED', 'timeInForce': 'GTC', 'updateTime': 1563654208948, 'time': 1563654208948, 'symbol': 'ETHBTC', 'type': 'MARKET', 'clientOrderId': '3MwUQaNQMyuMzK3HyZkCv2', 'side': 'BUY', 'stopPrice': '0.00000000', 'cummulativeQuoteQty': '0.00260747'}, 'filled': 0.123, 'amount': 0.123, 'id': '436039847', 'symbol': 'ETH/BTC', 'price': 0.021198943089430895, 'remaining': 0.0, 'average': 0.021198943089430895, 'type': 'market', 'cost': 0.00260747, 'side': 'buy', 'timestamp': 1563654208948}, 'size': 0.123, 'comminfo': None, 'created': <backtrader.order.OrderData object at 0x7fdd939dfcc0>, 'data': <ccxtbt.ccxtfeed.CCXTFeed object at 0x7fdd939dfa58>, 'triggered': False, '_active': True, 'dteos': 737240.9999999999, 'executed': <backtrader.order.OrderData object at 0x7fdd9386bcc0>, 'status': 4, 'ordtype': 0}
{'broker': None, '_plimit': None, 'owner': <strategies.basic_rsi.BasicRSI object at 0x7fdd939dfe80>, 'params': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7fdd939df400>, 'p': <backtrader.metabase.AutoInfoClass_OrderBase_CCXTOrder object at 0x7fdd939df400>, 'info': AutoOrderedDict(), 'ref': 1, '_limitoffset': 0.0, 'position': 0, 'exectype': 0, 'ccxt_order': {'fee': None, 'trades': None, 'datetime': '2019-07-20T20:23:28.948Z', 'lastTradeTimestamp': None, 'status': 'closed', 'info': {'executedQty': '0.12300000', 'icebergQty': '0.00000000', 'price': '0.00000000', 'origQty': '0.12300000', 'orderId': 436039847, 'isWorking': True, 'status': 'FILLED', 'timeInForce': 'GTC', 'updateTime': 1563654208948, 'time': 1563654208948, 'symbol': 'ETHBTC', 'type': 'MARKET', 'clientOrderId': '3MwUQaNQMyuMzK3HyZkCv2', 'side': 'BUY', 'stopPrice': '0.00000000', 'cummulativeQuoteQty': '0.00260747'}, 'filled': 0.123, 'amount': 0.123, 'id': '436039847', 'symbol': 'ETH/BTC', 'price': 0.021198943089430895, 'remaining': 0.0, 'average': 0.021198943089430895, 'type': 'market', 'cost': 0.00260747, 'side': 'buy', 'timestamp': 1563654208948}, 'size': 0.123, 'comminfo': None, 'created': <backtrader.order.OrderData object at 0x7fdd939dfcc0>, 'data': <ccxtbt.ccxtfeed.CCXTFeed object at 0x7fdd939dfa58>, 'triggered': False, '_active': True, 'dteos': 737240.9999999999, 'executed': <backtrader.order.OrderData object at 0x7fdd9386bcc0>, 'status': 4, 'ordtype': 0}
Finished with error:  unsupported operand type(s) for *: 'NoneType' and 'float'
Traceback (most recent call last):
  File "/home/tunc/PycharmProjects/btlivebot/main.py", line 107, in <module>
    main()
  File "/home/tunc/PycharmProjects/btlivebot/main.py", line 92, in main
    result = cerebro.run()
  File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
  File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1298, in runstrategies
    self._runnext(runstrats)
  File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1623, in _runnext
    self._brokernotify()
  File "/usr/local/lib/python3.5/dist-packages/backtrader/cerebro.py", line 1360, in _brokernotify
    self._broker.next()
  File "/usr/local/lib/python3.5/dist-packages/ccxtbt/ccxtbroker.py", line 203, in next
    pos.update(o_order.size, o_order.price)
  File "/usr/local/lib/python3.5/dist-packages/backtrader/position.py", line 179, in update
    self.price = (self.price * oldsize + size * price) / self.size
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

Process finished with exit code 1
Dave-Vallance commented 4 years ago

I don't use Binance at the moment...

Can you provide a complete working example (minus API keys) to reproduce so I don't need to set everything up?

If so, I will take a look when I get chance. Might be a bit slow though

FredYellow commented 3 years ago

Same issue here. All buys and sells have their TradeID, Price, Cost and Comm parameters as zero:

BUY EXECUTED, Ref: 887, TradeID: 000, Size: 0.00400000000000000008, Price: 0.00000, Lvl: 0.03196, Cost: 0.00000, Comm  0.00000

SELL EXECUTED, Ref: 868, TradeID: 000, Size: -0.00400000000000000008., Price: 0.00000, Lvl: 0.03233, Cost: 0.00000, Comm  0.00000

Thus, no trades are ever registered, no analyzers work... I'll try to get a minimal example.