Skip to content

Instantly share code, notes, and snippets.

@tudorelu
Last active February 3, 2021 08:51
Show Gist options
  • Select an option

  • Save tudorelu/3e3cb48dc759f9cf29c6cace0771b27e to your computer and use it in GitHub Desktop.

Select an option

Save tudorelu/3e3cb48dc759f9cf29c6cace0771b27e to your computer and use it in GitHub Desktop.
BTC FUTURES DATA

Binance Futures Data

import ccxt
print('CCXT Version:', ccxt.__version__)
from pprint import pprint

exchange = ccxt.binance({
    'enableRateLimit': True,
    'options': {
        'defaultType': 'future',
    },
})

markets = exchange.load_markets()
# exchange.verbose = True  # uncomment for debugging

symbol = 'BTC/USDT'
market = exchange.market(symbol)

# Current Funding Rate
response = exchange.fapiPublic_get_fundingrate({
    'symbol': market['id'],
    # 'startTime': exchange.parse8601('2020-11-25T00:00:00Z'),  # ms to get funding rate from INCLUSIVE.
    # 'endTime': exchange.parse8601('2020-11-26T00:00:00Z'),  # ms to get funding rate until INCLUSIVE.
    # 'limit': 100,  # default 100, max 1000
})

pprint(response)

# Current Long / Short Account Ratio of TOP traders (last 500 hours)
# Only have acccess to the last 30 days :(
response = exchange.fapiDataGetTopLongShortAccountRatio({
    'symbol':market['id'], 
    'period':'1h',
    'limit':500
})

pprint(response)

# Current Long / Short Position Ratio of TOP traders (last 500 hours)
# Only have acccess to the last 30 days :(
response = exchange.fapiDataGetTopLongShortPositionRatio({
    'symbol':market['id'], 
    'period':'1h',
    'limit':500
})

pprint(response)

# Current Long / Short Account Ratio of ALL traders (last 500 hours)
# Only have acccess to the last 30 days :(
response = exchange.fapiDataGetGlobalLongShortAccountRatio({
    'symbol':market['id'], 
    'period':'1h',
    'limit':500
})

pprint(response)

# Historical Open Interest (last 500 hours)
response = exchange.fapiDataGetOpenInterestHist({
    'symbol':market['id'], 
    'period':'1h',
    'limit': 500
})

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