Event enabling wstrade API #65
Replies: 2 comments 4 replies
-
Neat walkthrough, Tamimi! I think you hit the nail with the statement that quotes. The workaround for getting data into quotes. /** websocket stuff **/
const socket = new WebSocket('...');
socket.addEventListener('message', function (event) {
// parse and store the stock quote values
});
quotes.use('NYSE', {
async get(ticker): {
// fetch the quote stored from the socket above
}
});
// now everytime you do a marketBuy or marketSell for a NYSE-listed stock, the custom provider we defined above
// will be invoked by wstrade-api if you wish to do limit buys and sells, that makes the implementation even simpler as you don't even have to use the /** websocket stuff **/
const socket = new WebSocket('...');
socket.addEventListener('message', function (event) {
// parse stock quote values
// You can directly invoke the limitBuy and and limitSell APIs with the price since you have it
if (aaplPrice <= 120) {
orders.limitBuy(....);
}
}); |
Beta Was this translation helpful? Give feedback.
-
Hey guys, I have actually been playing around with websockets lately and wanted to ask some questions. Do you just want access to realtime quotes via websockets or do you want access to WSimple's Websocket service ? If all you want is realtime quotes via websockets, I have actually been working on a package for that myself, maybe that could refactored merged into this api. The real time data actually comes from the globe and mail's api which I reverse-engineered. They provide real-time data for US and CA markets. I reverse-engineered their api because at the time when I started using WSimple, they were the only ones providing realtime quotes for TSX. Now there is Yahoo Finance as well I believe.. Anyway I leave my repo here if you want to have a look and believe it has potential to be augmented or refactored and merged into here. https://github.com/YassineElbouchaibi/tgam-finance |
Beta Was this translation helpful? Give feedback.
-
I'm starting this discussion to gauge interest in real-time development with the westrade-api (plus github discussions are pretty cool!).
Some people were interested in websockets implementation (#21) to enable processing a stream of data. So a cool use-case is to have a stream stock market data and depending on stock prices execute a WealthSimple trade/action using the westrade-api.
This sounds interesting, however, imposes a couple of challenges including:
Scale: a proof of concept could be easily implemented with one application that has a websocket connection to a stock market and using
westrade-API
the application can execute trade actions. This however imposes tight coupling between the operational data layer (source stock market data) and the analytical data layer (westrade-API
)Flow control: A stream of data reflecting stock price updates could impose a flow control issue. This refers to having a data source (Stock market) publishing data over a websocket connection at a faster rate than the processing application (which utilizes
westrade-API
) resulting in a bottleneck scenarioFrom an architectural perspective, one way to approach event-driven architectures (where an event is a stock price update that drives a side effect like authorizing a trade using
westrade-API
or feeding into a ML model) is through using a message broker as seen belowThis shows a separate client application dedicated to retrieve a stream of data from a stock exchange market over a websocket connection and publishes the data to the message broker over a predefined topic. Applications connected to the broker could subscribe to the topic of choice and consume the data. Having the message broker as the middleware layer acts as a shock absorber with queuing functionalities and effectively routes the events to the respective applications. Taking this architectural approach avoids tight coupling between the source of the data (publisher) and the consuming applications (subscribers).
Anyways, this is just a thought people that could spark an interesting conversation. What use-cases do you all have with
westrade-API
?Beta Was this translation helpful? Give feedback.
All reactions