0

I am trying to use an Adaptive Algo from Interactive Brokers. It seems like IBrokers package for R (https://cran.r-project.org/web/packages/IBrokers/IBrokers.pdf - pg37 and 38) was not completed as my order does not go through when I execute the code below.

  tws <- twsConnect()

  stockEquity <- twsEquity("AAPL")

  parentLongId <- reqIds(tws)

  parentLongOrder <- twsOrder(parentLongId, action="BUY", totalQuantity = 100, orderType = "MKT", transmit=TRUE, 
algoStrategy ="Adaptive", algoParams = "Normal")

I found API Guide on GitHub (http://interactivebrokers.github.io/tws-api/ibalgos.html) for JAVA, Python, C# and C++. I was wondering if anyone knows how to convert the codes into R.

Example of Java,

  Order baseOrder = OrderSamples.LimitOrder("BUY", 1000, 1);
  AvailableAlgoParams.FillAdaptiveParams(baseOrder, "Normal");
  client.placeOrder(nextOrderId++, ContractSamples.USStockAtSmart(), baseOrder);
public static void FillAdaptiveParams(Order baseOrder, String priority) {
    baseOrder.algoStrategy("Adaptive");
    baseOrder.algoParams(new ArrayList<>());
    baseOrder.algoParams().add(new TagValue("adaptivePriority", priority));
}
  • 1
    Possible duplicate of [R IBrokers (Interactive Brokers API)](https://stackoverflow.com/questions/46482300/r-ibrokers-interactive-brokers-api) – phiver Apr 02 '18 at 12:48

1 Answers1

0

I think the easiest way for R users to access all of IBALGO is to install the Reticulate package which allows you to use Python in R. Then install ib_insync Python module. Now you can use R to manage IB API in almost every way as if working within its native Python thanks to Reticulate.

Just remember that the syntax to use the equivalent of Python's TagValue translate in R looks like this:

algoStrategy = 'Adaptive',
algoParams = list(insync$TagValue('adaptivePriority', 'Normal')))
ogukku
  • 53
  • 7