使用 IB_insync API。
加载ticker.Domticks 并接收报价列表时,美元金额似乎是正确的,但份额显示为0、1、3、6 等小整数......当它们最有可能缩放100 倍时......零很可能是少于 100 股。因为它不是浮点数,所以无法缩放。有谁知道为什么它会错误地返回股票号码?我最近确实订阅了 ASX 澳大利亚交易所,并注意到股票数量以数千计,所以它可能是正确的。合约 = 股票('AAPL', "ISLAND","USD") > 合约 = 股票('CBA', "ASX","AUD")
def runner(ticker):
global elements
# print(ticker.domTicks)
for i in range(100):
if i < len(ticker.domTicks):
grab = ticker.domTicks[i]
elements.append(grab)
if __name__ == "__main__":
depth = 120
time_samples = 260
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=2)
list_of_exchanges = ib.reqMktDepthExchanges()
for items in list_of_exchanges:
print(items)
print(list_of_exchanges)
contract = Stock('AAPL', "ISLAND","USD")
last_bid_book = np.zeros((0,depth))
print(last_bid_book)
last_ask_book = np.zeros((0,depth))
elements = []
ticker = ib.reqMktDepth(contract)
ib.sleep(1)
ticker.updateEvent += runner