Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import requests
  2. import time
  3.  
  4. # defining the api-endpoint  
  5. API_ENDPOINT = "https://www.binance.com/gateway-api/v1/public/future/data/global-long-short-account-ratio"
  6.  
  7.  
  8. OI_URL = "https://www.binance.com/gateway-api/v1/public/future/data/open-interest-stats"
  9. # data to be sent to api
  10. data = {"name":"BTCUSDT","periodMinutes":5}
  11.  
  12.  
  13.  
  14. while True:
  15.     print('trying')
  16.  
  17.     # sending post request and saving response as response object
  18.     r = requests.post(url = API_ENDPOINT, json = data)
  19.     resp = r.text
  20.     print(f"resp: {resp}")
  21.  
  22.     r = requests.post(url = OI_URL, json = data)
  23.     oi_resp = r.text
  24.     print(f"resp: {oi_resp}")
  25.  
  26.  
  27.     try:
  28.         with open('ls_data.csv', 'a') as ls_data:
  29.             ls_data.write(resp+'\n')
  30.         with open('oi_data.csv', 'a') as oi_data:
  31.             oi_data.write(oi_resp+'\n')
  32.         print('here')
  33.  
  34.     except Exception as e:
  35.         print(e)
  36.     time.sleep(300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement