Skip to content

Instantly share code, notes, and snippets.

@insanj
Last active April 18, 2018 01:41
Show Gist options
  • Save insanj/08325d3d23a593e4369b832a343b91bb to your computer and use it in GitHub Desktop.
Save insanj/08325d3d23a593e4369b832a343b91bb to your computer and use it in GitHub Desktop.
Binance API Ticker
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)
@insanj
Copy link
Author

insanj commented Feb 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment