Skip to content

Commit

Permalink
Drop support for API < v165
Browse files Browse the repository at this point in the history
  • Loading branch information
lbilli committed Jul 21, 2022
1 parent e037605 commit c45c4a2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 61 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rib
Title: An R implementation of Interactive Brokers API
Version: 0.15.1
Version: 0.16.0
Authors@R: person("Luca", "Billi", email = "[email protected]", role = c("aut", "cre"))
Description: A native R implementation of Interactive Brokers API.
It establishes a TCP connection to a server and handles
Expand Down
57 changes: 17 additions & 40 deletions R/Decoder.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ Decoder <- R6::R6Class("Decoder",
# The first field is the message ID
msgId <- imsg$pop()

# The second field is unused version, for msgId < 75 and != 3, 5, 11, 17, 21
# The second field is unused version, for msgId < 75 and != 3, 5, 10, 11, 17, 18, 21
imsgId <- Validator$i(msgId)
if(imsgId < 75L && ! imsgId %in% c(3L, 5L, 10L, 11L, 17L, 18L, 21L) ||
imsgId %in% c(10L, 18L) && private$serverVersion < MIN_SERVER_VER_SIZE_RULES)
if(imsgId < 75L && ! imsgId %in% c(3L, 5L, 10L, 11L, 17L, 18L, 21L))
imsg$pop()

# Convert ID -> Name
Expand Down Expand Up @@ -373,16 +372,10 @@ Decoder <- R6::R6Class("Decoder",
"dontUseAutoPriceForHedge",
"isOmsContainer",
"discretionaryUpToLimitPrice",
"usePriceMgmtAlgo")] <- imsg$pop(5L)

if(private$serverVersion >= MIN_SERVER_VER_DURATION)
order$duration <- imsg$pop()

if(private$serverVersion >= MIN_SERVER_VER_POST_TO_ATS)
order$postToAts <- imsg$pop()

if(private$serverVersion >= MIN_SERVER_VER_AUTO_CANCEL_PARENT)
order$autoCancelParent <- imsg$pop()
"usePriceMgmtAlgo",
"duration",
"postToAts",
"autoCancelParent")] <- imsg$pop(8L)

if(private$serverVersion >= MIN_SERVER_VER_PEGBEST_PEGMID_OFFSETS)
order[c("minTradeQty",
Expand Down Expand Up @@ -446,10 +439,6 @@ Decoder <- R6::R6Class("Decoder",
cd$contract$tradingClass <- imsg$pop()
cd$contract$conId <- imsg$pop()
cd$minTick <- imsg$pop()

if(private$serverVersion < MIN_SERVER_VER_SIZE_RULES)
imsg$pop() # deprecated mdSizeMultiplier

cd$contract$multiplier <- imsg$pop()
cd[4L:8L] <- imsg$pop(5L)
cd$contract$primaryExchange <- imsg$pop()
Expand All @@ -465,16 +454,10 @@ Decoder <- R6::R6Class("Decoder",
"underSecType",
"marketRuleIds",
"realExpirationDate",
"stockType")] <- imsg$pop(6L)

if(private$serverVersion >= MIN_SERVER_VER_FRACTIONAL_SIZE_SUPPORT &&
private$serverVersion < MIN_SERVER_VER_SIZE_RULES)
imsg$pop() # deprecated sizeMinTick

if(private$serverVersion >= MIN_SERVER_VER_SIZE_RULES)
cd[c("minSize",
"sizeIncrement",
"suggestedSizeIncrement")] <- imsg$pop(3L)
"stockType",
"minSize",
"sizeIncrement",
"suggestedSizeIncrement")] <- imsg$pop(9L)

private$validate("contractDetails", reqId=reqId, contractDetails=cd)
},
Expand Down Expand Up @@ -507,33 +490,27 @@ Decoder <- R6::R6Class("Decoder",
cd$contract[c("tradingClass",
"conId")] <- imsg$pop(2L)

cd$minTick <- imsg$pop()

if(private$serverVersion < MIN_SERVER_VER_SIZE_RULES)
imsg$pop() # deprecated mdSizeMultiplier

cd[c("orderTypes",
cd[c("minTick",
"orderTypes",
"validExchanges",
"nextOptionDate",
"nextOptionType",
"nextOptionPartial",
"notes",
"longName",
"evRule",
"evMultiplier")] <- imsg$pop(9L)
"evMultiplier")] <- imsg$pop(10L)

n <- Validator$i(imsg$pop())

if(n > 0L)
cd$secIdList <- fold_tagvalue(imsg$pop(2L * n))

cd[c("aggGroup",
"marketRuleIds")] <- imsg$pop(2L)

if(private$serverVersion >= MIN_SERVER_VER_SIZE_RULES)
cd[c("minSize",
"sizeIncrement",
"suggestedSizeIncrement")] <- imsg$pop(3L)
"marketRuleIds",
"minSize",
"sizeIncrement",
"suggestedSizeIncrement")] <- imsg$pop(5L)

private$validate("bondContractDetails", reqId=reqId, contractDetails=cd)
},
Expand Down
14 changes: 4 additions & 10 deletions R/IBClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,10 @@ IBClient <- R6::R6Class("IBClient",
"dontUseAutoPriceForHedge",
"isOmsContainer",
"discretionaryUpToLimitPrice",
"usePriceMgmtAlgo")])

if(self$serVersion >= MIN_SERVER_VER_DURATION)
payload <- c(payload, order$duration)

if(self$serVersion >= MIN_SERVER_VER_POST_TO_ATS)
payload <- c(payload, order$postToAts)

if(self$serVersion >= MIN_SERVER_VER_AUTO_CANCEL_PARENT)
payload <- c(payload, order$autoCancelParent)
"usePriceMgmtAlgo",
"duration",
"postToAts",
"autoCancelParent")])

if(self$serVersion >= MIN_SERVER_VER_ADVANCED_ORDER_REJECT)
payload <- c(payload, order$advancedErrorOverride)
Expand Down
10 changes: 1 addition & 9 deletions R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ HEADER_LEN <- 4L
MAX_MSG_LEN <- 0xFFFFFFL # 16Mb - 1b

# Server Versions
MIN_SERVER_VER_DURATION <- 158L
MIN_SERVER_VER_MARKET_DATA_IN_SHARES <- 159L
MIN_SERVER_VER_POST_TO_ATS <- 160L
MIN_SERVER_VER_WSHE_CALENDAR <- 161L
MIN_SERVER_VER_AUTO_CANCEL_PARENT <- 162L
MIN_SERVER_VER_FRACTIONAL_SIZE_SUPPORT <- 163L
MIN_SERVER_VER_SIZE_RULES <- 164L
MIN_SERVER_VER_HISTORICAL_SCHEDULE <- 165L
MIN_SERVER_VER_ADVANCED_ORDER_REJECT <- 166L
MIN_SERVER_VER_USER_INFO <- 167L
MIN_SERVER_VER_CRYPTO_AGGREGATED_TRADES <- 168L
Expand All @@ -25,5 +17,5 @@ MIN_SERVER_VER_IPO_PRICES <- 172L
MIN_SERVER_VER_WSH_EVENT_DATA_FILTERS_DATE <- 173L


MIN_CLIENT_VER <- 157L
MIN_CLIENT_VER <- 165L
MAX_CLIENT_VER <- MIN_SERVER_VER_WSH_EVENT_DATA_FILTERS_DATE
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ implements [Interactive Brokers](https://www.interactivebrokers.com/) API
to communicate with their TWS or IBGateway.

It aims to be feature complete, however it does not support legacy versions.
Currently, only API versions `v157+` are supported.
Currently, only API versions `v165+` are supported.

The package design mirrors the official C++/Java
[IB API](https://interactivebrokers.github.io/tws-api/),
Expand Down

0 comments on commit c45c4a2

Please sign in to comment.