Created
December 19, 2017 04:38
-
-
Save Orpheon/4bcb815111fbf0941884b00da4dd57bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
DROP_TIME_IN_SECONDS = 5 * 60 | |
REFRESH_PERIOD = 20 | |
old_data = [] | |
while True: | |
req = requests.get("https://api.binance.com/api/v3/ticker/price") | |
if req.status_code == 429: | |
print("Spam limit reached, waiting 5 seconds..") | |
time.sleep(5) | |
continue | |
elif req.status_code != 200: | |
print("Error: Request has status code {0}; {1}".format(req.status_code, req.text)) | |
input() | |
continue | |
data = req.json() | |
current_price = {} | |
for obj in data: | |
if "BTC" in obj["symbol"]: | |
current_price[obj["symbol"].replace("BTC", "")] = float(obj["price"]) | |
# USDT is special because it's the BTC price relative to USDT, not USDT price relative to BTC | |
current_price["USDT"] = 1.0 / current_price["USDT"] | |
old_data.append(current_price) | |
print("-------------------------------------------------------") | |
if len(old_data) > DROP_TIME_IN_SECONDS / REFRESH_PERIOD: | |
old_price = old_data.pop(0) | |
for symbol in sorted(list(current_price.keys())): | |
if old_price[symbol] > current_price[symbol]: | |
percent_drop = 100 * (old_price[symbol]-current_price[symbol]) / old_price[symbol] | |
if percent_drop > 1: | |
print("{0} dropped by {1}% over the last {2} minutes".format(symbol, percent_drop, int(DROP_TIME_IN_SECONDS / 60))) | |
time.sleep(REFRESH_PERIOD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment