Reputation: 1
I am trying to access The Ponolinex.com with Spot API menthotl in Delphi 10.3, but I do not know how to the API Signature Generation.
Here is the construction from Poloniex: Please help me.......
Signature Example Code
We provide signature codes in three languages, Java/Python/NodeJS, and examples of request codes, Here.API Signature Generation
Steps:Compose a “Request String” to be used for the generation of the digital signature which would include:
Method type (GET/POST/DELETE/etc) followed "\n" e.g. GET\n Access path, followed "\n" e.g. /orders\n Add the timestamp parameter and List of parameters sorted by ASCII order delimited by & e.g.:
limit=5&signTimestamp=1659259836247&symbol=ETH_USDT NOTE: all parameters must be URL/UTF-8 encoded. i.e. space is encoded as "%20" The final string for the signature generation, based on the example values above will be:
GET\n
/orders\n
limit=5&symbol=ETH_USDT
DELETE or POST Method with http body, for example: To cancel orders by IDs:
/orders/cancelByIds\n
Add requestBody and timestamp:
requestBody={"orderIds":["1234567890"],"clientOrderIds": ["myId-1"]} signTimestamp=1631018760000
Timestamp needs to be added. Timestamps are valid for 1 minute. Connect the parameters in the above order with the character "&": requestBody={"orderIds":["1234567890"],"clientOrderIds":["myId-1"]}&signTimestamp=1631018760000} The final string to be used for signature calculation is composed as follows:
DELETE\n
/orders/cancelByIds/\n
DELETE or POST Method with no http body, for example : To Cancel Order by Id: /orders/1
Timestamp needs to be added. Timestamps are valid for 1 minute. `signTimestamp=1631018760000`
The final string to be used for signature calculation is composed as follows:
DELETE\n
/orders/1\n
signTimestamp=1631018760000
Generate a digital signature using the "Request String" generated in the previous step and your key (Secret Key):
Call the HmacSHA256 hash function to get the hash value with the request string and API private key obtained in the previous step as two parameters.
Encode this hash with base-64 and the resulting value is used as the digital signature for this interface call.
Example: 5g4Rx5A2bLyMWFgR3Aqp+B4w+iJkL7n5OD3SuYtCJK8=
Request example using the above generated signature:
Note: POST\DELETE requests should contain application/json type content and be in valid JSON format.Sample GET command:
curl -X GET \
--header 'key: A3xxxxxx-99xxxxxx-84xxxxxx-72xxxxxx' \
--header 'signatureMethod: HmacSHA256' \
--header 'signatureVersion: 2' \
--header 'signTimestamp: 1631018760000' \
--header 'signature: 5g4Rx5A2bLyMWFgR3Aqp+B4w+iJkL7n5OD3SuYtCJK8=' \
'https://api.poloniex.com/orders?symbol=ETH_USDT&limit=5'
I am doing like this, but it does not work. :(
procedure Tfmain.BitBtn7Click(Sender: TObject);
var
Parameters: TStringList;
Json_data,Sign_HMAC,Coin_name: String;
NetHTTPClient:TNetHTTPClient;
Response: IHTTPResponse;
Vdata:TMemoryStream;
VHeader:TMemoryStream;
JsonValue: TJSONValue;
JsonObject,JsonObject1: TJSONObject;
jSubPar : TJSONPair;
i:Integer;
v_available,v_onorder:real;
begin
try
NetHTTPClient:=TNethttpClient.Create(nil);
Sign_HMAC := THashSHA2.GetHashString(Secretkey, SHA256);
NetHTTPClient.CustomHeaders['key'] := APIKey;
NetHTTPClient.CustomHeaders['signatureMethod'] := 'HmacSHA256';
NetHTTPClient.CustomHeaders['signatureVersion'] := '2';
NetHTTPClient.CustomHeaders['signTimestamp'] := Get_time(9.5);
NetHTTPClient.CustomHeaders['signature'] := Sign_HMAC;
Response:=NetHTTPClient.Get(E_post.Text);
finally
NetHTTPClient.Free;
end;
end;
Upvotes: 0
Views: 53