Server-Sent Events and fiat currencies, CFDs and futures ticker on an example

in programming •  2 years ago

Have you ever did something completely different that you initially wanted to do? For me this is frequently the case. But sometimes time is not wasted and I am happy to achieve something or learn something new.

Yesterday I logged in to my laptop for half an hour to check steemit posts and ended up with evening session that took place until 2 AM local time writing SSE client with real time feed for all available fiat currencies, CFDs and derivatives from This sounds weird for me even today as yesterday I did not know that SSE exist.

I had been working before on witness ICO price feed for Golos blockchain and noticed that solution provided by @someguy123 in Golosfeed-JS uses cheerio js ( to extract data from web page tables that contain different instruments' prices.

I was curious why @someguy123 had to extract those data from tables so I logged in to the website and MY EYES HURT. The design looks sooo 90's and indeed in the footer we see "1995 - 2016" the website has been there for around 20 years ;) I soon noticed it includes real time data at This looks fast. Almost like Poloniex ;) but there is no rest API.

I suspected that this must be some ancient AJAX code I started the debugger and whoops: inside the php page sits an iframe (another web page) generated server side using "JSP" (Java server pages). This thing contains some args after url. Digging deeeeper I found out that there are javascript modules that capture an access token from iframe url address and subscribe to SSE server to fetch data and update the tables.

Then I thought..."What the heck are Server-Sent Events (SSEs)", it is not AJAX, not websockets and found an article here with a quite good introduction to the subject.

And I came up with a crazy idea to catch this token and subscribe to a (sub)set of available instruments to get live ticker for fiat currencies, CFDs and futures directly from the server. Of course similar data are provided by brokers like IB, OANDA or other ones but 1) this was rather to solve a challenge 2) the website has a few Russian based instruments and currency pairs not easily available elsewhere.

And guess what - I succeeded. The outcome of this reverse-engineering exercise is an experimental tool that:

  1. Opens a keep-alive session and grabs SID token
  2. Subscribes to any instrument, subset, or all of them
  3. Streams ticker data in raw SSE format or dict/JSON

The available instruments are:

* INDEXES_CFD = ["DJIA", "SP500", "NASD_COMP", "NASD100", "FTSE100",
                   "DAX", "AEX" "CAC40", "SMI", "RTST", "USD_INDEX"]
              "SNG_ADR", "TAT_ADR", "VTB_ADR"]
              "COPPER", "NICKEL", "BRENT", "LIGHT"]
* MINI = ["NASDAQ", "SnP500"],
                    "EUR/AUD", "EUR/CAD", "EUR/CHF", "EUR/GBP",
                    "EUR/JPY", "EUR/USD", "GBP/CHF", "GBP/JPY",
                    "GBP/USD", "USD/CAD", "USD/CHF", "USD/JPY"]
                        "GBP_FUT", "JPY_FUT"]

Raw stream example for currencies:


Metals, stocks:



{'A': '+1212.44',
 'B': '+1212.14',
 'NCH': '-0.09',
 'NCHP': '-0.01',
 'S': 'GOLD',
 'T': '14:42:52'}
{'A': '+16.67',
 'B': '+16.64',
 'NCH': '0.00',
 'NCHP': '0.00',
 'S': 'SILVER',
 'T': '14:40:06'}
{'A': '+946.00',
 'B': '+936.00',
 'NCH': '0.00',
 'NCHP': '0.00',
 'T': '13:54:22'}

These are just static snapshots, normally data is streamed real time. Looks pretty cool.
Treat this implementation as an experiment, or a toy, but you can access real time data with it.

This post might be too technical, but well, I am writing about some original discoveries here and actually I am writing this not to forget afterwards. I think I found another application for steemit being a diary ;)

A few references:

  • Server-Sent events specification

  • What the heck are Server-Sent Events (SSEs)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Great work on deciphering this! I was never able to see any of this, so I just did some dirty HTML scanning. It works, it's not great, but it does definitely work well.

I should definitely work on porting your Python SSE to NodeJS (I don't actually like Node, but Piston has been iffy in the past few months, while steemjs-lib has been reliable) rather than using my HTML hacks.


The most important is that your solution is stable, therefore there is no need for changing it. But feel free to port it to NodeJS. It seems I need to check steemjs-lib as I did not pay much attention about it yet.