Sample code for 30+ languages & platforms
Perl

Bitfinex v2 REST Submit Order

See more Bitfinex v2 REST Examples

Submit an order.

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

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

my $http = Chilkat2::Http->new;

my $crypt = Chilkat2::Crypt2->new;

my $apiPath = 'v2/auth/w/order/submit';
my $apiKey = 'MY_API_KEY';
my $apiSecret = 'MY_API_SECRET';

my $dt = Chilkat2::DateTime->new;
$dt->SetFromCurrentSystemTime();

my $sbNonce = Chilkat2::StringBuilder->new;
$sbNonce->Append($dt->GetAsUnixTimeStr(0));
$sbNonce->Append('000');
my $nonce = $sbNonce->GetAsString();

my $json = Chilkat2::JsonObject->new;
$json->UpdateString('type', 'LIMIT');
$json->UpdateString('symbol', 'tBTCUSD');
$json->UpdateString('price', '15');
$json->UpdateString('amount', '0.001');
$json->UpdateInt('flags', 0);
my $body = $json->Emit();

my $sbSignature = Chilkat2::StringBuilder->new;
$sbSignature->Append('/api/');
$sbSignature->Append($apiPath);
$sbSignature->Append($nonce);
$sbSignature->Append($body);

$crypt->EncodingMode('hex_lower');
$crypt->HashAlgorithm('sha384');
$crypt->MacAlgorithm('hmac');
$crypt->SetMacKeyString($apiSecret);

my $sig = $crypt->MacStringENC($sbSignature->GetAsString());

$http->SetRequestHeader('bfx-apikey', $apiKey);
$http->SetRequestHeader('bfx-signature', $sig);
$http->SetRequestHeader('bfx-nonce', $nonce);

my $resp = Chilkat2::HttpResponse->new;
my $success = $http->HttpStr('POST', 'https://api.bitfinex.com/v2/auth/w/order/submit', $body, 'utf-8', 'application/json', $resp);
if (!$success) {
    print $http->LastErrorText, "\n";
    exit;
}

print "Response body:\n";
print $resp->BodyStr, "\n";