I am using ibpy to send orders to TWS in InteractiveBrokers. I am able to send stock orders, such as SPY, but I am unable to send Futures. Here is the code I am using, copied online:
from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
def make_contract(symbol, sec_type, exch, prim_exch, curr):
Contract.m_symbol = symbol
Contract.m_secType = sec_type
Contract.m_exchange = exch
Contract.m_primaryExch = prim_exch
Contract.m_currency = curr
return Contract
def make_order(action,quantity, price = None):
if price is not None:
order = Order()
order.m_orderType = 'LMT'
order.m_totalQuantity = quantity
order.m_action = action
order.m_lmtPrice = price
else:
order = Order()
order.m_orderType = 'MKT'
order.m_totalQuantity = quantity
order.m_action = action
return order
orderId=300
conn = Connection.create(port=7496, clientId=999)
conn.connect()
cont = make_contract('SPY', 'STK', 'SMART', 'SMART', 'USD')
trade = make_order('BUY', 1, 273)
conn.placeOrder(orderId, cont, trade)
conn.disconnect()
The code above works well. I am able to place a bid in SPY at 273.
However, I want to buy E-mini Futures S&P 500 Dec Contract. I made the following to define the contract:
def make_fut():
Contract.m_symbol = 'ES'
Contract.m_secType = 'FUT'
Contract.m_exchange = 'GLOBEX'
Contract.m_primaryExch = 'GLOBEX'
Contract.m_currency = 'USD'
Contract.m_lastTradeDateOrContractMonth ='201812'
return Contract
cont = make_fut()
It did not go through and it did not get back error messages. Does any one have some experience in this?