Is it possible to use the TWS/IBpy interface to collect and analyze tick data?

245 Views Asked by At

While searching for a template to test a paper trading strategy, I stumbled on IBPy. I have gone through the initial set-up and can connect and receive updates from the server. What I would like to do is:

a) Gather ticks from 1..n symbols when new prices (bid/asks) are published b) Store these temporarily in a vector (I guess with vector.append((bid,ask)) c) Once the vector reaches it's computational max (I need 30 seconds or a certain number of ticks) I will compute some valued on vector[] and decide on whether an entry is appropriate d) If not pop(0) and keep collecting e) exit on a stoploss or trailing profit

My questions are:

i) I have read that updates are 250 ms, that is fine for my analytics but can the program/system keep up because different symbols update at different times so just because symbolA updates every 250 ms, with 10 symbols the updates maybe very frequent ii) When I stop to make a calculation, haven't I lost updates?

If there is skeleton code for this, it would be great to mess around with it

Thanks for listening!

1

There are 1 best solutions below

1
On

If you need to handle 100s of stock symbols you shall have multiple (at least 2) threads. One thread pulls the incoming data from the socket, sorts the messages by message type and pushes the data to queues. Other threads are waiting for their respective queues to get some data and process the incoming data. The idea is that the dispatcher thread ensures that all incoming data gets pulled from the socket as fast as possible.

Generally your PC will be able to handle anything IB will be willing to send you. If your processing does not take too much time - no locks, calls to sleep(), file operations - you can do everything in a single thread.