[英]interactive brokers api python - pull bid/ask trading book vendor
我正在使用 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()
def tickPrice(self, reqId, tickType, price, attrib):
if tickType == 1 and reqId == 2:
print('The current ask price is: ', price)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.