BTC Price Ticker
4 stars based on
72 reviews
I recently made chartjs-plugin-streaminga Chart. It is suitable for IoT-related use cases such as sensor data monitoring, and when I was looking for some real examples of streaming data, I noticed that it is also good for displaying real-time digital currency trading data that the digital currency exchanges provide. So, I just tried that out. It is becoming more common for the exchanges to deliver trading data efficiently using WebSocket. Some of them require authentication, but in this article, let's create trading charts for bitstamp api background color exchanges that provide public API without authentication.
Next, let's add a canvas to the page. Include an id so that you can identify the chart later. Then, prepare an object for buffering data, which is buf. The first array is for 'buy' bitstamp api background color and the second is for 'sell' prices. Now, let's access the real data. As we only need bitstamp api background color trade type, the timestamp X-axis and the price Y-axisthe filtered data is stored into the buffer on every message receipt using the following code.
Finally, we need to configure the chart. Regarding the details of the chart customization, please refer to the Chart. The key points here are that the 'realtime' scale that the chartjs-plugin-streaming plugin provides are set to the X axis, and that the entire data stored in the buffer is added to the chart in the onRefresh callback function bitstamp api background color is called at a regular interval every second by default.
Below is the completed chart. You can see that the chart is scrolling from the right to the left slowly. The next example is Bitstamp, an exchange in UK, which is the central trading hub in Europe. Therefore, the data subscription code is much simpler. Below is the code that receives data. It also takes only the trade type, the timestamp and the price.
The configuration of the chart is bitstamp api background color same as above except for the id. BTC-E is also a popular exchage located in Bulgaria. It uses Pusher for streaming as well. Below are the request and the message to be received. The last one is Japanese exchange, CoinCheck. There are many other digital currency exchanges that provide API to deliver real-time trading data. The API and data format are slightly different each other, but you can draw a chart with minimum modification.
I hope this article helps you try out for yourself.