http://interactivebrokers.github.io/tws-api/おそらく役立つリンクです。 この画像は Interacitve Brokers の Java API ガイドからのもので、私が欲しい数字は取引ログの価格と手数料です。
1760 次
1 に答える
1
from ib.opt import Connection, message
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.ext.CommissionReport import CommissionReport
from ib.ext.TickType import TickType as tt
関心のある各タイプのコールバックを処理する関数を作成します。
def error_handler(msg):
print (msg)
def execDetails(msg):
print('ID',msg.execution.m_execId,'PRICE',msg.execution.m_price)
def commReport(msg):
print('ID',msg.commissionReport.m_execId,'COM',msg.commissionReport.m_commission)
tws = Connection.create(port = 4001, clientId=123)
tws.register(execDetails, message.execDetails)
tws.register(commReport, message.commissionReport)
tws.register(error_handler, 'Error')
tws.connect()
終了するまで待つ必要がありconnect()
ます。通常は nextOrderId コールバックを使用して準備ができたら通知しますが、Python では sleep(2) するか、この場合はノートブックを使用しているので、後で次のセルを実行します。
fx = Contract()
fx.m_secType = "CASH"
fx.m_symbol = "USD"
fx.m_currency = "CAD"
fx.m_exchange = "IDEALPRO"
#tws.reqMktData(1,fx,"",False)
ord = Order()
ord.m_orderType = 'MKT'
ord.m_totalQuantity = 100000
ord.m_action = 'SELL'
tws.placeOrder(123,fx,ord) #increment this every order
これは印刷します
ID 0001f4e8.57427bd9.01.01 PRICE 1.31565
ID 0001f4e8.57427bd9.01.01 COM 2.6313`
いつか忘れないtws.disconnect()
で
于 2016-05-23T13:00:02.583 に答える