From e569ed02332f30be7b074481c3e6dfa05f13964d Mon Sep 17 00:00:00 2001 From: Olivier Milla Date: Wed, 26 Jun 2024 21:26:49 +0200 Subject: [PATCH] Breaking: Now tick types are served as enum instead of strings. --- src/InteractiveBrokers.jl | 2 +- src/TickTypes.jl | 115 ++++++++++++++++++++++++++++++++++++++ src/decode.jl | 1 - src/process.jl | 12 ++-- src/ticktype.jl | 110 ------------------------------------ test/test_utils.jl | 41 ++++++-------- 6 files changed, 140 insertions(+), 141 deletions(-) create mode 100644 src/TickTypes.jl delete mode 100644 src/ticktype.jl diff --git a/src/InteractiveBrokers.jl b/src/InteractiveBrokers.jl index a162bf3..5749a15 100644 --- a/src/InteractiveBrokers.jl +++ b/src/InteractiveBrokers.jl @@ -12,7 +12,7 @@ include("types_private.jl") include("wrapper.jl") include("reader.jl") ; using .Reader: check_all, start_reader include("utils.jl") - +include("TickTypes.jl") """ Connection() diff --git a/src/TickTypes.jl b/src/TickTypes.jl new file mode 100644 index 0000000..f72a089 --- /dev/null +++ b/src/TickTypes.jl @@ -0,0 +1,115 @@ +module TickTypes + +export tickname +export TICK_TYPES + +tickname(i) = string(TICK_TYPES(i)) + +@enum TICK_TYPES::Int begin + BID_SIZE = 0 + BID = 1 + ASK = 2 + ASK_SIZE = 3 + LAST = 4 + LAST_SIZE = 5 + HIGH = 6 + LOW = 7 + VOLUME = 8 + CLOSE = 9 + BID_OPTION = 10 + ASK_OPTION = 11 + LAST_OPTION = 12 + MODEL_OPTION = 13 + OPEN = 14 + LOW_13_WEEK = 15 + HIGH_13_WEEK = 16 + LOW_26_WEEK = 17 + HIGH_26_WEEK = 18 + LOW_52_WEEK = 19 + HIGH_52_WEEK = 20 + AVG_VOLUME = 21 + OPEN_INTEREST = 22 + OPTION_HISTORICAL_VOL = 23 + OPTION_IMPLIED_VOL = 24 + OPTION_BID_EXCH = 25 + OPTION_ASK_EXCH = 26 + OPTION_CALL_OPEN_INTEREST = 27 + OPTION_PUT_OPEN_INTEREST = 28 + OPTION_CALL_VOLUME = 29 + OPTION_PUT_VOLUME = 30 + INDEX_FUTURE_PREMIUM = 31 + BID_EXCH = 32 + ASK_EXCH = 33 + AUCTION_VOLUME = 34 + AUCTION_PRICE = 35 + AUCTION_IMBALANCE = 36 + MARK_PRICE = 37 + BID_EFP_COMPUTATION = 38 + ASK_EFP_COMPUTATION = 39 + LAST_EFP_COMPUTATION = 40 + OPEN_EFP_COMPUTATION = 41 + HIGH_EFP_COMPUTATION = 42 + LOW_EFP_COMPUTATION = 43 + CLOSE_EFP_COMPUTATION = 44 + LAST_TIMESTAMP = 45 + SHORTABLE = 46 + FUNDAMENTAL_RATIOS = 47 + RT_VOLUME = 48 + HALTED = 49 + BID_YIELD = 50 + ASK_YIELD = 51 + LAST_YIELD = 52 + CUST_OPTION_COMPUTATION = 53 + TRADE_COUNT = 54 + TRADE_RATE = 55 + VOLUME_RATE = 56 + LAST_RTH_TRADE = 57 + RT_HISTORICAL_VOL = 58 + IB_DIVIDENDS = 59 + BOND_FACTOR_MULTIPLIER = 60 + REGULATORY_IMBALANCE = 61 + NEWS_TICK = 62 + SHORT_TERM_VOLUME_3_MIN = 63 + SHORT_TERM_VOLUME_5_MIN = 64 + SHORT_TERM_VOLUME_10_MIN = 65 + DELAYED_BID = 66 + DELAYED_ASK = 67 + DELAYED_LAST = 68 + DELAYED_BID_SIZE = 69 + DELAYED_ASK_SIZE = 70 + DELAYED_LAST_SIZE = 71 + DELAYED_HIGH = 72 + DELAYED_LOW = 73 + DELAYED_VOLUME = 74 + DELAYED_CLOSE = 75 + DELAYED_OPEN = 76 + RT_TRD_VOLUME = 77 + CREDITMAN_MARK_PRICE = 78 + CREDITMAN_SLOW_MARK_PRICE = 79 + DELAYED_BID_OPTION = 80 + DELAYED_ASK_OPTION = 81 + DELAYED_LAST_OPTION = 82 + DELAYED_MODEL_OPTION = 83 + LAST_EXCH = 84 + LAST_REG_TIME = 85 + FUTURES_OPEN_INTEREST = 86 + AVG_OPT_VOLUME = 87 + DELAYED_LAST_TIMESTAMP = 88 + SHORTABLE_SHARES = 89 + DELAYED_HALTED = 90 + REUTERS_2_MUTUAL_FUNDS = 91 + ETF_NAV_CLOSE = 92 + ETF_NAV_PRIOR_CLOSE = 93 + ETF_NAV_BID = 94 + ETF_NAV_ASK = 95 + ETF_NAV_LAST = 96 + ETF_FROZEN_NAV_LAST = 97 + ETF_NAV_HIGH = 98 + ETF_NAV_LOW = 99 + SOCIAL_MARKET_ANALYTICS = 100 + ESTIMATED_IPO_MIDPOINT = 101 + FINAL_IPO_LAST = 102 + DELAYED_YIELD_BID = 103 + DELAYED_YIELD_ASK = 104 +end +end \ No newline at end of file diff --git a/src/decode.jl b/src/decode.jl index 1e84d24..9d5f21e 100644 --- a/src/decode.jl +++ b/src/decode.jl @@ -1,7 +1,6 @@ using Base.Iterators: take include("process.jl") -include("ticktype.jl") # Make a shortcut const pop = popfirst! diff --git a/src/process.jl b/src/process.jl index 7c6bbdb..1a0a23f 100644 --- a/src/process.jl +++ b/src/process.jl @@ -93,7 +93,7 @@ const process = Dict( size::Union{Float64,Nothing}, mask::Int = it - InteractiveBrokers.forward(w, :tickPrice, tickerId, tickname(ticktype), price, size, unmask(TickAttrib, mask)) + InteractiveBrokers.forward(w, :tickPrice, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), price, size, unmask(TickAttrib, mask)) end, # TICK_SIZE @@ -103,7 +103,7 @@ const process = Dict( ticktype::Int, size::Float64 = it - InteractiveBrokers.forward(w, :tickSize, tickerId, tickname(ticktype), size) + InteractiveBrokers.forward(w, :tickSize, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), size) end, # ORDER_STATUS @@ -499,7 +499,7 @@ const process = Dict( # (delta, gamma, vega, theta) == -2 means NA replace!(view(v, [2, 5, 6, 7]), -2 => nothing) - InteractiveBrokers.forward(w, :tickOptionComputation, tickerId, tickname(ticktype), tickAttrib, v...) + InteractiveBrokers.forward(w, :tickOptionComputation, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), tickAttrib, v...) end, # TICK_GENERIC @@ -509,7 +509,7 @@ const process = Dict( ticktype::Int, value::Float64 = it - InteractiveBrokers.forward(w, :tickGeneric, tickerId, tickname(ticktype), value) + InteractiveBrokers.forward(w, :tickGeneric, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), value) end, # TICK_STRING @@ -519,7 +519,7 @@ const process = Dict( ticktype::Int, value::String = it - InteractiveBrokers.forward(w, :tickString, tickerId, tickname(ticktype), value) + InteractiveBrokers.forward(w, :tickString, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), value) end, # TICK_EFP @@ -528,7 +528,7 @@ const process = Dict( tickerId::Int, ticktype::Int = it - InteractiveBrokers.forward(w, tickEFP, tickerId, tickname(ticktype), slurp((Float64, String, Float64, Int, String, Float64, Float64), it)...) + InteractiveBrokers.forward(w, tickEFP, tickerId, InteractiveBrokers.TICK_TYPES(ticktype), slurp((Float64, String, Float64, Int, String, Float64, Float64), it)...) end, # CURRENT_TIME diff --git a/src/ticktype.jl b/src/ticktype.jl deleted file mode 100644 index 57f761c..0000000 --- a/src/ticktype.jl +++ /dev/null @@ -1,110 +0,0 @@ -tickname(i) = get(ticktype, i + 1) do - @error "tickname(): unknown ticktype" T=i - "UNKNOWN" - end - -const ticktype = ["BID_SIZE", # 0 - "BID", # 1 - "ASK", # 2 - "ASK_SIZE", # 3 - "LAST", # 4 - "LAST_SIZE", # 5 - "HIGH", # 6 - "LOW", # 7 - "VOLUME", # 8 - "CLOSE", # 9 - "BID_OPTION", # 10 - "ASK_OPTION", # 11 - "LAST_OPTION", # 12 - "MODEL_OPTION", # 13 - "OPEN", # 14 - "LOW_13_WEEK", # 15 - "HIGH_13_WEEK", # 16 - "LOW_26_WEEK", # 17 - "HIGH_26_WEEK", # 18 - "LOW_52_WEEK", # 19 - "HIGH_52_WEEK", # 20 - "AVG_VOLUME", # 21 - "OPEN_INTEREST", # 22 - "OPTION_HISTORICAL_VOL", # 23 - "OPTION_IMPLIED_VOL", # 24 - "OPTION_BID_EXCH", # 25 - "OPTION_ASK_EXCH", # 26 - "OPTION_CALL_OPEN_INTEREST", # 27 - "OPTION_PUT_OPEN_INTEREST", # 28 - "OPTION_CALL_VOLUME", # 29 - "OPTION_PUT_VOLUME", # 30 - "INDEX_FUTURE_PREMIUM", # 31 - "BID_EXCH", # 32 - "ASK_EXCH", # 33 - "AUCTION_VOLUME", # 34 - "AUCTION_PRICE", # 35 - "AUCTION_IMBALANCE", # 36 - "MARK_PRICE", # 37 - "BID_EFP_COMPUTATION", # 38 - "ASK_EFP_COMPUTATION", # 39 - "LAST_EFP_COMPUTATION", # 40 - "OPEN_EFP_COMPUTATION", # 41 - "HIGH_EFP_COMPUTATION", # 42 - "LOW_EFP_COMPUTATION", # 43 - "CLOSE_EFP_COMPUTATION", # 44 - "LAST_TIMESTAMP", # 45 - "SHORTABLE", # 46 - "FUNDAMENTAL_RATIOS", # 47 - "RT_VOLUME", # 48 - "HALTED", # 49 - "BID_YIELD", # 50 - "ASK_YIELD", # 51 - "LAST_YIELD", # 52 - "CUST_OPTION_COMPUTATION", # 53 - "TRADE_COUNT", # 54 - "TRADE_RATE", # 55 - "VOLUME_RATE", # 56 - "LAST_RTH_TRADE", # 57 - "RT_HISTORICAL_VOL", # 58 - "IB_DIVIDENDS", # 59 - "BOND_FACTOR_MULTIPLIER", # 60 - "REGULATORY_IMBALANCE", # 61 - "NEWS_TICK", # 62 - "SHORT_TERM_VOLUME_3_MIN", # 63 - "SHORT_TERM_VOLUME_5_MIN", # 64 - "SHORT_TERM_VOLUME_10_MIN", # 65 - "DELAYED_BID", # 66 - "DELAYED_ASK", # 67 - "DELAYED_LAST", # 68 - "DELAYED_BID_SIZE", # 69 - "DELAYED_ASK_SIZE", # 70 - "DELAYED_LAST_SIZE", # 71 - "DELAYED_HIGH", # 72 - "DELAYED_LOW", # 73 - "DELAYED_VOLUME", # 74 - "DELAYED_CLOSE", # 75 - "DELAYED_OPEN", # 76 - "RT_TRD_VOLUME", # 77 - "CREDITMAN_MARK_PRICE", # 78 - "CREDITMAN_SLOW_MARK_PRICE", # 79 - "DELAYED_BID_OPTION", # 80 - "DELAYED_ASK_OPTION", # 81 - "DELAYED_LAST_OPTION", # 82 - "DELAYED_MODEL_OPTION", # 83 - "LAST_EXCH", # 84 - "LAST_REG_TIME", # 85 - "FUTURES_OPEN_INTEREST", # 86 - "AVG_OPT_VOLUME", # 87 - "DELAYED_LAST_TIMESTAMP", # 88 - "SHORTABLE_SHARES", # 89 - "DELAYED_HALTED", # 90 - "REUTERS_2_MUTUAL_FUNDS", # 91 - "ETF_NAV_CLOSE", # 92 - "ETF_NAV_PRIOR_CLOSE", # 93 - "ETF_NAV_BID", # 94 - "ETF_NAV_ASK", # 95 - "ETF_NAV_LAST", # 96 - "ETF_FROZEN_NAV_LAST", # 97 - "ETF_NAV_HIGH", # 98 - "ETF_NAV_LOW", # 99 - "SOCIAL_MARKET_ANALYTICS", # 100 - "ESTIMATED_IPO_MIDPOINT", # 101 - "FINAL_IPO_LAST", # 102 - "DELAYED_YIELD_BID", # 103 - "DELAYED_YIELD_ASK"] # 104 diff --git a/test/test_utils.jl b/test/test_utils.jl index ef31500..bb8c27a 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -1,25 +1,20 @@ @testset "Utils" begin - @test InteractiveBrokers.Reader.tickname( 0) == "BID_SIZE" - - @test InteractiveBrokers.Reader.tickname(90) == "DELAYED_HALTED" - - @test InteractiveBrokers.Reader.tickname(102) == "FINAL_IPO_LAST" - - @test (@test_logs (:error, "tickname(): unknown ticktype") InteractiveBrokers.Reader.tickname(-1)) == "UNKNOWN" - - @test InteractiveBrokers.funddist("Y") == "Income Fund" - @test InteractiveBrokers.fundtype("003") == "Multi-asset" - @test InteractiveBrokers.funddist("") == InteractiveBrokers.fundtype("") == "None" - - @test fieldname(InteractiveBrokers.Contract, 15) === :secId - @test fieldname(InteractiveBrokers.Contract, 17) === :issuerId - - @test fieldname(InteractiveBrokers.ContractDetails, 44) === :fundName - @test fieldname(InteractiveBrokers.ContractDetails, 58) === :fundBlueSkyTerritories - - @test fieldname(InteractiveBrokers.Order, 79) === :account - @test fieldname(InteractiveBrokers.Order, 125) === :parentPermId - - end - \ No newline at end of file + @test InteractiveBrokers.TickTypes.tickname(0) == "BID_SIZE" + @test InteractiveBrokers.TickTypes.tickname(90) == "DELAYED_HALTED" + @test InteractiveBrokers.TickTypes.tickname(102) == "FINAL_IPO_LAST" + + @test InteractiveBrokers.funddist("Y") == "Income Fund" + @test InteractiveBrokers.fundtype("003") == "Multi-asset" + @test InteractiveBrokers.funddist("") == InteractiveBrokers.fundtype("") == "None" + + @test fieldname(InteractiveBrokers.Contract, 15) === :secId + @test fieldname(InteractiveBrokers.Contract, 17) === :issuerId + + @test fieldname(InteractiveBrokers.ContractDetails, 44) === :fundName + @test fieldname(InteractiveBrokers.ContractDetails, 58) === :fundBlueSkyTerritories + + @test fieldname(InteractiveBrokers.Order, 79) === :account + @test fieldname(InteractiveBrokers.Order, 125) === :parentPermId + +end