Class: IB::IncomingMessages::TickPrice
- Inherits:
-
AbstractMessage
- Object
- ExtremelyAbstractMessage
- AbstractMessage
- IB::IncomingMessages::TickPrice
- Defined in:
- lib/ib-ruby/messages.rb
Overview
The IB code seems to dispatch up to two wrapped objects for this message, a tickPrice and sometimes a tickSize, which seems to be identical to the TICK_SIZE object.
Important note from chuckcaplan.com/twsapi/index.php/void%20tickPrice%28%29 :
“The low you get is NOT the low for the day as you’d expect it to be. It appears IB calculates the low based on all transactions after 4pm the previous day. The most inaccurate results occur when the stock moves up in the 4-6pm aftermarket on the previous day and then gaps open upward in the morning. The low you receive from TWS can be easily be several points different from the actual 9:30am-4pm low for the day in cases like this. If you require a correct traded low for the day, you can’t get it from the TWS API. One possible source to help build the right data would be to compare against what Yahoo lists on finance.yahoo.com/q?s=ticker under the ”Day’s Range“ statistics (be careful here, because Yahoo will use anti-Denial of Service techniques to hang your connection if you try to request too many bytes in a short period of time from them). For most purposes, a good enough approach would start by replacing the TWS low for the day with Yahoo’s day low when you first start watching a stock ticker; let’s call this time T. Then, update your internal low if the bid or ask tick you receive is lower than that for the remainder of the day. You should check against Yahoo again at time T+20min to handle the occasional case where the stock set a new low for the day in between T-20min (the real time your original quote was from, taking into account the delay) and time T. After that you should have a correct enough low for the rest of the day as long as you keep updating based on the bid/ask. It could still get slightly off in a case where a short transaction setting a new low appears in between ticks of data that TWS sends you. The high is probably distorted in the same way the low is, which would throw your results off if the stock traded after-hours and gapped down. It should be corrected in a similar way as described above if this is important to you.”
Instance Attribute Summary
Attributes inherited from AbstractMessage
Attributes inherited from ExtremelyAbstractMessage
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from AbstractMessage
Constructor Details
This class inherits a constructor from IB::IncomingMessages::AbstractMessage
Class Method Details
.message_id ⇒ Object
912 913 914 |
# File 'lib/ib-ruby/messages.rb', line 912 def self. 1 end |
Instance Method Details
#inspect ⇒ Object
load
944 945 946 |
# File 'lib/ib-ruby/messages.rb', line 944 def inspect "Tick (" + @data[:type].to_s + " at " + @data[:price].to_digits + ") " + super.inspect end |
#load ⇒ Object
916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'lib/ib-ruby/messages.rb', line 916 def load autoload([:version, :int], [:ticker_id, :int], [:tick_type, :int], [:price, :decimal]) version_load(2, [:size, :int]) version_load(3, [:can_auto_execute, :int]) if @data[:version] >= 2 # the IB code translates these into 0, 3, and 5, respectively, and wraps them in a TICK_SIZE-type wrapper. @data[:type] = case @data[:tick_type] when 1 :bid when 2 :ask when 4 :last when 6 :high when 7 :low when 9 :close else nil end end end |
#to_human ⇒ Object
948 949 950 |
# File 'lib/ib-ruby/messages.rb', line 948 def to_human @data[:size].to_s + " " + @data[:type].to_s + " at " + @data[:price].to_digits end |