![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift) Bitfinex v2 REST Submit OrderSubmit an order. For more information, see https://docs.bitfinex.com/reference#rest-auth-submit-order
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()! let crypt = CkoCrypt2()! var apiPath: String? = "v2/auth/w/order/submit" 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() let json = CkoJsonObject()! json.updateString(jsonPath: "type", value: "LIMIT") json.updateString(jsonPath: "symbol", value: "tBTCUSD") json.updateString(jsonPath: "price", value: "15") json.updateString(jsonPath: "amount", value: "0.001") json.updateInt(jsonPath: "flags", value: 0) var body: String? = json.emit() 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.httpStr(verb: "POST", url: "https://api.bitfinex.com/v2/auth/w/order/submit", bodyStr: body, charset: "utf-8", contentType: "application/json", response: resp) if success == false { print("\(http.lastErrorText!)") return } print("Response body:") print("\(resp.bodyStr!)") } |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.