Last active
April 18, 2018 01:41
-
-
Save insanj/08325d3d23a593e4369b832a343b91bb to your computer and use it in GitHub Desktop.
Binance API Ticker
This file contains 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 json | |
import datetime | |
import pytz | |
import time | |
print("Welcome π\n-------\nCreated by Julian Weiss 2018 Feb 8 (c)\n\n") | |
def check_binance_api(last_status): | |
remote_data = requests.get('https://api.binance.com/api/v1/exchangeInfo').content | |
json_data = json.loads(remote_data) | |
symbols = json_data['symbols'] | |
first_symbol = symbols[0] | |
first_symbol_status = first_symbol['status'] | |
eastern = pytz.timezone('US/Eastern') | |
broken_timestamp_naive = datetime.datetime(2018, 2, 7, 19, 30, 00, 00) | |
broken_timestamp = eastern.localize(broken_timestamp_naive) | |
current_timestamp = datetime.datetime.now(eastern) | |
delta_timestamp = current_timestamp - broken_timestamp | |
delta_seconds = delta_timestamp.total_seconds() | |
delta_minutes = delta_timestamp.total_seconds() / 60 | |
delta_hours = delta_timestamp.total_seconds() / 3600 | |
if last_status != first_symbol_status and first_symbol_status == 'BREAK': | |
print("π₯ FUCK main Binance exchange is DOWN") | |
elif first_symbol_status == 'BREAK': | |
print(f"π₯ {delta_hours:,.2f} hours {delta_minutes:,.0f} mins {delta_seconds:,.0f} secs") | |
else: | |
print("πππ wow holy shit main Binance exchange is UP AGAIN? status = " + first_symbol_status) | |
return first_symbol_status | |
print("Checking Binance API...") | |
last_status = '' | |
while 1: | |
time.sleep(1) | |
last_status = check_binance_api(last_status) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
π Live at https://repl.it/@julian_insanj__insanj_/Binance-API-Ticker