femtotrader / rabbit4mt4

Metatrader 4 / AMQP (RabbitMQ) bridge
GNU General Public License v2.0
81 stars 56 forks source link

python receive_dom_plot_pyqtgraph.py --enable_sample_mode #1

Closed OpenTrading closed 9 years ago

OpenTrading commented 9 years ago

I'm still going through the code, but I came across this:

Traceback (most recent call last): File "receive_dom_plot_pyqtgraph.py", line 263, in update_sample self.order_book_plot.update((routing_key, json_message)) File "receive_dom_plot_pyqtgraph.py", line 93, in update self.update_orderbook(data) File "receive_dom_plot_pyqtgraph.py", line 124, in update_orderbook df_all["price"] = df_all["price"].astype(float) File "/usr/lib/python2.7/site-packages/pandas/core/frame.py", line 1780, in getitem return self._getitem_column(key) File "/usr/lib/python2.7/site-packages/pandas/core/frame.py", line 1787, in _getitem_column return self._get_item_cache(key) File "/usr/lib/python2.7/site-packages/pandas/core/generic.py", line 1068, in _get_item_cache values = self._data.get(item) File "/usr/lib/python2.7/site-packages/pandas/core/internals.py", line 2849, in get loc = self.items.get_loc(item) File "/usr/lib/python2.7/site-packages/pandas/core/index.py", line 1402, in get_loc return self._engine.get_loc(_values_from_object(key)) File "pandas/index.pyx", line 134, in pandas.index.IndexEngine.get_loc (pandas/index.c:3812) File "pandas/index.pyx", line 156, in pandas.index.IndexEngine.get_loc (pandas/index.c:3749) KeyError: 'price'

femtotrader commented 9 years ago

Are you using MT4 or MT5 ?

femtotrader commented 9 years ago

DOM is MT5 only. Maybe you should have a look at df_all

print(df_all)
OpenTrading commented 9 years ago

No I'm sure that it's a pure Python error: Mt4 is not even running. I was just feeding it with rabbit4mt4/receive/Python/emit_dom.py from the command line.

femtotrader commented 9 years ago

Ok I understand. I changed message format. In sample mode it was like

{
    'orderbook':
        [['1.38276', '3000000.0', 1],
          ['1.38271', '500000.0', 1],
          ['1.38269', '1500000.0', 1],
          ['1.38267', '3500000.0', 1],
          ['1.38266', '500000.0', 1],
          ['1.38265', '15000000.0', 1],
          ['1.38264', '500000.0', 1],
          ['1.38263', '10000000.0', 1],
          ['1.38262', '3600000.0', 1],
          ['1.38261', '24000000.0', 1],
          ['1.38260', '5100000.0', 1],
          ['1.38259', '4500000.0', 1],
          ['1.38258', '9550000.0', 1],
          ['1.38257', '6250000.0', 1],
          ['1.38255', '1000000.0', 1],
          ['1.38254', '100000.0', 1],
          ['1.38246', '2000000.0', 2],
          ['1.38245', '3000000.0', 2],
          ['1.38244', '2750000.0', 2],
          ['1.38243', '14550000.0', 2],
          ['1.38242', '5500000.0', 2],
          ['1.38241', '13000000.0', 2],
          ['1.38240', '4300000.0', 2],
          ['1.38239', '11000000.0', 2],
          ['1.38238', '500000.0', 2],
          ['1.38237', '23000000.0', 2],
          ['1.38236', '500000.0', 2],
          ['1.38235', '2000000.0', 2],
          ['1.38234', '500000.0', 2],
          ['1.38233', '500000.0', 2],
          ['1.38231', '500000.0', 2],
          ['1.38229', '500000.0', 2]]
    }

but now (what MT5 is sending) looks like

{
    'ask': '1.38254',
    'bid': '1.38246',
    'last': '1.38254',
    'orderbook': {
        'price': ['1.38276', '1.38271', '1.38269', '1.38267', '1.38266', '1.38265',
             '1.38264', '1.38263', '1.38262', '1.38261', '1.38260', '1.38259',
             '1.38258', '1.38257', '1.38255', '1.38254', '1.38246', '1.38245',
             '1.38244', '1.38243', '1.38242', '1.38241', '1.38240', '1.38239',
             '1.38238', '1.38237', '1.38236', '1.38235', '1.38234', '1.38233',
             '1.38231', '1.38229'],
        'type': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
        'volume': ['3000000.0', '500000.0', '1500000.0', '3500000.0',
            '500000.0', '15000000.0', '500000.0', '10000000.0',
            '3600000.0', '24000000.0', '5100000.0', '4500000.0',
            '9550000.0', '6250000.0', '1000000.0', '100000.0',
            '2000000.0', '3000000.0', '2750000.0', '14550000.0',
            '5500000.0', '13000000.0', '4300000.0', '11000000.0',
            '500000.0', '23000000.0', '500000.0', '2000000.0',
            '500000.0', '500000.0', '500000.0', '500000.0']
    },
    'spread_points': '10',
    'unixtime_s': 1430236000,
    'volume': '1000.0'
}

so change for message_json_default = '{"unixtime_s": 1430236000, "bid": "1.38246", "ask": "1.38254", "volume": "1000.0", "last": "1.38254", "spread_points": "10", "orderbook": {"volume": ["3000000.0", "500000.0", "1500000.0", "3500000.0", "500000.0", "15000000.0", "500000.0", "10000000.0", "3600000.0", "24000000.0", "5100000.0", "4500000.0", "9550000.0", "6250000.0", "1000000.0", "100000.0", "2000000.0", "3000000.0", "2750000.0", "14550000.0", "5500000.0", "13000000.0", "4300000.0", "11000000.0", "500000.0", "23000000.0", "500000.0", "2000000.0", "500000.0", "500000.0", "500000.0", "500000.0"], "price": ["1.38276", "1.38271", "1.38269", "1.38267", "1.38266", "1.38265", "1.38264", "1.38263", "1.38262", "1.38261", "1.38260", "1.38259", "1.38258", "1.38257", "1.38255", "1.38254", "1.38246", "1.38245", "1.38244", "1.38243", "1.38242", "1.38241", "1.38240", "1.38239", "1.38238", "1.38237", "1.38236", "1.38235", "1.38234", "1.38233", "1.38231", "1.38229"], "type": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]}}'

or $ git pull

femtotrader commented 9 years ago

Please tell me if it fix isue on your side (it should)