简体   繁体   中英

Get Funding Rate Data From CoinGlass in Python 3

I am trying to get API data from CoinGlass and I have this working code:

# https://coinglass.github.io/API-Reference/#general-info
# 16 Nov 2022

# Symbol:
# BTC,ETH,EOS,BCH,LTC,XRP,BSV,ETC,TRX,LINK are now supported

# Exchange Name:
# Bitmex,Binance,Bybit,Okex,Huobi,FTX,Deribit,Kraken,Bitfinex,Phemex are now supported


# Parameter Default  Description
# type      string  default C (Token Margined=C, USDT or USD Margined=U)
# symbol    string  Symbol

url = "https://open-api.coinglass.com/api/pro/v1/futures/funding_rates_chart?symbol=BTC&type=C"
params = {}
headers = {'coinglassSecret': '1be40c5d2d71425084cd08b9e9817557'}
response = requests.request("GET", url, headers = headers, data = params)
print(response.text.encode('utf8'))

I am going to add more symbols to the url. I made a list of possible symbols but it did not return anything.

symbol_list = ['BTC', 'ETH']

# Parameter Default  Description
# type      string  default C (Token Margined=C, USDT or USD Margined=U)
# symbol    string  Symbol

url = "https://open-api.coinglass.com/api/pro/v1/futures/funding_rates_chart?symbol=symbol_list&type=C"
params = {}
headers = {'coinglassSecret': '1be40c5d2d71425084cd08b9e9817557'}
response = requests.request("GET", url, headers = headers, data = params)
print(response.text.encode('utf8'))

Please let me know what I should do.

You can simply loop over your symbol_list with a for loop:

import requests

symbol_list = ['BTC', 'ETH']
headers = {'coinglassSecret': '1be40c5d2d71425084cd08b9e9817557'}
params = {}
responses = []
for symbol in symbol_list:
    url = f"https://open-api.coinglass.com/api/pro/v1/futures/funding_rates_chart?symbol={symbol}&type=C"
    print(symbol)
    response = responses.append(requests.request("GET", url, headers = headers, data = params))

Now you have a responses array which contains your wanted info for both symbols.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM