Created
September 28, 2014 10:47
-
-
Save QuantTraderEd/3e6c8d2d8b9486759074 to your computer and use it in GitHub Desktop.
IBPy_Test1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Sun Sep 28 18:48:04 2014 | |
@author: assa | |
""" | |
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 | |
def main(): | |
conn = Connection.create(port=7496, clientId=999) | |
conn.connect() | |
oid = 2 | |
cont = make_contract('TSLA', 'STK', 'SMART', 'SMART', 'USD') | |
#offer = make_order('BUY', 1, 200) | |
offer = make_order('BUY', 1) | |
conn.placeOrder(oid, cont, offer) | |
conn.disconnect() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment