Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
const api_path = "v2/auth/r/info/user";
const api_key = "MY_API_KEY";
const api_secret = "MY_API_SECRET";
const dt = try chilkat.DateTime.init();
defer dt.deinit();
dt.setFromCurrentSystemTime() catch {};
const sb_nonce = try chilkat.StringBuilder.init();
defer sb_nonce.deinit();
sb_nonce.append(try dt.getAsUnixTimeStr(alloc, false)) catch {};
sb_nonce.append("000") catch {};
const nonce = try sb_nonce.getAsString(alloc);
// This particular request has an empty body.
const body = "";
const sb_signature = try chilkat.StringBuilder.init();
defer sb_signature.deinit();
sb_signature.append("/api/") catch {};
sb_signature.append(api_path) catch {};
sb_signature.append(nonce) catch {};
sb_signature.append(body) catch {};
crypt.setEncodingMode("hex_lower");
crypt.setHashAlgorithm("sha384");
crypt.setMacAlgorithm("hmac");
crypt.setMacKeyString(api_secret) catch {};
const sig = try crypt.macStringENC(alloc, try sb_signature.getAsString(alloc));
http.setRequestHeader("bfx-apikey", api_key);
http.setRequestHeader("bfx-signature", sig);
http.setRequestHeader("bfx-nonce", nonce);
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("POST", "https://api.bitfinex.com/v2/auth/r/info/user", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response body:\n", .{});
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
// Sample response body:
// [1234567,"joe@example.com","joe_trader",1527691729000,0,null,null,"Central Time (US & Canada)"]
}