Sample code for 30+ languages & platforms
Lua

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local http = chilkat.Http.new()

local crypt = chilkat.Crypt2.new()

local apiPath = "v2/auth/w/order/submit"
local apiKey = "MY_API_KEY"
local apiSecret = "MY_API_SECRET"

local dt = chilkat.DateTime.new()
dt:set_from_current_system_time()

local sbNonce = chilkat.StringBuilder.new()
sbNonce:append(dt:get_as_unix_time_str(false))
sbNonce:append("000")
local nonce = sbNonce:get_as_string()

local json = chilkat.JsonObject.new()
json:update_string("type", "LIMIT")
json:update_string("symbol", "tBTCUSD")
json:update_string("price", "15")
json:update_string("amount", "0.001")
json:update_int("flags", 0)
local body = json:emit()

local sbSignature = chilkat.StringBuilder.new()
sbSignature:append("/api/")
sbSignature:append(apiPath)
sbSignature:append(nonce)
sbSignature:append(body)

crypt.encoding_mode = "hex_lower"
crypt.hash_algorithm = "sha384"
crypt.mac_algorithm = "hmac"
crypt:set_mac_key_string(apiSecret)

local sig = crypt:mac_string_enc(sbSignature:get_as_string())

http:set_request_header("bfx-apikey", apiKey)
http:set_request_header("bfx-signature", sig)
http:set_request_header("bfx-nonce", nonce)

local resp = chilkat.HttpResponse.new()
local success = http:http_str("POST", "https://api.bitfinex.com/v2/auth/w/order/submit", body, "utf-8", "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

print("Response body:")
print(resp.body_str)