title: Problem with IB Insync Futures Order on Interactive Brokers TWS API
body: <p>I am hoping somebody here may be able to help clarify how to structure the IB-Insync Contract Format for a Futures order in a python API link with Interactive Brokers API.
  I am trying to develop a autobot API link into the Interactive Brokers API using IB-Insync.
  I have the system working perfectly now automatically placing orders with a 'Stock' contract format; as follows:</p>
  <pre><code>stock = Stock(message_data['ticker'], 'SMART', 'USD')
  ib.qualifyContracts(stock)
  order = MarketOrder(message_data['strategy']['order_action'], message_data['strategy']['order_contracts'])
  trade = ib.placeOrder(stock, order)
  </code></pre>
  <p>but when i apply the same python script to my understanding of the required IB-Insync contract format for a Futures order as per the documentation, nothing happens and a error shows in the API log.</p>
  <p>The IB-Insync Futures contract format used is below:</p>
  <pre><code>contract = Future(symbol='MES', lastTradeDateOrContractMonth='20211217', exchange='GLOBEX',
  localSymbol='MESZ1', multiplier='5', currency='USD')
  ib.qualifyContracts(contract)
  order = MarketOrder(message_data['strategy']['order_action'], message_data['strategy']['order_contracts'])
  trade = ib.placeOrder(contract, order)
  </code></pre>
  <p>API Log Error message below:</p>
  <p><em>22:28:49:791 &lt;- 9-8-59-0-MES-STK--0.0---SMART--USD---0---
  22:28:50:029 -&gt; ---A4-2-59-200-No security definition has been found for the request-
  22:28:50:030 &lt;- 3-60-0-MES-STK--0.0---SMART--USD-----BUY-1-MKT------O-0--1-0-0-0-0-0-0-0--0.0--------0---1-0---0---0-0--0------0-----0-----------0---0-0---0--0-0-0-0-------0---------0-0-0-0-
  22:28:50:264 -&gt; ---A4-2-60-200-No security definition has been found for the request-</em></p>
  <p>I have tried numerous different ways to structure the Futures Contract Format; including:</p>
  <pre><code>contract=Future('MES', '20121217', 'GLOBEX')
  </code></pre>
  <p>But the same problem occurs - the Interactive Brokers TWS API is recording the order as a STK order routing it through the SMART exchange protocol; which clearly it is not.
  I can manually place a Futures order on TWS for MES; so it cannot be due to a privilege's setting.</p>
  <p>I am hoping somebody here may know of a resolution or has come across this problem before?</p>
  <p>I am stumped by it</p>
  <p>Thankyou for your help</p>
  <p>The entire code is below:</p>
  <pre><code>import redis, json
  from ib_insync import *
  import asyncio, time, random
  from dataclasses import dataclass, field
  from typing import List, NamedTuple, Optional
  import ib_insync.util as util
  
  # connect to Interactive Brokers 
  util.startLoop()
  ib = IB()
  ib.connect('127.0.0.1', 7497, clientId=1)
  
  # connect to Redis and subscribe to tradingview messages
  r = redis.Redis(host='localhost', port=6379, db=0)
  p = r.pubsub()
  p.subscribe('tradingview')
  
  async def check_messages():
      print(f&quot;{time.time()} - checking for tradingview webhook messages&quot;)
      message = p.get_message()
      if message is not None and message['type'] == 'message':
          print(message)
  
          message_data = json.loads(message['data'])
  
          contract = Future(symbol='MES', lastTradeDateOrContractMonth='20211217', exchange='GLOBEX', localSymbol='MESZ1', multiplier='5', currency='USD')
          ib.qualifyContracts(contract)
          order = MarketOrder(message_data['strategy']['order_action'], message_data['strategy']['order_contracts'])
          trade = ib.placeOrder(contract, order)
  
  async def run_periodically(interval, periodic_function):
      while True:
          await asyncio.gather(asyncio.sleep(interval), periodic_function())
  
  asyncio.run(run_periodically(1, check_messages))
  
  ib.run()
  </code></pre>