Professional Documents
Culture Documents
Qqqetf Test
Qqqetf Test
Qqqetf Test
class MyTradingApp(EWrapper):
def __init__(self, client_id):
self.app = IBApi(self)
self.client_id = client_id
self.current_price = None
def start(self):
self.app.connect("127.0.0.1", 7497, clientId=self.client_id)
self.app.run()
def stop(self):
self.app.disconnect()
def place_order(self):
contract = self.create_contract("QQQ")
order = self.create_order('BUY', 1)
# Place buy order
self.app.placeOrder(self.app.nextValidOrderId, contract, order)
def fetch_market_data(self):
contract = self.create_contract("QQQ")
self.app.reqMktData(1, contract, "", False, False, [])
contract = self.create_contract("QQQ")
order = self.create_order('SELL', 1)
if __name__ == "__main__":
YOUR_CLIENT_ID = 1 # Replace this with your actual client ID
trading_app = MyTradingApp(YOUR_CLIENT_ID)
trading_app.start()
trading_app.fetch_market_data() # Request market data
time.sleep(10) # Wait for 10 seconds before stopping the app (adjust
as needed)
trading_app.stop()