Hello! I’m building my own bot on python, in order to connect to exchange’s api and make it process some information for me. I’m still a beginner on python, i know some stuff but i still have a lot to learn.
I encountered some problems: my bot is able to fetch data from an exchange’s api (Bittrex) and prints the last orders for a currency choosen by me, so far everything is alright, but the problem is that i can’t make it print the orders in real time, i tried to create a while loop with an if statement that tells the bot to print ONLY orders with a bigger timestamp, it works and prints the new orders but the problem is that it keeps printing the same order over and over. I know that’s because of the while loop but i can’t solve it, could anyone give me an hint on how to handle this?
Also, i’d like to make it print the difference between buys and sells, any idea on how i can sort it out? is the piece of code created by me, feel free to correct it or use it if it could be useful!
import time, requests, json try: BU = requests.session() URL = 'https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-DOGE' r = BU.get(URL, timeout=(15, 10)) time.sleep(1) MarketPairs = json.loads(r.content) for element in MarketPairs['result']: id = element['Id'] price = element['Price'] tot = element['Total'] time = element['TimeStamp'] type = element['OrderType'] if time > '2017-12-11T12:30:48.887': print type, " ", id, " ", tot, " ", price, " ", time time.sleep(1) except Exception as e: print e print 'Error... possible timeout'