的 'Adjusted_Last' 我使用Python我不能得到ibapi
API_VERSION = 9.73.04
from ibapi import wrapper
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract as IBcontract
from threading import Thread
import queue
import datetime
from ibapi.utils import iswrapper #just for decorator
from ibapi.common import *
from ibapi.contract import *
from ibapi.ticktype import *
class TestApp(wrapper.EWrapper, EClient):
def __init__(self):
wrapper.EWrapper.__init__(self)
EClient.__init__(self, wrapper=self)
@iswrapper
def historicalData(self, reqId:int, bar: BarData):
print("HistoricalData. ", reqId, " Date:", bar.date, "Open:", bar.open,
"High:", bar.high, "Low:", bar.low, "Close:", bar.close, "Volume:", bar.volume)
self.done = True
def main():
t = time()
max_amount_per_Iter = 70 #max number per iter to save cost
max_Iter = ceil(len(all_data)/max_amount_per_Iter)-1
for i in range (0,max_Iter):
print('====================round : ',i+1,'===============================')
app = TestApp()
app.connect("127.0.0.1", 7496, clientId=i)
print("serverVersion:%s connectionTime:%s" % (app.serverVersion(),app.twsConnectionTime()))
for j in range (0,min(max_amount_per_Iter,len(all_data)-i*max_amount_per_Iter)):
print(j+i*70)
app.done = False
app.i = j+i*max_amount_per_Iter
contract = Contract()
contract.symbol = all_data.iloc[app.i,0]
contract.secType = all_data.iloc[app.i,1]
contract.currency = all_data.iloc[app.i,3]
contract.exchange = all_data.iloc[app.i,2]
queryTime = (datetime.datetime.today() - datetime.timedelta(days=180)).strftime("%Y%m%d %H:%M:%S")
print('i=', i)
app.reqHistoricalData(app.i, contract, queryTime,"1 W", "1 day", "Adjusted_Last", 1, 1, False, [])
i+1
app.run()
sleep(1)
app.disconnect()
sleep(0.02)
print('=========End round : ',i+1,'with time :',time() - t,'==============')
if __name__ == "__main__":
main()
由於
app.reqHistoricalData(app.i, contract, queryTime,"1 W", "1 day", "Adjusted_Last", 1, 1, False, [])
它會返回錯誤,沒有數據。
ERROR:root:ERROR 0 321 Error validating request:-'bm' : cause - What to show value of ADJUSTED_LAST rejected.
我必須嘗試各種方法。但我是Python新手,所以我甚至不知道如何開始搜索。對於all_data是一個pd.DataFame,我用它來保持S & P 500成分股,我將用這些價格來計算回報。
然後,我打算獲得一個我持有並系統地交易它們的股票頭寸。
我知道我有關於app.done = True的另一個問題,我想我可以自己處理它。但我無法解決這個問題。 謝謝!
我得到了同樣的錯誤:錯誤驗證請求: - 「BM」:原因 - 怎麼顯示ADJUSTED_LAST的價值拒絕。你找到解決方案嗎? – k26dr
不,但您可以嘗試從第一個答案的鏈接下載API的新版本。 –
試試app.reqHistoricalData(app.i,contract,「」,「1 W」,「1 day」,「Adjusted_Last」,1,1,False,[]) –