Sample code for 30+ languages & platforms
AutoIt

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

$oCrypt = ObjCreate("Chilkat.Crypt2")

Local $sApiPath = "v2/auth/w/order/submit"
Local $sApiKey = "MY_API_KEY"
Local $sApiSecret = "MY_API_SECRET"

$oDt = ObjCreate("Chilkat.CkDateTime")
$oDt.SetFromCurrentSystemTime()

$oSbNonce = ObjCreate("Chilkat.StringBuilder")
$oSbNonce.Append($oDt.GetAsUnixTimeStr(False))
$oSbNonce.Append("000")
Local $sNonce = $oSbNonce.GetAsString()

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("type","LIMIT")
$oJson.UpdateString("symbol","tBTCUSD")
$oJson.UpdateString("price","15")
$oJson.UpdateString("amount","0.001")
$oJson.UpdateInt("flags",0)
Local $sBody = $oJson.Emit()

$oSbSignature = ObjCreate("Chilkat.StringBuilder")
$oSbSignature.Append("/api/")
$oSbSignature.Append($sApiPath)
$oSbSignature.Append($sNonce)
$oSbSignature.Append($sBody)

$oCrypt.EncodingMode = "hex_lower"
$oCrypt.HashAlgorithm = "sha384"
$oCrypt.MacAlgorithm = "hmac"
$oCrypt.SetMacKeyString($sApiSecret)

Local $sig = $oCrypt.MacStringENC($oSbSignature.GetAsString())

$oHttp.SetRequestHeader "bfx-apikey",$sApiKey
$oHttp.SetRequestHeader "bfx-signature",$sig
$oHttp.SetRequestHeader "bfx-nonce",$sNonce

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpStr("POST","https://api.bitfinex.com/v2/auth/w/order/submit",$sBody,"utf-8","application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Response body:" & @CRLF)
ConsoleWrite($oResp.BodyStr & @CRLF)