@@ -13,19 +13,25 @@ public extension KucoinAPI {
13
13
14
14
/// Creates and returns the signature for the `KC-API-SIGN` header field.
15
15
///
16
+ /// From Kucoin documentation *"Use API-Secret to encrypt the prehash string
17
+ /// {timestamp+method+endpoint+body} with sha256 HMAC. The request body
18
+ /// is a JSON string and need to be the same with the parameters passed by the API.
19
+ /// After that, use base64-encode to encrypt the result..."*
20
+ ///
16
21
/// https://docs.kucoin.com/futures/#authentication
17
22
/// - Parameters:
18
23
/// - method: `HTTPMethod`. E.g.: `GET`, `POST.`
19
24
/// - path: Endpoint path including query parameters, if any. E.g.: *"/api/v1/account-overview?currency=USDT"*
25
+ /// - body: The request body as a `JSON` `String`. For `GET`, `DELETE` requests, the body is "".
20
26
/// - secret: The API secret.
21
27
/// - Returns: `Base64` encoded signature.
22
- static func createSignature( for method: HTTPMethod , path: String , secret: String ) throws -> String {
28
+ static func createSignature( for method: HTTPMethod , path: String , body : String , secret: String ) throws -> String {
23
29
guard let secretData = secret. data ( using: . utf8) else {
24
30
throw KucoinAPIError . stringToDataFailed ( string: secret)
25
31
}
26
32
let key = SymmetricKey ( data: secretData)
27
33
let timestamp = Date ( ) . timestampMilliseconds
28
- let stringToSign = " \( timestamp) " + HTTPMethod . GET . rawValue + path
34
+ let stringToSign = " \( timestamp) " + method . rawValue + path + body
29
35
guard let stringToSignData = stringToSign. data ( using: . utf8) else {
30
36
throw KucoinAPIError . stringToDataFailed ( string: stringToSign)
31
37
}
0 commit comments