Definitions
1. Environment Setup:
api_key: This variable retrieves the API key from the environment variables to securely access the Binance API without hardcoding sensitive information.
2. Global Constants:
Weights (WEIGHTS): These are coefficients used to calculate the Annual Percentage Rate (APR) score based on the funding rates over various periods. They reflect the importance of each period's funding rate in determining the overall APR score. The weights are defined as follows:
W3: Weight for the 3-day funding rate.
W7: Weight for the 7-day funding rate.
W30: Weight for the 30-day funding rate.
W_next: Weight for the next funding rate.
W_prev: Weight for the previous funding rate.
3. Function Definitions:
get_futures_symbols(): Calls the Binance API to retrieve a list of all available futures symbols.
get_funding_rate_history(symbol, display_days=30): Fetches the funding rate history for a specified futures symbol over a set number of days from the Binance API.
calculate_apr_score(group): Computes the APR score for a given dataset of funding rates using predefined weights. This score helps in assessing the profitability of each contract.
4. Data Retrieval and Processing:
Initially, all futures symbols are fetched and stored.
For each symbol, its funding rate history is retrieved for the last 60 days.
This data is then processed to compute the APR score using the function calculate_apr_score.
5. Data Aggregation and Output:
All the processed data is aggregated into a DataFrame.
The DataFrame is sorted by APR score, and the top 5 entries are assigned allocation percentages based on their rankings.
The final DataFrame is formatted for readability and saved as a CSV file named APR.csv.
6. Post-Processing:
Certain columns in the DataFrame are formatted as percentages for clarity.
The DataFrame includes columns like symbol, time, funding rates, APR score, and allocation percentage, making it informative and easy to understand.
Last updated