defbuy(self):
self.symbol = varSymbol.get() # gets the symbol string from the symbol combo box
self.quantity = varQuantity.get() # gets the share size from the quantity spinbox
self.order_type = varOrderType.get() # gets the order type for the order type combobox
self.limit_price = varLimitPrice.get() # gets the limit price from the limit price spinbox# calls the function place_market order passes variables# symbol, quantity, order type, buy or sell represeted by true or false, and limit price
self.place_market_order(self.symbol, self.quantity, self.order_type, True, self.limit_price)
defsell(self):
self.symbol = varSymbol.get()
self.quantity = varQuantity.get()
self.order_type = varOrderType.get()
self.limit_price = varLimitPrice.get()
self.place_market_order(self.symbol, self.quantity, self.order_type, False, self.limit_price)
Place order function
defplace_market_order(self, symbol, quantity, order_type, is_buy, limit_price):
print (symbol, quantity, order_type, is_buy, limit_price)
contract = self.create_contract(symbol,
'STK',
'SMART',
'NASDAQ',
'USD')
# tests if is buy or sell
buysell = 'BUY'if is_buy else'SELL'
order = self.create_order(order_type, quantity, buysell, limit_price)
self.tws_conn.placeOrder(self.order_id, contract, order)
# increses the order id by one
self.order_id += 1 # add number to order id so it is ready for the next order# must be increase higher than the previous number
No comments:
Post a Comment