Communication with Binance through REST-calls (HTTP GET) lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- MortenB · 2021-03-13 22:48 I have tried to use the Indy Library in order to download a list of trades done. However, I always get an error 400 when I execute my function for getting the result(s) back. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function HTTPGetClientDownload(URL, TheAPIKey: AnsiString): AnsiString;  begin// Note: URL is combined with path and query string.    // Result will be:    // - empty ('') when it has failed    Result := '';    With TFPHttpClient.Create(Nil) do    try      AddHeader('X-MBX- APIKEY',TheAPIKey);      try        Result := Get(URL);      except      on E: Exception do          ShowMessage('Error: ' + E.Message);    end;    finally      Free;    end;  end; The full URL with QueryString is as follows: https://api.binance.com/api/v3/allOrders?symbol=NPXS×tamp=1615674 994125&signature=2bb3245106aa33048c1e5c6a098441b080ae000671d9f6aad1a06 540032740df - the QueryString (symbol=NPXS×tamp=1615674994125) is digested with my secret key, and the resulting byte array is converted to Hex. As far as I understand, the API-key have to be sent as an HTTP Header, which I do (I believe). - When I run the Get(URL) in above code example, I get an error: Project xxx raised exception class 'EHTTPClient' with message: Unexpected response status code: 400 Does anybody have an idea of what I do/make wrong? I believe my Hashing routine work very well, as I reproduce exactly as in examples from Binance on dummy variables. ---------------------------------------------------------------------- engkin · 2021-03-14 00:22 The server does not like your request. Probably a missing header like user agent, accept or something. Compare your request with a working client to find where you went wrong. If you add 400 to accepted results, the server might give a better message. ---------------------------------------------------------------------- MortenB · 2021-03-14 05:49 Haha. Yes. I did gather that the server didn't like my request. On the bright side, I did get it to work and will share the details: Binance does not say much at all about what exactly is wrong. The error 400 is triggered from the Binance server as an answer to the request. All this means, is that the error is on the user side, but where to start tracking this error down when there is so little information returned. All I wanted was all my trades with the NTXS-currency (I am not rich, so I only play with the very cheap crypto-coins) With my software, I asked for a list of what I have done towards NPXS (last 500 records) (which is by default). And this failed with error 400. I then added another two headers, User-Agent and Content-type, but to no help at all. Still failing with error 400. I then changed my header: "X-MBX-APIKEY" to "APIKEY" and this was in a weird way "Success". I still got an error, but this time 401. I gather that 401 means something like "No Access", so now I knew that I had access before, but not now, ergo: Changing the APIKEY-header was wrong. – Back with the header: "X-MBX-APIKEY", and I took it for granted that my timestamp was correct... hey. What can go wrong when I generate a Unix-timestamp on the millisecond for a server in Malta when I sit locally on my computer in Thailand. Nothing, Right  Then it was only the "symbol" left, which stands for "currency" in this setting. If NPXS is wrong, when it is correct. Arrrghhh. By chance I added "symbol" as a "currency pair"... I use USDT when I buy NPXS, so I changed the "symbol" into "NPXSUSDT" and all of a sudden the error did not occur. I was then just waiting... waiting... waiting waiting waiting ... and then I got a list long as a bad year. Problem solved! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function HTTPGetClientDownload(URL, QueryString, TheAPIKey: AnsiString): AnsiString;  begin    // Result will be:    // - empty ('') when it has failed    Result := '';    With TFPHttpClient.Create(Nil) do    try      AddHeader('User-Agent','Mozilla/4.0 (compatible; Lazarus/FreePascal Binance API)');      AddHeader('Content- type','application/x-www-form-urlencoded');      AddHeader('X-MBX- APIKEY',TheAPIKey);      try        Result := Get(URL);//        Result := Get(URL,mmoResult.Lines);      except        on E: Exception do//          ShowMessage('Error: ' + E.Message);          Result:=Result+'*** Error *** '+E.Message;      end;    finally      Free;    end;This routine is now what I use, and it works... as long as the payload for Binance is correct to the letter.