简体   繁体   中英

R IBrokers algoStrategy option when submitting twsOrder

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));
}

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')))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM