AlpacaSocket | R Documentation |
A WebSocket with modifications for Alpaca/Polygon websocket streams. \lifecycleexperimental
websocket::WebSocket
-> AlpacaSocket
opts
Options supplied to AlpacaStreams$new()
are stored here. Channel specific streams are stored in nested lists with the channel/stream name. All of these options can be altered after the websocket has been activated, with the exception of write_dir
.
websocket::WebSocket$clearAccessLogChannels()
websocket::WebSocket$clearErrorLogChannels()
websocket::WebSocket$close()
websocket::WebSocket$connect()
websocket::WebSocket$onClose()
websocket::WebSocket$onError()
websocket::WebSocket$onMessage()
websocket::WebSocket$onOpen()
websocket::WebSocket$protocol()
websocket::WebSocket$readyState()
websocket::WebSocket$send()
websocket::WebSocket$setAccessLogChannels()
websocket::WebSocket$setErrorLogChannels()
new()
Connect to an Alpaca websocket
AlpacaSocket$new(opts, ...)
opts
passed from AlpacaStreams
...
passed on to WebSocket
lastmessage()
Returns the last message received by the socket
AlpacaSocket$lastmessage()
logs()
Returns the message log
AlpacaSocket$logs(channel)
channel
(character)
Channel name of logs to be returned. Use "status"
to get all status messages for the socket.
channel()
Sends request to websocket to join the specified channel. Channel options are inherited from defaults set in AlpacaStreams$initialize
unless overridden. Notes 1. the Polygon website is only available to Polygon subscribers. 2. The sip
data stream is only available to Alpaca PRO subscribers.
AlpacaSocket$channel( channel = NULL, subscribe = TRUE, overwrite = FALSE, msg_action = NULL, ... )
channel
The channel to join.
For Alpaca v1: (character)
vector of symbols
For Alpaca Data v2: (named list)
Items with names trades
, quotes
, bars
are accepted. See the https://alpaca.markets/docs/api-documentation/api-v2/market-data/alpaca-data-api-v2/real-time#subscribe for details.
For Polygon: (character)
vector of channels formatted according to the websocket documentation.
subscribe
(logical)
Default TRUE
. Set to FALSE
to unsubscribe from specified channel(s).
overwrite
(logical)
Default FALSE
. Set to TRUE
to overwrite data from previous instances of this channel socket.
msg_action
(expression)
An expression that performs a user-specified action on the receipt of websocket message. These act on the msg
object seen printed to the console when a message is received (if toConsole = TRUE
). The msg
object also contains a $ts
column with the timestamp as a POSIXct
and a $socket
column with the socket name of origin ("Alpaca"/"Polygon"
) that are not visible in what is printed to the console but accessible to msg_action
. The expression can also reference the self
internal environment of this R6Class
.
...
Named arguments from AlpacaStreams$new()
If log = TRUE
for a Polygon channel, all non-status messages will be stored as tibbles named according to their respective channel name and accessed via the $logs()
method.
auth()
Authorize the stream (this is done automatically when initializing via the AlpacaStreams
class.)
AlpacaSocket$auth()
clone()
The objects of this class are cloneable with this method.
AlpacaSocket$clone(deep = FALSE)
deep
Whether to make a deep clone.
websocket::WebSocket
-> AlpacaforR::AlpacaSocket
-> PolygonSocket
websocket::WebSocket$clearAccessLogChannels()
websocket::WebSocket$clearErrorLogChannels()
websocket::WebSocket$close()
websocket::WebSocket$connect()
websocket::WebSocket$onClose()
websocket::WebSocket$onError()
websocket::WebSocket$onMessage()
websocket::WebSocket$onOpen()
websocket::WebSocket$protocol()
websocket::WebSocket$readyState()
websocket::WebSocket$send()
websocket::WebSocket$setAccessLogChannels()
websocket::WebSocket$setErrorLogChannels()
AlpacaforR::AlpacaSocket$auth()
AlpacaforR::AlpacaSocket$channel()
AlpacaforR::AlpacaSocket$initialize()
AlpacaforR::AlpacaSocket$lastmessage()
AlpacaforR::AlpacaSocket$logs()
clone()
The objects of this class are cloneable with this method.
PolygonSocket$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.