Skip to content

Commit

Permalink
Update to API v161
Browse files Browse the repository at this point in the history
  • Loading branch information
lbilli committed Jul 23, 2021
1 parent 26be2b3 commit 880b345
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Jib"
uuid = "f310f2d2-a263-11e8-3998-47bd686f18f7"
authors = ["Luca Billi <noreply.section+dev@gmail.com>"]
version = "0.12.2"
version = "0.12.3"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
4 changes: 2 additions & 2 deletions src/Jib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ function connect(host, port, clientId, connectOptions::String="", optionalCapabi

@assert length(res) == 2

@info "Connected" V=res[1] T=res[2]
@info "connected" V=res[1] T=res[2]

v = parse(Int, res[1])
m v M || error("Unsupported version.")
m v M || error("unsupported version")

ib = Connection(s, clientId, connectOptions, Client.Version(v), from_ibtime(res[2]))

Expand Down
6 changes: 3 additions & 3 deletions src/decoder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ function decode(msg, w, ver)
f = get(process, id, nothing)

if isnothing(f)
@error "Decoder: unknown message" id
@error "decoder: unknown message" id

else
try
f(it, w, ver)
catch e
if e isa EOFError
@error "Decoder: reached end of message" id
@error "decoder: reached end of message" id
else
rethrow()
end
end

isempty(it) || @error "Decoder: messsage not fully parsed" id
isempty(it) || @error "decoder: message not fully parsed" id
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/encoder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
Define various encodings for known types
"""
(e::Encoder)(::T) where T = error("Unknown Type: $T")
(e::Encoder)(::T) where T = error("unknown Type: $T")

(e::Encoder)(x::Union{AbstractString,Int,Float64,Symbol}) = print(e.buf, x, '\0')

Expand All @@ -29,7 +29,7 @@ function (e::Encoder)(x::NamedTuple)

for (n, v) pairs(x)
v isa Union{AbstractString,Int,Float64} ||
@warn "Unsupported Type in NamedTuple" n v T=typeof(v)
@warn "unsupported Type in NamedTuple" n v T=typeof(v)

print(e.buf, n, '=', v, ';')
end
Expand Down
2 changes: 1 addition & 1 deletion src/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Base.convert(::Type{Bool}, x::Field)

res = findfirst(==(x.value), ("1", "true", "0", "false"))

isnothing(res) && error("Invalid Bool: $(x.value)")
isnothing(res) && error("invalid Bool: $(x.value)")

res < 3
end
Expand Down
10 changes: 8 additions & 2 deletions src/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ const process = Dict{Int,Function}( # TODO Use a Tuple instead?
w.tickByTickMidPoint(reqId, time, slurp(Float64, it))

else
@warn "TICK_BY_TICK: Unknown ticktype" T=ticktype
@warn "TICK_BY_TICK: unknown ticktype" T=ticktype
end
end,

Expand Down Expand Up @@ -1017,6 +1017,12 @@ const process = Dict{Int,Function}( # TODO Use a Tuple instead?
102 => (it, w, ver) -> w.completedOrdersEnd(),

# REPLACE_FA_END
103 => (it, w, ver) -> w.replaceFAEnd(slurp((Int,String), it)...)
103 => (it, w, ver) -> w.replaceFAEnd(slurp((Int,String), it)...),

# WSH_META_DATA
104 => (it, w, ver) -> w.wshMetaData(slurp((Int,String), it)...),

# WSH_EVENT_DATA
105 => (it, w, ver) -> w.wshEventData(slurp((Int,String), it)...)

)
6 changes: 3 additions & 3 deletions src/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ function start_reader(ib, w)
catch e

if e isa EOFError
@warn "Connection Terminated"
@warn "connection terminated"
else
@error "Exception thrown" e
@error "exception thrown" e
end
end

@info "Reader Exiting"
@info "reader exiting"
end
end

Expand Down
13 changes: 12 additions & 1 deletion src/requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,13 @@ cancelTickByTickData(ib::Connection, reqId::Int) = req_simple(ib, 98, reqId) ###

reqCompletedOrders(ib::Connection, apiOnly::Bool) = req_simple(ib, 99, apiOnly) ### REQ_COMPLETED_ORDERS

reqWshMetaData(ib::Connection, reqId::Int) = req_simple(ib, 100, reqId) ### REQ_WSH_META_DATA

cancelWshMetaData(ib::Connection, reqId::Int) = req_simple(ib, 101, reqId) ### CANCEL_WSH_META_DATA

reqWshEventData(ib::Connection, reqId::Int, conId::Int) = req_simple(ib, 102, reqId) ### REQ_WSH_EVENT_DATA

cancelWshEventData(ib::Connection, reqId::Int) = req_simple(ib, 103, reqId) ### CANCEL_WSH_EVENT_DATA

# Exports
export reqMktData,
Expand Down Expand Up @@ -689,5 +696,9 @@ export reqMktData,
reqHistoricalTicks,
reqTickByTickData,
cancelTickByTickData,
reqCompletedOrders
reqCompletedOrders,
reqWshMetaData,
cancelWshMetaData,
reqWshEventData,
cancelWshEventData
end
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function from_ibtime(s)
ZonedDateTime(DateTime(s[1:17], "yyyymmdd HH:MM:SS"), tz)

else
error("Unknown format $s")
error("unknown format $s")
end
end

Expand Down Expand Up @@ -57,7 +57,7 @@ function validatetz(tz)
tz"Asia/Shanghai"

else
error("Unknown TZ: $tz")
error("unknown TZ: $tz")
end
end

Expand Down
1 change: 1 addition & 0 deletions src/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
DURATION = 158
MARKET_DATA_IN_SHARES = 159
POST_TO_ATS = 160
WSHE_CALENDAR = 161

end
20 changes: 13 additions & 7 deletions src/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ struct Wrapper
completedOrder::Function
completedOrdersEnd::Function
replaceFAEnd::Function
wshMetaData::Function
wshEventData::Function
end
function Wrapper(; kw...)

Expand Down Expand Up @@ -136,7 +138,7 @@ function simple_wrap()
println("OpenOrder: $orderId $(orderstate.status)")
end,

openOrderEnd= () -> println("OpenOrderEnd."),
openOrderEnd= () -> println("OpenOrderEnd"),

updateAccountValue= (key::String, val::String, currency::String, accountName::String) ->
println("AccountValue: $key $val $currency $accountName"),
Expand Down Expand Up @@ -202,7 +204,7 @@ function simple_wrap()

scannerParameters= function(xml::String)
d[:scannerparam] = xml
println("ScannerParameters.")
println("ScannerParameters")
end,

scannerData= function(reqId::Int, rank::Vector{Int}, contractDetails::Vector{ContractDetails}, distance::Vector{String}, benchmark::Vector{String}, projection::Vector{String}, legsStr::Vector{String})
Expand Down Expand Up @@ -231,13 +233,13 @@ function simple_wrap()

commissionReport= function(commissionReport::CommissionReport)
d[:commission] = commissionReport
println("CommissionReport.")
println("CommissionReport")
end,

position= (account::String, contract::Contract, position::Float64, avgCost::Float64) ->
println("Position: $account $(contract.symbol) $position $avgCost"),

positionEnd= () -> println("PositionEnd."),
positionEnd= () -> println("PositionEnd"),

accountSummary= (reqId::Int, account::String, tag::String, value::String, currency::String) -> println("AccountSummary: $reqId $account $tag $value $currency"),

Expand Down Expand Up @@ -281,7 +283,7 @@ function simple_wrap()

mktDepthExchanges= function(depthMktDataDescriptions::DataFrame)
d[:mktdepthexchanges] = depthMktDataDescriptions
println("MktDepthExchanges.")
println("MktDepthExchanges")
end,

tickNews= (tickerId::Int, timeStamp::Int, providerCode::String, articleId::String, headline::String, extraData::String) ->
Expand All @@ -299,7 +301,7 @@ function simple_wrap()

newsProviders= function(newsProviders::DataFrame)
d[:newsproviders] = newsProviders
println("NewsProviders.")
println("NewsProviders")
end,

newsArticle= function(requestId::Int, articleType::Int, articleText::String)
Expand Down Expand Up @@ -377,9 +379,13 @@ function simple_wrap()
println("CompletedOrder: $(contract.symbol) $(orderState.status)")
end,

completedOrdersEnd= () -> println("CompletedOrdersEnd."),
completedOrdersEnd= () -> println("CompletedOrdersEnd"),

replaceFAEnd= (reqId::Int, text::String) -> println("ReplaceFAEnd: $reqId $text"),

wshMetaData= (reqId::Int, dataJson::String) -> println("WshMetaData: $reqId $dataJson"),

wshEventData= (reqId::Int, dataJson::String) -> println("WshEventData: $reqId $dataJson"),
)

d, w
Expand Down

0 comments on commit 880b345

Please sign in to comment.