python - 交互式经纪人 api python - 拉出/询问交易书供应商
问题描述
我正在使用 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)
推荐阅读
- java - 将字符串数组中的元素转换为字符
- apache-nifi - NiFi:打开的文件太多无法启动 FlowController
- sql - 选择适当的记录
- mongodb - 流星聚合类型错误:无法读取属性
- javascript - 更新跨项目导出的对象
- azure - 如何以非交互方式从 Powershell 脚本运行 Azure Log Analytics 查询?
- android - CardView 未显示在文本视图下方
- php - Authorize.net 对 ARB 订阅申请一次现金折扣
- amazon-web-services - AWS Spark 作业监控工具
- javascript - 如何使用 Node、Express 将图像、CSS 和 JS 等浏览器内容发送到浏览器上的 html?