Multithreading-Subscribe to different instruments in different threads

kapilaggr
kapilaggr edited October 9 in Python client
Hi All,

I have an excel file in which i have a list of instrument ids.I want to iterate over this list and create a separate thread to get the tick data for every instrument and do some processing on that and place the orders.Something like-
def on_ticks(ws, ticks):
#define my logic here


def on_connect(ws, response):
ws.subscribe(token)
ws.set_mode(ws.MODE_FULL, token)


kws.on_ticks = on_ticks
kws.on_connect = on_connect
kws.connect(threaded=True)


while True:
for i in exceldata.index:
ws.subscribe(exceldata.at[i,'instrumentid'])
ws.set_mode(ws.MODE_FULL, at[i,'instrumentid'])
Kindly suggest how I can do this in an efficient manner or any other alternative approach that would be useful here.

Also,based on your experience,what would be the optimal number of threads that can run parallelly without impacting the performance.I am using the local system.

Thanks and Regards,
Kapil
  • ZI4453
    Refer this
    If you give more clarity on why you need multiple threads we might be able to suggest other options, also incase if you are tech savy you can put up those(each) threads through different ISP/internet using dispatch proxy.
    mostly computation wont be an issue in local system, your NIC cache,handling socket data wil be a challange ..
    API trading will be simple is we stick to simple "Computational signal generation" instead of Algo strategies.
  • kapilaggr
    Hi ZI4453,

    Every row of my excel file has the instrument ids and contract names of two stocks.Additionally,there are a fixed set of parameters and their values will vary for every row.I want to loop through the rows of this excel and create a separate thread for every row,so that every threads shows the tick data of two instruments,does some calculations on the basis of the parameters and sends orders.
Sign In or Register to comment.