yogat3ch / AlpacaforR

Connecting to Alpaca API and using it with R
35 stars 20 forks source link

Streaming #31

Closed MislavSag closed 2 years ago

MislavSag commented 3 years ago

First, thanks for the great package. I think this is the first package of this kind in R. The main reason I moved to python, from R, are great backtest / trading tools.

I saw on Alpaca site some examples with streaming: https://github.com/alpacahq/alpaca-trade-api-python/tree/master/examples

Is it even possible to set up the stream with this package, even theoretically?

yogat3ch commented 3 years ago

Yes, check out the fork over on github.com/yogat3ch/AlpacaforR where it is implemented.

MislavSag commented 3 years ago

There is no vignette("AlpacaforR", "Websockets") in you fork?

yogat3ch commented 3 years ago

Oops, forgot to finish that! I'll get one up by the end of the weekend. I think the helpfiles give a pretty good understanding of how to use it in lieu of the vignette.

MislavSag commented 3 years ago

Is it possible to use websocket with paper trading? I am from EU, so, for now I am planning to just use alpaca for backtesting and paper trading. I wold be great if there would be few samples of trading strategies, like this one: https://github.com/alpacahq/alpaca-trade-api-python/tree/master/examples

yogat3ch commented 3 years ago

Websockets streaming of price data comes through Polygon and thus only users with cash accounts are able to use the feature. You will have access to just trade and account updates as solely a paper user.

yogat3ch commented 3 years ago

As for trading strategies - that's where your creativity comes in :D

MislavSag commented 3 years ago

Without price data, I think it is nor usefull. In the end I think you have to use web socket with price data, to test your strategies. I already have some srategies, but in python. But I have analysis in R, so I hope I will set it up with AlpacaforR. The thing is that there are great packages like backtrader and quantconnect for backtesting/trading and there is nothing even close in R.

yogat3ch commented 3 years ago

You can access historical price data from the Alpaca v1 API through the market_data function. Websockets are for streaming realtime price data - only necessary if you are live-testing your algorithm. You can backtest to your heart's desire with the historical data. I personally built my own backtesting engine but you can check out quantstrat (an older package) and flyingfox for existing backtesting functionality in R.

MislavSag commented 3 years ago

It seems quantstrat is not maintained anymore. Do you take into account slippage, market impact, possibility that order want be fulfilled ant other important factors in backtesing?

yogat3ch commented 3 years ago

Account slippage - no, it's random. Market impact - no, I'm not trading with enough money to where that matters. Possibility that order won't be fulfilled - the strategy is made such that unfilled orders don't matter.

yogat3ch commented 2 years ago

I think these are questions or Alpaca itself, I'm closing this issue unless there's a reason to re-open it. Thanks!