Matatrader5 for python, market_book_add, market_book_get not working. Please help!

 

Hello, for Metatrader5 in python, market_book_get is not working. It always print "mt5.market_book_add('EURUSD') failed, error code = (1, 'Success')".

How to solve this problem ?

Thanks

This is the script:

import MetaTrader5 as mt5
import time
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
print("")
 
# establish connection to the MetaTrader 5 terminal
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
   # shut down connection to the MetaTrader 5 terminal
    mt5.shutdown()
    quit()
 
# subscribe to market depth updates for EURUSD (Depth of Market)
if mt5.market_book_add('EURUSD'):
  # get the market depth data 10 times in a loop
   for i in range(10):
        # get the market depth content (Depth of Market)
        items = mt5.market_book_get('EURUSD')
        # display the entire market depth 'as is' in a single string
        print(items)
        # now display each order separately for more clarity
        if items:
            for it in items:
                # order content
                print(it._asdict())
        # pause for 5 seconds before the next request of the market depth data
        time.sleep(5)
  # cancel the subscription to the market depth updates (Depth of Market)
   mt5.market_book_release('EURUSD')
else:
    print("mt5.market_book_add('EURUSD') failed, error code =",mt5.last_error())
 
# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()
Documentation on MQL5: Python Integration / market_book_release
Documentation on MQL5: Python Integration / market_book_release
  • www.mql5.com
market_book_release - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Problem solved.

Hello, when I use BTCUSD the script works. May be it's because we are in weekend.

I really wanna understand more about market_book structure. thanks!

 
laiang:

Hello, for Metatrader5 in python, market_book_get is not working. It always print "mt5.market_book_add('EURUSD') failed, error code = (1, 'Success')".

How to solve this problem ?

Thanks

This is the script:

Why are thinking it's "not working" when it returns "Success" ?

There is usually not market book orders for Forex symbols. Some brokers provide it for their own market book which is only a small part of the real market.

 

Thank you! I change the broker and it's working right now. thank you!

Alain Verleyen #:

Why are thinking it's "not working" when it returns "Success" ?

There is usually not market book orders for Forex symbols. Some brokers provide it for their own market book which is only a small part of the real market.