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 get value from trade.history
-
Hello.
I can't figure out how to work with trade history.
When I dotrade_data['history'].to_string()
I get a dict:1 [{'status': {'status': 1, 'dt': 738415.125, 'b... 2 [{'status': {'status': 1, 'dt': 738416.8333333... 3 [{'status': {'status': 1, 'dt': 738418.4583333... 4 [{'status': {'status': 1, 'dt': 738420.0833333... 5 [{'status': {'status': 1, 'dt': 738420.5833333... 6 [{'status': {'status': 1, 'dt': 738421.0416666... 7 [{'status': {'status': 1, 'dt': 738421.7083333...
But if I try to get a value
trade_data.iloc[0]['history']
, I get a list[TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 738415.125), ('barlen', 0), ('size', -0.050256307), ('price', 19898.0), ('value', -999.999996686), ('pnl', 0.0), ('pnlcomm', -0.39999999867440006), ('tz', None)])), ('event', AutoOrderedDict([('order', <backtrader.order.SellOrder object at 0x7f7fc9d028f0>), ('size', -0.050256307), ('price', 19898.0), ('commission', 0.39999999867440006)]))]), TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 738415.25), ('barlen', 3), ('size', -0.100634395), ('price', 19873.970956808553), ('value', -2000.005043486), ('pnl', 0.0), ('pnlcomm', -0.8000020173944), ('tz', None)])), ('event', AutoOrderedDict([('order', <backtrader.order.SellOrder object at 0x7f7fc9d03010>), ('size', -0.050378088), ('price', 19850.0), ('commission', 0.40000201872)]))]), TradeHistory([('status', AutoOrderedDict([('status', 1), ('dt', 738416.0416666666), ('barlen', 22), ('size', -0.15069948), ('price', 19911.919904985738), ('value', -3000.715975483), ('pnl', 0.0), ('pnlcomm', -1.2002863901932002), ('tz', None)])), ('event', AutoOrderedDict([('order', <backtrader.order.SellOrder object at 0x7f7fc9d34040>), ('size', -0.050065085), ('price', <backtrader.linebuffer.LineBuffer object at 0x7f7fc9d701f0>), ('commission', 0.4002843727988)]))]), TradeHistory([('status', AutoOrderedDict([('status', 2), ('dt', 738416.8333333334), ('barlen', 41), ('size', 0.0), ('price', 19911.919904985738), ('value', 0.0), ('pnl', 29.600377543000118), ('pnlcomm', 27.211644913630916), ('tz', None)])), ('event', AutoOrderedDict([('order', <backtrader.order.BuyOrder object at 0x7f7fc9d35180>), ('size', 0.15069948), ('price', 19715.5), ('commission', 1.188446239176)]))])]
What am I doing wrong?
-
To get the object, you need to extract the result of command
trade_data.loc[[0]]['history'].values
twice. Like thishist = trade_data.loc[[0]]['history'].values hist = hist[0][0]