Hello i new here i try get data for multiple symbol,
about 580 +-,
but it take allot time and not always finish this.
this how i try make this.
from ibapi.client import EClient
|
|
from ibapi.wrapper import EWrapper
|
|
from ibapi.contract import Contract
|
|
import pandas as pd
|
|
import threading
|
|
import time
|
|
from datetime import timedelta
|
|
import datetime
|
|
tickers=list(pdToList[0:600]) #########-> list example i put here <-#########
|
|
listnumb = []
|
|
from ibapi.common import BarData
|
|
from random import random
|
|
|
|
start = datetime.datetime.utcnow()
|
|
|
|
class IBapi(EWrapper, EClient):
|
|
????def __init__(self):
|
|
????????EClient.__init__(self, self)
|
|
????????self.data = []
|
|
|
|
????def error(self, reqId, errorCode, errorString):
|
|
????????print("Error. Id: ", reqId, " Code: ", errorCode, " Msg: ", errorString)
|
|
|
|
????def historicalTicksBidAsk(self, reqId, ticks, done):
|
|
????????for i in listnumb:
|
|
????????????mama = int(''.join(filter(str.isdigit, i)))
|
|
????????????if str(reqId) == str(mama):
|
|
????????????????symbllll = str(i)
|
|
????????????????result = ''.join([i for i in symbllll if not i.isdigit()])
|
|
????????????????symbllll = str(result)
|
|
????????????????break
|
|
????????for tick in ticks:
|
|
????????????print("HistoricalTickBidAsk. ReqId:", reqId , "symb : " + symbllll, tick)
|
|
????????????
|
|
????# include this callback to track progress and maybe disconnectwhen all are finished
|
|
????def historicalDataEnd(self, reqId: int, start: str, end: str):
|
|
????????print("finished")
|
|
|
|
|
|
def run_loop():
|
|
????app.run()
|
|
|
|
|
|
app = IBapi()
|
|
app.connect('127.0.0.1', 4001, 123)
|
|
|
|
api_thread = threading.Thread(target=run_loop, daemon=True)
|
|
api_thread.start()
|
|
|
|
time.sleep(1)
|
|
|
|
reqId = 1
|
|
sym_dict = {}
|
|
start_time = time.time()
|
|
for sym in tickers:
|
|
????contract = Contract()
|
|
????contract.symbol = str(sym)
|
|
????sym_dict[reqId] = sym
|
|
????contract.secType = "STK"
|
|
????contract.exchange = "SMART"
|
|
????contract.currency = "USD"
|
|
|
|
????listnumb.append(sym + str(reqId))
|
|
????app.reqHistoricalTicks(reqId, contract, "20211022 04:09:40", "", 1, "BID_ASK", 1, False, [])
|
|
????reqId += 1 |