Skip to content

Commit

Permalink
Update to API v179
Browse files Browse the repository at this point in the history
  • Loading branch information
lbilli committed Oct 19, 2023
1 parent facb730 commit e09ecc4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 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 <[email protected]>"]
version = "0.20.1"
version = "0.20.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ To install from GitHub:

### Usage
The user interacts mainly with these two objects:
- `Connection`: holding a reference to an established connection with the server
- `Wrapper`: containing the callbacks that are invoked when the server responses
are processed.
- `Connection`: a handle holding a connection to the server
- `Wrapper`: a container for the callbacks that are invoked
when the server responses are processed.

Other data structures, such as `Contract` and `Order`, are implemented as Julia `struct`
and mirror the respective classes in the official IB API.

A complete minimal working example is shown.
For this code to work, an instance of the IB TWS or IBGateway needs to be running
on the local machine, listening on port `4002`.
For this code to work, an instance of IB TWS or IBGateway needs to be running
on the local machine and listening on port `4002`.
**Note:** _demo_ or _paper_ account recommended!! :smirk:
```julia
using Jib
Expand Down Expand Up @@ -64,7 +64,7 @@ order = Jib.Order();
order.action = "BUY"
order.totalQuantity = 10
order.orderType = "LMT"
order.lmtPrice = 1000
order.lmtPrice = 100

orderId = 1 # Should match whatever is returned by the server

Expand Down
14 changes: 14 additions & 0 deletions src/enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@

@enum ConditionType PRICE=1 TIME=3 MARGIN=4 EXECUTION=5 VOLUME=6 PERCENTCHANGE=7


funddist(v) = v == "N" ? "Accumulation Fund" :
v == "Y" ? "Income Fund" :
"None"

fundtype(v) = v == "000" ? "Others" :
v == "001" ? "Money Market" :
v == "002" ? "Fixed Income" :
v == "003" ? "Multi-asset" :
v == "004" ? "Equity" :
v == "005" ? "Sector" :
v == "006" ? "Guaranteed" :
v == "007" ? "Alternative" :
"None"
10 changes: 10 additions & 0 deletions src/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import ...Bar,
...TickAttribLast,
...TickAttribBidAsk,
...condition_map,
...funddist,
...fundtype,
...ns


Expand Down Expand Up @@ -324,6 +326,14 @@ const process = Dict(
:sizeIncrement,
:suggestedSizeIncrement), it)

if ver Client.FUND_DATA_FIELDS && cd.contract.secType == "FUND"

slurp!(cd, 44:58, it)

cd.fundDistributionPolicyIndicator = funddist(slurp(String, it))
cd.fundAssetType = fundtype(slurp(String, it))
end

w.contractDetails(reqId, cd)
end,

Expand Down
20 changes: 19 additions & 1 deletion src/types_private.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,29 @@ mutable struct ContractDetails
nextOptionType::String
nextOptionPartial::Bool
notes::String
fundName::String
fundFamily::String
fundType::String
fundFrontLoad::String
fundBackLoad::String
fundBackLoadTimeInterval::String
fundManagementFee::String
fundClosed::Bool
fundClosedForNewInvestors::Bool
fundClosedForNewMoney::Bool
fundNotifyAmount::String
fundMinimumInitialPurchase::String
fundSubsequentMinimumPurchase::String
fundBlueSkyStates::String
fundBlueSkyTerritories::String
fundDistributionPolicyIndicator::String
fundAssetType::String
end
ContractDetails() = ContractDetails(Contract(), ns, 0, ns, ns, 0, 0, fill(ns, 9)...,
nothing, nothing, fill(ns, 6)..., nothing, nothing,
nothing, (;), fill(ns, 5)..., false, false,
nothing, false, ns, ns, ns, ns, false, ns)
nothing, false, ns, ns, ns, ns, false, ns,
fill(ns, 7)..., false, false, false, fill(ns, 7)...)


struct Execution
Expand Down
1 change: 1 addition & 0 deletions src/versions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
BOND_ISSUERID = 176
FA_PROFILE_DESUPPORT = 177
PENDING_PRICE_REVISION = 178
FUND_DATA_FIELDS = 179

end
4 changes: 2 additions & 2 deletions src/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function simple_wrap()

bondContractDetails = function(reqId::Int, contractDetails::ContractDetails)
d[:cdbond] = contractDetails
println("bondContractDetails: $reqId ", contractDetails.contract.conId)
println("bondContractDetails: $reqId $(contractDetails.contract.conId) $(contractDetails.contract.exchange) $(contractDetails.descAppend)")
end,

contractDetailsEnd= (reqId::Int) -> println("contractDetailsEnd: $reqId"),
Expand Down Expand Up @@ -247,7 +247,7 @@ function simple_wrap()
benchmark= benchmark,
projection= projection,
legsStr= legsStr)
println("scannerData: $reqId")
println("scannerData: $reqId $(length(rank))")
end,

realtimeBar= (reqId::Int, time::Int, open::Float64, high::Float64, low::Float64, close::Float64, volume::Float64, wap::Float64, count::Int) ->
Expand Down
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include("requests.jl")
include("roundtrip.jl")


@testset "TickType" begin
@testset "Utils" begin

@test Jib.Reader.tickname( 0) == "BID_SIZE"

Expand All @@ -18,9 +18,16 @@ include("roundtrip.jl")

@test (@test_logs (:error, "tickname(): unknown ticktype") Jib.Reader.tickname(-1)) == "UNKNOWN"

@test Jib.funddist("Y") == "Income Fund"
@test Jib.fundtype("003") == "Multi-asset"
@test Jib.funddist("") == Jib.fundtype("") == "None"

@test fieldname(Jib.Contract, 15) === :secId
@test fieldname(Jib.Contract, 17) === :issuerId

@test fieldname(Jib.ContractDetails, 44) === :fundName
@test fieldname(Jib.ContractDetails, 58) === :fundBlueSkyTerritories

@test fieldname(Jib.Order, 79) === :account
@test fieldname(Jib.Order, 125) === :parentPermId

Expand Down

0 comments on commit e09ecc4

Please sign in to comment.