As a series of Steem-Python scripts I have been sharing, today I wanted to show you the code of a bot that gets the latest price of Bitcoin, Steem and Steem Dollar from the Poloniex API and creates a post on Steemit.
To start, create the python file:
sudo nano price_bot.py
Then paste this code inside (make sure to put your posting key and user in the required fields):
from steem import Steem
import urllib.request
import json
url = urllib.request.urlopen('https://poloniex.com/public?command=returnTicker')
result = url.read()
resultj = json.loads(result)
BTC = resultj['USDT_BTC']['last']
BTC = float(BTC)
BTC = round(BTC, 2)
STEEM = resultj['BTC_STEEM']['last']
STEEM = float(STEEM) * float(BTC)
STEEM = round(STEEM, 2)
SBD = resultj['BTC_SBD']['last']
SBD = float(SBD) * float(BTC)
SBD = round(SBD, 2)
print ("posting prices...")
s = Steem(keys=["YOUR POSTING KEY"])
s.commit.post(
"Todays Daily Market: STEEM @ {} ...".format(STEEM),
"**Bitcoin:** {} USD".format(BTC) + "
**Steem:** {}".format(STEEM) + "
**Steem Dollars:** {}
".format(SBD) + "
*This is an automated msg posted by the [price_bot.py](https://github.com/PixelNoob/python-steem)*" ,
"YOUR ACCOUNT",
tags=["bitcoin","steem", "trade"]
)
print ("prices posted succesfully")
To run the the script just type:
python3 bot_price.py
The end result should look like this:
You could also create a crontab job to run this script daily and get a daily price update on your feed.
Let me know what you think and make sure the check out my other scripts here: