-2

I would like to know how to scrape data (position, name of the trader, symbol,..)from the Binance leaderboard with Python and Binance API.

Thanks for your answers!

This is my actual code which doesn't work:

from binance.client import Client, AsyncClient

api_key = 'xxx'
api_secret = 'xxx'

client = Client(api_key, api_secret)

leaderboard = client.futures_leaderboard()['positions']

I tried the code just above, but there are no results.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Yredle
  • 1
  • 1

2 Answers2

0

You can use this third party API. Remember to check its documentation.

Here is an example of code to achieve what I think you want:

Getting traders:

import requests

# API URL with its endpoint to use
url = "https://binance-futures-leaderboard1.p.rapidapi.com/v2/searchLeaderboard"

# Parameters to use
querystring = {
    "isShared": True,  # Set to true if you want to get traders sharing their positions
    "limit": 10        # Total traders to get
}

# Headers to use
headers = {
    "X-RapidAPI-Key": "YOUR-API-KEY",
    "X-RapidAPI-Host": "binance-futures-leaderboard1.p.rapidapi.com"
}

# Get response
response = requests.get(url, headers=headers, params=querystring)

# Print response to JSON
print(response.json())

Getting trader positions:

import requests

# Now we use the endpoint to get the positions shared by a trader
url = "https://binance-futures-leaderboard1.p.rapidapi.com/v2/getTraderPositions"

# Parameters to use
querystring = {
    "encryptedUid": "<REQUIRED>",  # Trader UUID
    "tradeType": "PERPETUAL"       # Set to PERPETUAL to get USDⓈ-M positions
}

# Parameters to use
headers = {
    "X-RapidAPI-Key": "YOUR-API-KEY",
    "X-RapidAPI-Host": "binance-futures-leaderboard1.p.rapidapi.com"
}

# Get response
response = requests.get(url, headers=headers, params=querystring)

# Print response to JSON
print(response.json())
-1

You have to fill in the api key and secret

How to Create API

Creating an API allows you to connect to Binance’s servers via several programming languages.

ViktorMS
  • 1,112
  • 10
  • 25