Skip to content

Commit

Permalink
Added necessary parameters to handle multiple sink formats. Functiona…
Browse files Browse the repository at this point in the history
…lity unchanged. Transparent if you pass DataFrame to you initial processing method.
  • Loading branch information
oliviermilla committed Feb 22, 2024
1 parent a24e0a1 commit db4b9c6
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 141 deletions.
7 changes: 6 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ version = "0.20.4"

[deps]
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

[weakdeps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

[extensions]
DataFramesExt = "DataFrames"

[compat]
DataFrames = "1.0"
julia = "1.7"
Expand All @@ -15,4 +20,4 @@ julia = "1.7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "DataFrames"]
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,17 @@ Jib.disconnect(ib)
##### Foreground vs. Background Processing
It is possible to process the server responses either within the main process
or in a separate background `Task`:
- **foreground processing** is triggered by invoking `Jib.check_all(ib, wrap)`.
- **foreground processing** is triggered by invoking `Jib.check_all(ib, wrap, Tab=Dict)`.
It is the user's responsibility to call it on a **regular basis**,
especially when data are streaming in.
- **background processing** is started by `Jib.start_reader(ib, wrap)`.
- **background processing** is started by `Jib.start_reader(ib, wrap, Tab=Dict)`.
A separate `Task` is started in the background, which monitors the connection and processes
the responses as they arrive.

Tab is the sink format. that is used when applicable. The library supports an extension for
DataFrames (just pass `DataFrame` as a last parameter to the above functions), otherwise
you'll receive a Dict as a default format.

To avoid undesired effects, the two approaches should not be mixed together
on the same connection.

Expand Down
20 changes: 10 additions & 10 deletions data/wrapper_signatures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ managedAccounts(accountsList::String)

receiveFA(faDataType::FaDataType, xml::String)

historicalData(reqId::Int, bar::DataFrame)
historicalData(reqId::Int, bar::Dict)

scannerParameters(xml::String)

Expand Down Expand Up @@ -106,15 +106,15 @@ familyCodes(familyCodes::Vector{FamilyCode})

symbolSamples(reqId::Int, contractDescriptions::Vector{ContractDescription})

mktDepthExchanges(depthMktDataDescriptions::DataFrame)
mktDepthExchanges(depthMktDataDescriptions::Dict)

tickNews(tickerId::Int, timeStamp::Int, providerCode::String, articleId::String, headline::String, extraData::String)

smartComponents(reqId::Int, theMap::DataFrame)
smartComponents(reqId::Int, theMap::Dict)

tickReqParams(tickerId::Int, minTick::Union{Float64,Nothing}, bboExchange::String, snapshotPermissions::Int)

newsProviders(newsProviders::DataFrame)
newsProviders(newsProviders::Dict)

newsArticle(requestId::Int, articleType::Int, articleText::String)

Expand All @@ -124,25 +124,25 @@ historicalNewsEnd(requestId::Int, hasMore::Bool)

headTimestamp(reqId::Int, headTimestamp::String)

histogramData(reqId::Int, data::DataFrame)
histogramData(reqId::Int, data::Dict)

historicalDataUpdate(reqId::Int, bar::Bar)

rerouteMktDataReq(reqId::Int, conid::Int, exchange::String)

rerouteMktDepthReq(reqId::Int, conid::Int, exchange::String)

marketRule(marketRuleId::Int, priceIncrements::DataFrame)
marketRule(marketRuleId::Int, priceIncrements::Dict)

pnl(reqId::Int, dailyPnL::Float64, unrealizedPnL::Float64, realizedPnL::Float64)

pnlSingle(reqId::Int, pos::Int, dailyPnL::Float64, unrealizedPnL::Union{Float64,Nothing}, realizedPnL::Union{Float64,Nothing}, value::Float64)

historicalTicks(reqId::Int, ticks::DataFrame, done::Bool)
historicalTicks(reqId::Int, ticks::Dict, done::Bool)

historicalTicksBidAsk(reqId::Int, ticks::DataFrame, done::Bool)
historicalTicksBidAsk(reqId::Int, ticks::Dict, done::Bool)

historicalTicksLast(reqId::Int, ticks::DataFrame, done::Bool)
historicalTicksLast(reqId::Int, ticks::Dict, done::Bool)

tickByTickAllLast(reqId::Int, tickType::Int, time::Int, price::Float64, size::Float64, attribs::TickAttribLast, exchange::String, specialConditions::String)

Expand All @@ -162,6 +162,6 @@ wshMetaData(reqId::Int, dataJson::String)

wshEventData(reqId::Int, dataJson::String)

historicalSchedule(reqId::Int, startDateTime::String, endDateTime::String, timeZone::String, sessions::DataFrame)
historicalSchedule(reqId::Int, startDateTime::String, endDateTime::String, timeZone::String, sessions::Dict)

userInfo(reqId::Int, whiteBrandingId::String)
21 changes: 21 additions & 0 deletions ext/DataFramesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module DataFramesExt

import Jib

using DataFrames

function Jib.Reader.fill_table(cols, n::Int, it, Tab::Type{<:DataFrame})

df = Tab([k => Vector{T}(undef, n) for (k, T) pairs(cols)];
copycols=false)

nr, nc = size(df)

for r 1:nr, c 1:nc
df[r, c] = Jib.Reader.pop(it)
end

df
end

end
3 changes: 1 addition & 2 deletions src/Jib.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Jib

using DataFrames,
Sockets
using Sockets

include("client.jl")
include("enums.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include("ticktype.jl")
# Make a shortcut
const pop = popfirst!

function decode(it, w, ver)
function decode(it, w, ver, Tab=Dict)

# The first field is the message ID
id::Int = pop(it)
Expand All @@ -23,7 +23,7 @@ function decode(it, w, ver)

else
try
f(it, w, ver)
f(it, w, ver, Tab)
catch e
@error "decode(): exception caught" M=it.msg
# Print stacktrace to stderr
Expand Down
Loading

0 comments on commit db4b9c6

Please sign in to comment.