April 2019
Intermediate to advanced
426 pages
11h 13m
English
With a long position opened by sending a market order to buy, we should be able to view our current EUR/USD position. We can do so on the broker object using the following code:
def on_position_event(symbol, is_long, units, upnl, pnl):
print(
dt.datetime.now(), '[POSITION]',
'symbol:', symbol,
'is_long:', is_long,
'units:', units,
'upnl:', upnl,
'pnl:', pnl
)
broker.on_position_event = on_position_event
broker.get_positions()
The on_position_event() function is defined as the listener for incoming position updates from our broker and is assigned to the broke.on_position_event event handler. When the get_positions() method is called, the broker returns the position information and triggers the following output: