I want to create multiple orders to close my positions at the end of trading session. Below is one of the orders. This code is repeated multiple times (with the number "1" just replaced with different numbers). Can someone please suggest how to code to avoid duplication?
def submit_closing_market_order_stock_1(contract, direction, ordertype='MKT', transmit=True):
order = Order()
order.action = direction
order.totalQuantity = app.quantity_stock_1
order.orderType = ordertype
order.eTradeOnly = False
order.firmQuoteOnly = False
app.placeOrder(app.nextorderId, contract, order)
app.nextorderId += 1
order.transmit = transmit
I think I'm close with the following code; however Pycharm says on the "submit_closing_market_order()" line that the parameter 'contract' is unfilled. Is anyone able to help me solve this?
order = Order()
order.action = direction
order.orderType = ordertype
order.eTradeOnly = False
order.firmQuoteOnly = False
app.placeOrder(app.nextorderId, contract, order)
app.nextorderId += 1
order.transmit = transmit
def submit_closing_market_order_stock_1():
submit_closing_market_order()
order = Order()
order.totalQuantity = app.quantity_stock_1````