Swift
Swift
Bitfinex v2 REST User Info
See more Bitfinex v2 REST Examples
Retrieve the user ID, email, username and timezone setting for the account associated with the API key used.Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Implements the following CURL command:
// curl -X POST -H "bfx-nonce: nonce" \
// -H "bfx-apikey: apiKey" \
// -H "bfx-signature: sig" \
// https://api.bitfinex.com/v2/auth/r/info/user
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
let crypt = CkoCrypt2()!
var apiPath: String? = "v2/auth/r/info/user"
var apiKey: String? = "MY_API_KEY"
var apiSecret: String? = "MY_API_SECRET"
let dt = CkoDateTime()!
dt.setFromCurrentSystemTime()
let sbNonce = CkoStringBuilder()!
sbNonce.append(value: dt.get(asUnixTimeStr: false))
sbNonce.append(value: "000")
var nonce: String? = sbNonce.getAsString()
// This particular request has an empty body.
var body: String? = ""
let sbSignature = CkoStringBuilder()!
sbSignature.append(value: "/api/")
sbSignature.append(value: apiPath)
sbSignature.append(value: nonce)
sbSignature.append(value: body)
crypt.encodingMode = "hex_lower"
crypt.hashAlgorithm = "sha384"
crypt.macAlgorithm = "hmac"
crypt.setMacKeyString(key: apiSecret)
var sig: String? = crypt.macStringENC(inText: sbSignature.getAsString())
http.setRequestHeader(name: "bfx-apikey", value: apiKey)
http.setRequestHeader(name: "bfx-signature", value: sig)
http.setRequestHeader(name: "bfx-nonce", value: nonce)
let resp = CkoHttpResponse()!
success = http.httpNoBody(verb: "POST", url: "https://api.bitfinex.com/v2/auth/r/info/user", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response body:")
print("\(resp.bodyStr!)")
// Sample response body:
// [1234567,"joe@example.com","joe_trader",1527691729000,0,null,null,"Central Time (US & Canada)"]
}