binance-webrequest

Author: Copyright 2021, Edson Cavalca Jr
Miscellaneous
Uses files from the file systemIt writes information to file
0 Views
0 Downloads
0 Favorites
binance-webrequest
ÿþ//+------------------------------------------------------------------+

//|                                           binance-webrequest.mq5 |

//|                                 Copyright 2021, Edson Cavalca Jr |

//|                                        https://tinosangue.com.br |

//+------------------------------------------------------------------+

#property copyright "Copyright 2021, Edson Cavalca Jr"

#property link      "https://tinosangue.com.br"

#property version   "1.00"

//+------------------------------------------------------------------+

//| Script program start function                                    |

//+------------------------------------------------------------------+

void OnStart()

  {

//---



   string cookie=NULL, headers;

   char data[], result[]; // array de char



// https://binance-docs.github.io/apidocs/spot/en/#compressed-aggregate-trades-list

   string url = "https://api.binance.com/api/v3/klines";

// parameters:

// symbol

// interval   

// example interval:   1m 3m  5m  15m  30m  1h   2h   4h   6h   8h   12h   1d   3d   1w   1M

   string query = "?symbol=BTCUSDT&interval=1d";

//[

//  [

//    1499040000000,      // Open time

//    "0.01634790",       // Open

//    "0.80000000",       // High

//    "0.01575800",       // Low

//    "0.01577100",       // Close

//    "148976.11427815",  // Volume

//    1499644799999,      // Close time

//    "2434.19055334",    // Quote asset volume

//    308,                // Number of trades

//    "1756.87402397",    // Taker buy base asset volume

//    "28.46694368",      // Taker buy quote asset volume

//    "17928899.62484339" // Ignore.

//  ]

//]



   ResetLastError();



   int res = WebRequest("GET",url+query,cookie,NULL,5000,data,0,result,headers);

   if(res==-1) // error !!!

     {

      Print("Error = ", GetLastError());

     }

   else // no error

     {

      Print("Ok!");    

      string texto = CharArrayToString(result);

      Print(texto);

      uchar arr[];

      //--- Open the file

      ResetLastError();    

      int file_handle=FileOpen("test-binance-api2.json",FILE_WRITE|FILE_BIN);

      Print(file_handle);

      if(file_handle!=INVALID_HANDLE)

        {

         Print("Saving ...");

         FileWriteArray(file_handle,result,0,ArraySize(result)); // Write the array

         FileClose(file_handle);

        }

      else

         Print("Error in the FileOpen. Code Error=",GetLastError());

     }

  }





//+------------------------------------------------------------------+

Comments