Sample code for 30+ languages & platforms
Rust

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat Rust Downloads

Rust

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

let http = chilkat::Http::new();

let crypt = chilkat::Crypt2::new();

let api_path = "v2/auth/w/order/submit".to_string();
let api_key = "MY_API_KEY".to_string();
let api_secret = "MY_API_SECRET".to_string();

let dt = chilkat::DateTime::new();
let _ = dt.set_from_current_system_time();

let sb_nonce = chilkat::StringBuilder::new();
let _ = sb_nonce.append(&dt.get_as_unix_time_str(false).unwrap_or_default());
let _ = sb_nonce.append("000");
let nonce = sb_nonce.get_as_string().unwrap_or_default();

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

let sb_signature = chilkat::StringBuilder::new();
let _ = sb_signature.append("/api/");
let _ = sb_signature.append(&api_path);
let _ = sb_signature.append(&nonce);
let _ = sb_signature.append(&body);

crypt.set_encoding_mode("hex_lower");
crypt.set_hash_algorithm("sha384");
crypt.set_mac_algorithm("hmac");
let _ = crypt.set_mac_key_string(&api_secret);

let sig = crypt.mac_string_enc(&sb_signature.get_as_string().unwrap_or_default()).unwrap_or_default();

http.set_request_header("bfx-apikey", &api_key);
http.set_request_header("bfx-signature", &sig);
http.set_request_header("bfx-nonce", &nonce);

let resp = chilkat::HttpResponse::new();
if http.http_str("POST", "https://api.bitfinex.com/v2/auth/w/order/submit", &body, "utf-8", "application/json", &resp).is_err() {
    println!("{}", http.last_error_text());
    return;
}

println!("Response body:");
println!("{}", resp.body_str());