Retrieve type of position [Python]

 

Hello,

When I make a get_position I have the list of my positions opened, and I have a colum with the "type".

Type 0 is a Buy position and Type 1 is a sell position.


positions=mt5.positions_get(symbol="GOLDmicro")
if positions==None:
    print("No position on Gold, error code={}".format(mt5.last_error()))
elif len(positions)>0:
    print("GOLD positions =",len(positions))
 # Show all open positions
    for position in positions:
        print(position)

The result looks like this:

TradePosition(ticket=542919563, time=1653651234, time_msc=1653651234856, time_update=1653651234, time_update_msc=1653651234856, type=0, magic=234000, identifier=542919563, reason=3, 

volume=0.1, price_open=1859.44, sl=0.0, tp=1862.44, price_current=1859.35, swap=0.0, profit=-0.01, symbol='GOLDmicro', comment='TP0', external_id='')


How can I retrieve the type=0 to use it after?


I want after that something like this but I want to add the "type of position".

if len(positions)>0 [and Ordertype(position)==0]:
    print ("Buy position already opened")


Someone got an idea?