forked from kevinlawler/High-Frequency-Trading-Model-with-IB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibUtil.py
33 lines (28 loc) · 1.19 KB
/
ibUtil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#######################################
# Author: James Ma
# Email stuff here: [email protected]
#######################################
from ib.ext.Contract import Contract
from ib.ext.Order import Order
import ibDataTypes as DataType
def make_ib_contract(contractTuple):
newContract = Contract()
newContract.m_symbol = contractTuple[0]
newContract.m_secType = contractTuple[1]
newContract.m_exchange = contractTuple[2]
newContract.m_currency = contractTuple[3]
newContract.m_expiry = contractTuple[4]
newContract.m_strike = contractTuple[5]
newContract.m_right = contractTuple[6]
#print 'Contract Values:%s,%s,%s,%s,%s,%s,%s:' % contractTuple
return newContract
def create_stock_contract(stock):
contract_tuple = (stock, 'STK', 'SMART', 'USD', '', 0.0, '')
stock_contract = make_ib_contract(contract_tuple)
return stock_contract
def create_stock_order(quantity, is_buy, is_market_order=True):
order = Order()
order.m_orderType = DataType.ORDER_TYPE_MARKET if is_market_order else DataType.ORDER_TYPE_LIMIT
order.m_totalQuantity = quantity
order.m_action = DataType.ORDER_ACTION_BUY if is_buy else DataType.ORDER_ACTION_SELL
return order