Downloading historical trading pair data on BINANCE using Matlab.

19 views (last 30 days)
Hi. I need to download the historical funding data for each of the crypto pairs from the Binance website https://www.binance.com/en/futures/funding-history/1 The trading pairs can be selected on the website, and then a download button already exists that allows for downloading the .csv file. I know this will probably be easier in python but I am not familiar with python. I basically just want to write a Matlab script that automatically selects one pair after another and then downloads the default amount of data similar to when you will manually click on the download button.
Any ideas would be appreciated.

Answers (1)

Satyam
Satyam on 10 Feb 2025
Hi there,
To download historical funding data using MATLAB, you can start by identifying the URL, request body, and options for the API call. Once you have those details, you can use the webwrite function in MATLAB to specify the HTTP URL and the content as name-value pairs. For more information on how to use webwrite, you can check out the following MathWorks documentation https://www.mathworks.com/help/releases/R2021a/matlab/ref/webwrite.html
Additionally, you might need to include HTTP request options, which can be specified using the weboptions object and passing it as an argument to the webwritefunction call. API calls often require the request body in JSON format, so you can use jsonencodeobject to convert your data into JSON. More details on jsonencode can be found: https://www.mathworks.com/help/releases/R2021a/matlab/ref/jsonencode.html
Here's a sample code snippet to help you get started with downloading the historical funding data using a MATLAB script:
httpsUrl = '<YOUR-API-URL>';
options = weboptions("RequestMethod", "post", 'ContentType', 'json', 'MediaType', 'application/json');
pair = '<CRYPTO-PAIR>';
requestBody = struct("symbol", pair, "page", 1, "rows", 10000);
jsonRequest = jsonencode(requestBody);
data = webwrite(httpsUrl, jsonRequest, options);
fundingTable = struct2table(data.data);
writetable(fundingTable, "Funding_Rates_" + pair + ".csv");
Feel free to adjust the script according to your specific requirements.
I hope this helps!

Categories

Find more on Downloads in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!