Python-Steem Price Bot

chitty(69)
Published in
#steem
Words
123
Reading
1 min
Listen
Play
8y

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:

Captura de pantalla 2018-03-27 a la(s) 18.07.31.png

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:

https://github.com/PixelNoob/python-steem

Python-Steem Price Bot | Ecency