Frage

At first I want to find some API, but I have searched on the internet and didn't find anything really helpful.

"Real time" I mean live stream the stock price on a webpage without a refresh.

If there is not such API, would my following method be a good way to implement this? 1. Python side, call yahoo finance api to get the most recent price. 2. Browser side, use ajax to constantly call server side to get the price and display the price. More specifically, I am thinking to use setInterval in jquery to achieve this.

How does this approach look?

Actually this is not specific to stock price data, any website that need to constantly retrieve data from server side need to consider this problem. For example google chat, facebook news feed, and so on. Can anybody tell me in general how to achieve live streaming data from server to browser?

War es hilfreich?

Lösung

Another way would be to use a push architecture. You could take a look at APE - Ajax Push Engine.

You could also take a look at Socket.IO, a realtime application framework for Node.JS.

Hope this helps!

Andere Tipps

You should definitely use a Push API. These days you should probably use http://www.websocket.org/

You don't want to use a rest API for real time, its inefficient to constantly "pull" the live price. Instead you want a service that will "push" changes to you whenever new trades are executed on the exchange. This is done with a websocket, which is a type of API but it is definitely different from a rest API. This article discusses the difference.

Intrinio provides a real-time websocket and you can access it via Python using this SDK on Github. You can access the same data via rest API using this package in Python. If you try them both you will see the architecture doesn't make sense with a rest API.

This video shows the trades coming in- trades don't execute on the market at regular intervals, it's completely sporadic. Instead of constantly "asking" the server for the data, it's better to "listen". This is called top of the book, meaning you get the newest trades as they come in from the top.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top