I needed a steem price ticker api for both BTC and USD for one of my internal projects. Instead of sending two concurrent requests to poloniex and bittrex, for the love of service-oriented architecture, I have decided to make a REST api for it. This way I can use it for other projects, too.
price.steem.rocks
With a simple HTTP GET request to price.steem.rocks, you can also see it.
Update interval
It's 10 seconds. Every 10 seconds, a background process makes API requests to poloniex and bittrex and get the latest values. API response has a field named "last_update" to indicate the last update.
Also, it's open source. You can fire up a instance on your own for your personal or public use.
Installation
$ virtualenv steemprice-env
$ source steemprice-env/bin/activate
$ git clone https://github.com/emre/steemprice.git
$ vim steemprice/settings.py # edit redis server settings
$ pip install -r requirements.txt
Running the background process
$ FLASK_APP=steemprice/app.py flask update_rates
This command will keep updating rates in every 10 seconds.
Running the API server
I use gunicorn the serve flask applications. Install it via pip.
$ pip install gunicorn
Then to run the server:
gunicorn steemprice.app:app --bind 0.0.0.0:PORT_NUMBER
To make sure, the gunicorn and rate_updater process doesn't stop due to unexpected conditions, you can use supervisord to make sure processes always run.
Example Supervisord Configurations
Gunicorn
[program:steemprice]
command = /var/www/steemprice-env/bin/gunicorn steemprice.app:app --bind 0.0.0.0:8002
directory = /var/www/steemprice
stdout_logfile = /var/www/steemprice/serverlogs
stderr_logfile = /var/www/steemprice/serverlogs
redirect_stderr = True
environment = FLASK_APP=app.py,LC_ALL=C.UTF-8,LANG=C.UTF-8
Rate Updater Process
[program:steempriceupdater]
command = /var/www/steemprice-env/bin/flask update_rates
directory = /var/www/steemprice/steemprice/
stdout_logfile = /var/www/steemprice/serverupdatelogs
stderr_logfile = /var/www/steemprice/serverupdatelogs
redirect_stderr = True
environment = FLASK_APP=app.py,LC_ALL=C.UTF-8,LANG=C.UTF-8
Warning
If you plan to use this data for actions of a trader bot or something like that, don't. There is no guarantee that the rates here will be valid forever. You can study the code and implementation and use it on your own with a private instance.
Posted on Utopian.io - Rewarding Open Source Contributors
Nice! Out of curiosity, are you using Python 2 or 3? The code indicates 2, which leads to another question: maybe try upgrading to 3? :)
Moreover, one huge improvement would be to decouple Redis as a dependency from both adapters. Not all servers have Redis onboard, and I think for this particular use case memory cache (e.g. a shared dict) could be as efficient. Ideally, when running the application it could be specified which cache backend you want to use.
WDYT?
I agree with you on both of your points. I have needed a quick solution so I did how I feel most comfortable.
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thanks!
Hey @emrebeyler I am @utopian-io. I have just super-voted you at 13% Power!
Suggestions https://utopian.io/rules
Achievements
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Haver another happy year, !BEER