Skip to content

Commit

Permalink
Update to API v169
Browse files Browse the repository at this point in the history
  • Loading branch information
lbilli committed Mar 15, 2022
1 parent 2bb7ab2 commit 5c2c1e6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 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.13.5
Version: 0.14.0
Authors@R: person("Luca", "Billi", email = "noreply.section+dev@gmail.com", 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
21 changes: 15 additions & 6 deletions R/IBClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ IBClient <- R6::R6Class("IBClient",
#
# ########################################################################

reqMktData= function(tickerId, contract, genericTicks="", snapshot=TRUE, regulatorySnaphsot=FALSE, mktDataOptions=character()) {
reqMktData= function(tickerId, contract, genericTicks, snapshot, regulatorySnaphsot=FALSE, mktDataOptions=character()) {

msg <- c("1", "11") ### REQ_MKT_DATA

Expand Down Expand Up @@ -445,6 +445,9 @@ IBClient <- R6::R6Class("IBClient",
if(self$serVersion >= MIN_SERVER_VER_ADVANCED_ORDER_REJECT)
payload <- c(payload, order$advancedErrorOverride)

if(self$serVersion >= MIN_SERVER_VER_MANUAL_ORDER_TIME)
payload <- c(payload, order$manualOrderTime)

# Convert NA -> ""
payload[is.na(payload)] <- ""

Expand All @@ -454,16 +457,22 @@ IBClient <- R6::R6Class("IBClient",
private$encodeMsg(msg)
},

cancelOrder= function(id) private$req_simple("4", "1", id), ### CANCEL_ORDER
cancelOrder= function(id, manualOrderCancelTime) {

msg <- c("4", "1", ### CANCEL_ORDER
id,
if(self$serVersion >= MIN_SERVER_VER_MANUAL_ORDER_TIME) manualOrderCancelTime)

# Encode and send
private$encodeMsg(msg)
},

reqOpenOrders= function() private$req_simple("5", "1"), ### REQ_OPEN_ORDERS

reqAccountUpdates= function(subscribe, acctCode) {

msg <- c("6", "2") ### REQ_ACCT_DATA

# Add payload
msg <- c(msg, private$sanitize(list(subscribe, acctCode)))
msg <- c("6", "2", ### REQ_ACCT_DATA
private$sanitize(list(subscribe, acctCode)))

# Encode and send
private$encodeMsg(msg)
Expand Down
4 changes: 3 additions & 1 deletion R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ 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
MIN_SERVER_VER_MANUAL_ORDER_TIME <- 169L


MIN_CLIENT_VER <- 157L
MAX_CLIENT_VER <- MIN_SERVER_VER_USER_INFO
MAX_CLIENT_VER <- MIN_SERVER_VER_MANUAL_ORDER_TIME
3 changes: 2 additions & 1 deletion R/structs.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ Order <- list(orderId= 0L,
usePriceMgmtAlgo= NA,
duration= NA_integer_,
postToAts= NA_integer_,
advancedErrorOverride= "")
advancedErrorOverride= "",
manualOrderTime= "")

ScannerSubscription <- list(numberOfRows= -1L,
instrument= "",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ IBWrapCustom <- R6::R6Class("IBWrapCustom",

public= list(
# Customized methods go here
error= function(id, errorCode, errorString)
cat("Error:", id, errorCode, errorString, "\n"),
error= function(id, errorCode, errorString, advancedOrderRejectJson)
cat("Error:", id, errorCode, errorString, advancedOrderRejectJson, "\n"),

nextValidId= function(orderId)
cat("Next OrderId:", orderId, "\n"),
Expand Down
2 changes: 1 addition & 1 deletion inst/data-raw/codes_struct.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct type name
Contract i,c,c,c,n,c,c,c,c,c,c,c,l,c,c,c,vComboLeg,oDeltaNeutralContract conId,symbol,secType,lastTradeDateOrContractMonth,strike,right,multiplier,exchange,primaryExchange,currency,localSymbol,tradingClass,includeExpired,secIdType,secId,comboLegsDescrip,comboLegs,deltaNeutralContract
ContractDetails Contract,c,n,c,c,i,i,c,c,c,c,c,c,c,c,c,n,i,c,c,c,c,c,c,n,n,n,TagValue,c,c,c,c,c,l,l,n,l,c,c,c,c,l,c contract,marketName,minTick,orderTypes,validExchanges,priceMagnifier,underConId,longName,contractMonth,industry,category,subcategory,timeZoneId,tradingHours,liquidHours,evRule,evMultiplier,aggGroup,underSymbol,underSecType,marketRuleIds,realExpirationDate,lastTradeTime,stockType,minSize,sizeIncrement,suggestedSizeIncrement,secIdList,cusip,ratings,descAppend,bondType,couponType,callable,putable,coupon,convertible,maturity,issueDate,nextOptionDate,nextOptionType,nextOptionPartial,notes
ContractDescription Contract,c contract,derivativeSecTypes
Order i,i,i,c,n,c,n,n,c,c,c,c,i,c,l,i,l,l,i,i,l,l,c,c,c,l,i,n,l,n,n,c,c,c,c,c,c,i,c,i,n,l,c,n,n,n,n,n,l,l,n,i,c,n,i,c,c,c,c,l,i,c,l,i,n,i,i,i,n,n,i,n,l,i,i,l,c,c,c,c,c,c,c,c,TagValue,TagValue,c,l,l,l,c,n,TagValue,i,n,l,n,c,c,n,n,n,n,i,n,vCondition,l,l,c,SoftDollarTier,n,c,c,c,c,l,l,l,c,n,i,l,c,l,l,i,l,i,i,c orderId,clientId,permId,action,totalQuantity,orderType,lmtPrice,auxPrice,tif,activeStartTime,activeStopTime,ocaGroup,ocaType,orderRef,transmit,parentId,blockOrder,sweepToFill,displaySize,triggerMethod,outsideRth,hidden,goodAfterTime,goodTillDate,rule80A,allOrNone,minQty,percentOffset,overridePercentageConstraints,trailStopPrice,trailingPercent,faGroup,faProfile,faMethod,faPercentage,openClose,origin,shortSaleSlot,designatedLocation,exemptCode,discretionaryAmt,optOutSmartRouting,auctionStrategy,startingPrice,stockRefPrice,delta,stockRangeLower,stockRangeUpper,randomizeSize,randomizePrice,volatility,volatilityType,deltaNeutralOrderType,deltaNeutralAuxPrice,deltaNeutralConId,deltaNeutralSettlingFirm,deltaNeutralClearingAccount,deltaNeutralClearingIntent,deltaNeutralOpenClose,deltaNeutralShortSale,deltaNeutralShortSaleSlot,deltaNeutralDesignatedLocation,continuousUpdate,referencePriceType,basisPoints,basisPointsType,scaleInitLevelSize,scaleSubsLevelSize,scalePriceIncrement,scalePriceAdjustValue,scalePriceAdjustInterval,scaleProfitOffset,scaleAutoReset,scaleInitPosition,scaleInitFillQty,scaleRandomPercent,scaleTable,hedgeType,hedgeParam,account,settlingFirm,clearingAccount,clearingIntent,algoStrategy,algoParams,smartComboRoutingParams,algoId,whatIf,notHeld,solicited,modelCode,orderComboLegs,orderMiscOptions,referenceContractId,peggedChangeAmount,isPeggedChangeAmountDecrease,referenceChangeAmount,referenceExchangeId,adjustedOrderType,triggerPrice,adjustedStopPrice,adjustedStopLimitPrice,adjustedTrailingAmount,adjustableTrailingUnit,lmtPriceOffset,conditions,conditionsCancelOrder,conditionsIgnoreRth,extOperator,softDollarTier,cashQty,mifid2DecisionMaker,mifid2DecisionAlgo,mifid2ExecutionTrader,mifid2ExecutionAlgo,dontUseAutoPriceForHedge,isOmsContainer,discretionaryUpToLimitPrice,autoCancelDate,filledQuantity,refFuturesConId,autoCancelParent,shareholder,imbalanceOnly,routeMarketableToBbo,parentPermId,usePriceMgmtAlgo,duration,postToAts,advancedErrorOverride
Order i,i,i,c,n,c,n,n,c,c,c,c,i,c,l,i,l,l,i,i,l,l,c,c,c,l,i,n,l,n,n,c,c,c,c,c,c,i,c,i,n,l,c,n,n,n,n,n,l,l,n,i,c,n,i,c,c,c,c,l,i,c,l,i,n,i,i,i,n,n,i,n,l,i,i,l,c,c,c,c,c,c,c,c,TagValue,TagValue,c,l,l,l,c,n,TagValue,i,n,l,n,c,c,n,n,n,n,i,n,vCondition,l,l,c,SoftDollarTier,n,c,c,c,c,l,l,l,c,n,i,l,c,l,l,i,l,i,i,c,c orderId,clientId,permId,action,totalQuantity,orderType,lmtPrice,auxPrice,tif,activeStartTime,activeStopTime,ocaGroup,ocaType,orderRef,transmit,parentId,blockOrder,sweepToFill,displaySize,triggerMethod,outsideRth,hidden,goodAfterTime,goodTillDate,rule80A,allOrNone,minQty,percentOffset,overridePercentageConstraints,trailStopPrice,trailingPercent,faGroup,faProfile,faMethod,faPercentage,openClose,origin,shortSaleSlot,designatedLocation,exemptCode,discretionaryAmt,optOutSmartRouting,auctionStrategy,startingPrice,stockRefPrice,delta,stockRangeLower,stockRangeUpper,randomizeSize,randomizePrice,volatility,volatilityType,deltaNeutralOrderType,deltaNeutralAuxPrice,deltaNeutralConId,deltaNeutralSettlingFirm,deltaNeutralClearingAccount,deltaNeutralClearingIntent,deltaNeutralOpenClose,deltaNeutralShortSale,deltaNeutralShortSaleSlot,deltaNeutralDesignatedLocation,continuousUpdate,referencePriceType,basisPoints,basisPointsType,scaleInitLevelSize,scaleSubsLevelSize,scalePriceIncrement,scalePriceAdjustValue,scalePriceAdjustInterval,scaleProfitOffset,scaleAutoReset,scaleInitPosition,scaleInitFillQty,scaleRandomPercent,scaleTable,hedgeType,hedgeParam,account,settlingFirm,clearingAccount,clearingIntent,algoStrategy,algoParams,smartComboRoutingParams,algoId,whatIf,notHeld,solicited,modelCode,orderComboLegs,orderMiscOptions,referenceContractId,peggedChangeAmount,isPeggedChangeAmountDecrease,referenceChangeAmount,referenceExchangeId,adjustedOrderType,triggerPrice,adjustedStopPrice,adjustedStopLimitPrice,adjustedTrailingAmount,adjustableTrailingUnit,lmtPriceOffset,conditions,conditionsCancelOrder,conditionsIgnoreRth,extOperator,softDollarTier,cashQty,mifid2DecisionMaker,mifid2DecisionAlgo,mifid2ExecutionTrader,mifid2ExecutionAlgo,dontUseAutoPriceForHedge,isOmsContainer,discretionaryUpToLimitPrice,autoCancelDate,filledQuantity,refFuturesConId,autoCancelParent,shareholder,imbalanceOnly,routeMarketableToBbo,parentPermId,usePriceMgmtAlgo,duration,postToAts,advancedErrorOverride,manualOrderTime
OrderState c,c,c,c,c,c,c,c,c,c,n,n,n,c,c,c,c status,initMarginBefore,maintMarginBefore,equityWithLoanBefore,initMarginChange,maintMarginChange,equityWithLoanChange,initMarginAfter,maintMarginAfter,equityWithLoanAfter,commission,minCommission,maxCommission,commissionCurrency,warningText,completedTime,completedStatus
Execution c,c,c,c,c,n,n,i,i,i,i,n,n,c,c,n,c,i execId,time,acctNumber,exchange,side,shares,price,permId,clientId,orderId,liquidation,cumQty,avgPrice,orderRef,evRule,evMultiplier,modelCode,lastLiquidity
ExecutionFilter i,c,c,c,c,c,c clientId,acctCode,time,symbol,secType,exchange,side
Expand Down

0 comments on commit 5c2c1e6

Please sign in to comment.