Skip to content

RobinHood R API

2 messages · Steve Hun, Daniel Cegiełka

#
hi,
Has anyone used the RobinHood package for order management? For example, dynamic stop level setting (in other words, not use standard trailing stop) and filled order tracking?
Thanks
3 days later
#
Hi Steve,

I have never worked with RobinHood, but I have analyzed the code of
this package. Maybe my insights will be useful for you.

RobinHood, as well as Alpaca Markets, operate in the PFOF model
(payment for order flow). Your order does not go public, but is sold
to market makers. Is it good or bad? Currently, the PFOF model is
regulated by Regulation NMS[1] - your order must be filled at a price
equal to or better than the NBBO (National Best Bid and Offer) or best
price rule in short. In fact, most brokers work in the PFOF model too
- you pay a commission, but they sell your orders anyway. So RH and
Alpaca are fair here - if we make money from selling your order, you
do not pay commissions anymore. I explain this because I have noticed
that many people don't understand the RH and Alpaca's business model.

[1] https://www.investopedia.com/terms/r/regulation-nms.asp

As for this R package, it works in the request-response model. It's
not the best pattern for algo trading. Your application will have to
work in the so-called batch model:

repeat {
    get_mktdata()
    get_positions()
    calc_model_and_risk()
    place_orders()
    sleep(x_min_or_even_more)
}

This is inefficient, so this solution is only suitable for very slow
models. It's difficult to manage the execution, so you should place
orders type of market.

The best pattern for algo trading is event-driven. Here you subscribe
to data stream (events) and your application responds to every new
message. IBrokers is written in this model:

https://github.com/joshuaulrich/IBrokers/blob/master/vignettes/RealTime.pdf

Your minimal strategy should look like this:

subscribe(c('AAPL', 'MSFT', 'GS'))

on_tick <- function()
{
    (...)
    place_order(...)
}

on_order <- function()
{
    # accepted, rejected etc.
}

on_exec <- function()
{
}

on_system_event <- function()
{
}

# main event loop
run_strategy(host = 'api_server', port = 123, daemon = TRUE)


place_order() means submit  and subscribe orders events.
an event-driven model.

I hope that will be helpful for you.

Best regards,
Daniel






czw., 4 kwi 2019 o 19:28 Steve Hun via R-SIG-Finance
<r-sig-finance at r-project.org> napisa?(a):