roPopa 0 Posted April 2 (edited) Hi all Did anyone have any piece of code working with binance API? I found myself in need of an "hello word" example and I did not find it on the intenet. Anyone can help me to understand that I am thinking correct or not please. I have the following code Code: procedure TfrmMain.btnInfoClick(Sender: TObject); var workStream : TStringStream; workResponse : TStringStream; responseObject : ISuperObject; serverTIME : Int64; begin mDEBUG.Lines.Clear; try workStream := TStringStream.Create; workResponse := TStringStream.Create; restCLIENT_MAIN.ResetToDefaults; restREQUEST_MAIN.ResetToDefaults; restRESPONSE_MAIN.ResetToDefaults; restCLIENT_MAIN.BaseURL := API_URL; serverTIME := GetAPI_TIME; restREQUEST_MAIN.Resource := '/sapi/v1/broker/info'; restREQUEST_MAIN.ResourceSuffix := '?timestamp=' + serverTIME.ToString + '&signature=' + SECRET_KEY; restREQUEST_MAIN.Method := TRESTRequestMethod.rmGET; restREQUEST_MAIN.AddParameter('Content-Type', 'application/json'); restREQUEST_MAIN.AddParameter('X-MBX-APIKEY', CLIENT_KEY); restREQUEST_MAIN.Execute; workResponse := TStringStream.Create(restRESPONSE_MAIN.JSONText); responseObject := TSuperObject.ParseStream(workResponse, True); if responseObject <> nil then begin mDEBUG.Lines.Add(responseObject.AsString); end else begin mDEBUG.Lines.Add(restRESPONSE_MAIN.Content); end; finally mDEBUG.Lines.Add(''); mDEBUG.Lines.Add('restCLIENT_MAIN.BaseURL:' + restCLIENT_MAIN.BaseURL); mDEBUG.Lines.Add('restREQUEST_MAIN.Resource:' + restREQUEST_MAIN.Resource); mDEBUG.Lines.Add('restREQUEST_MAIN.ResourceSuffix:' + restREQUEST_MAIN.ResourceSuffix); FreeAndNil(workStream); FreeAndNil(workResponse); end; end; the result is Code: {"msg":"API-key format invalid.","code":-2014} but the postman give me a different error. (timestamp difference) What I am missing? Anyone can help me with some hints? Edited April 2 by roPopa Share this post Link to post
mvanrijnen 22 Posted April 6 The creator of Delphi WebSockets Binance API (esegece.com) is also on this forum, find him or buy his product. (i think i gonna buy it for trading on binance) Share this post Link to post
mvanrijnen 22 Posted April 6 (edited) [code] SIGNED (TRADE and USER_DATA) Endpoint security SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body. Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation. The signature is not case sensitive. totalParams is defined as the query string concatenated with the request body. [/code] see the: Use your secretKey as the key and totalParams as the value for the HMAC operation. Be very carefull with your secret key ! Also make sure, you have your computer/server synchronized with a timeserver. (and if i got it correct, you have to need the timestamp in UTC time, not local time). this had to be one post, sorry Edited April 6 by mvanrijnen Share this post Link to post