【问题标题】:interactive brokers api python - pull bid/ask trading book vendor交互式经纪人 api python - 拉出/询问交易书供应商
【发布时间】:2021-08-29 23:31:20
【问题描述】:

我正在使用 IB API 来自动提取完整的每日买卖交易簿供应商的实时数据。 我无法弄清楚如何在屏幕上打印这些数据, 不胜感激

这是我提取冻结的延迟市场数据的代码示例:

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
from ibapi.ticktype import TickTypeEnum


class TestApp(EWrapper, EClient):
    def __init__(self):
        EClient.__init__(self, self)

    def error(self, reqId, errorCode, errorString):
        print("Error: ", reqId, " ", errorCode, " ", errorString)

    def tickPrice(self, reqId, tickType, price, attrib):
        print("Tick Price. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Price:", price, end=' ')

    def tickSize(self, reqId, tickType, size):
        print("Tick Size. Ticker Id:", reqId, "tickType:", TickTypeEnum.to_str(tickType), "Size:", size)
        #if tickType == 2 and reqId == 1:
        #   print('The current ask price is: ', price)

def main():
    app = TestApp()

    app.connect("127.0.0.1", 7497, 0)

    contract = Contract()
    contract.symbol = "AAPL"
    contract.secType = "STK"
    contract.exchange = "SMART"
    contract.currency = "USD"
    contract.primaryExchange = "NASDAQ"


    try:
        app.reqMarketDataType(1)  # switch to delayed-frozen data if live is not available
        app.reqMktData(1, contract, "", False, False, [])
        
    except Exception:
        marketData=0
    
        
    else:
        app.reqMarketDataType(4)  # switch to delayed-frozen data if live is not available
        app.reqMktData(1, contract, "", False, False, [])
        marketData = -1
    
    finally:
        print (marketData)



    app.run()


if __name__ == "__main__":
    main()

【问题讨论】:

    标签: python ib-api


    【解决方案1】:
    def tickPrice(self, reqId, tickType, price, attrib):
        if tickType == 1 and reqId == 2:
            print('The current ask price is: ', price)
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    相关资源
    最近更新 更多