Keyboard Shortcuts
ctrl + shift + ? :
Show all keyboard shortcuts
ctrl + g :
Navigate to a group
ctrl + shift + f :
Find
ctrl + / :
Quick actions
esc to dismiss
Likes
Search
twsapi: Re: Ways of filtering bad quotes from TWS
Michel
开云体育Yes, I
sometimes get quotes and/or sizes =0 for a litle moment buy I dont understand
your problem: 'if lastPrice = 0 then... exit sub'
?
Michel.
|
mbluhm2001
Tbanks for the reply. Thanks what I'm doing with the 0 price quotes,
throwing them away. I didn't mention that I'm also getting what seems to be quotes that non zero but incorrect. So I'm trying to filter them with some type of algrothrim so I don't get caught executing a bad trade. I also wanted to make sure that its not something I'm doing incorrectly with my interface to TWS. Thanks, Mark --- In twsapi@y..., "Michel" <migurull@t...> wrote: Yes, I sometimes get quotes and/or sizes =0 for a litle moment buy Idont understand your problem: 'if lastPrice = 0 then... exit sub'filter > and wanted to see if anyone else had any better ideas. The wayI'm > trying it is the following:previous > quote by X% and the error counter is less than Ythat thethe > quote is out of range Y number of times (i'm starting with 5)then usezero > either.Service. |
Michel
开云体育I dont
know how you handle your quotes and sizes so I can't help.
The
way in which I handle them is through the use of a 'one shoot' timer of 200 ms.
In my tickPrice event I update a variable LastPrice = price and enable the
timer. In my tickSize event I update a variable LastSize = size and also enable
the timer if it is not. Then in the Timer.Timer event I disable the timer and do
the job with LastPrice and LastSize.
This
way I allow a 200ms. time window after every price or size event to wait for the
second event (size or price) to update the other variable and if the second
event dont comes, simply the other variable is unchanged when I use them in my
Timer.timer event.
?
Michel.
[Michel]??-----Mensaje original----- De: mbluhm2001 [mailto:mbluhm2001@...] Enviado el: jueves, 04 de julio de 2002 21:35 Para: twsapi@... Asunto: twsapi: Re: Ways of filtering bad quotes from TWS Tbanks for the reply. Thanks what I'm doing with the 0 price quotes, |
mbluhm2001
I guess the first question is why do you turn off your timer. I would
think that the only issue you could have is if your processing of the ticks would last more than 200ms and that's alot of CPU cycles. But your program works and my has problems so I would like to understand this better. In my program I never turn off my Timer. In my timer routine I call m_pClient->checkMessages(); which I assume will call the tickPrice and tickSize events in my program for each stock that has a new tick price & size. After that I process the stocks with the new price looking for entry/exits/stops trades. This is an example of the tick price I'm seeing from BRCD. I see this on all of the stocks that I'm monitering. Here is what I saw tonight with the times shown. Since the values are very close together I'm assuming I must be doing something wrong. 16:44:41 BRCD Out of Range Price = -1.000009 17:05:53 BRCD Out of Range Price = -1.000016 17:10:33 BRCD Out of Range Price = -1.000018 17:18:20 BRCM Out of Range Price = -1.000099 Thanks, Mark --- In twsapi@y..., "Michel" <migurull@t...> wrote: I dont know how you handle your quotes and sizes so I can't help.timer of 200 ms. In my tickPrice event I update a variable LastPrice = priceand enable the timer. In my tickSize event I update a variable LastSize= size and also enable the timer if it is not. Then in the Timer.Timerevent I disable the timer and do the job with LastPrice and LastSize.event to wait for the second event (size or price) to update the othervariable and if the second event dont comes, simply the other variable isunchanged when I use them in my Timer.timer event.quotes, throwing them away. I didn't mention that I'm also getting whatseems to be quotes that non zero but incorrect. So I'm trying to filterthem with some type of algrothrim so I don't get caught executing a bad |
Michel
开云体育I see
you are using C++ API, and I'm using ActiveX VB but for the purpose of this
discussion this is not a problem.
?
First
of all we need to understand how IB sends price and size
changes:
- if
price changes but not size, IB sends a tickPrice event/message with the new
price.
- if
size changes but not price, IB sends a tickSize event/message with the new
size.
- if
price AND size change, IB sends a tickPrice and a tickSize event/message with
new price and new size.
- if
price NOR size change, IB sends... nothing.
?
I
asked IB about the timming of this events and they say:
- they
send bursts of messages with new values (if any change) every 0.7
seconds.
-
order in which tickPrice and tickSize are fired is not guaranteed (actually,
tickPrice comes before tickSize but this can be different in new versions so we
must assume there is not a defined order in this events).
?
The
problem with this 'differential' approach (only changes are transmitted) is that
when we receive a tickPrice (or tickSize)event/message, we never know if it will
be alone or followed by a tickSize (or tickPrice).For example, as you explain
the way you handle this events, when you empty the message queue
(?m_pClient->checkMessages()) and find for example a newPrice (or when
you receive a tickPrice event), you can't process it immediatly (assuming a new
tick with newPrice and oldSize) because you dont know if it will be followed by
a newSize message/event... so the only way is to WAIT A CERTAIN TIME to allow
ALL messages related to a tick to reach your application.
This
is the reason for the use of a 'one shoot' timer of 200 ms: every reception of a
newPrice or newSize event resets this timer, allowing a time frame of 200 ms. to
eventually receive other messages/events related to the same
tick.
Only
when this tempo had compleded, you are sure to have received all events and can
begin to process the new tick.
The
200 ms. is arbitrary and based on some tets: generally tickSize, when present,
comes a few milliseconds after tickPrice but you must allow some delay (for
example, tickSize message could be routed differently on the net and take more
time).
Also
during this 200 ms, your program can complete other pending tasks related to the
precedent tick (for example archiving it in a file). The idea behind it is,
assuming a new tick every 0.7 second, to allow 200 ms to complete the tick and
500 ms to process it. This 500 ms is more than sufficient: I make lots of tests
and?displays (including a real time graph of the last 15 minutes ticks) in
less than 50 ms in Visual Basic with an Athlon 700 MHz on
WinXP.
?
The
reason why I turn off the timer is now obvious: I only need it AFTER a tickPrice
or tickSize event to define a time slot during which I consider all messages
pertaining to the same tick. The timer can be off for minutes if no new
tickPrice nor tickSize events are received. Dont confuse this timer with the
timer needed in the API to poll the message queue.
?
Hope
this can help and also interessed in other ways to implement
it.
?
Michel.
?
?
|
Carl Erikson
Hey Mark,
I don't know what is causing your problem. However, I just wanted to mention that in my programs, m_pClient->checkMessages() is called everytime there is an event and is not associated with any timer. If you check out the latest SocketClient source from IB, they do this too (they changed this from earlier versions where the checkMessages() was on a timer). On the latest TWS, check out: SocketClient/src/EclientSocket.cpp, line 647 Seems like this shouldn't help (and probably won't), but I haven't had bad quote problems like the ones you are experiencing. Are these bad quotes coming from the demo TWS or the real thing (or both)? Good luck, Carl --- mbluhm2001 <mbluhm2001@...> wrote: I guess the first question is why do you turn off __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free |
to navigate to use esc to dismiss