React Native
React Native
Bitfinex v2 REST Submit Order
See more Bitfinex v2 REST Examples
Submit an order.Chilkat React Native Downloads
import { CkDateTime, Crypt2, Http, HttpResponse, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
const crypt = new Crypt2();
const apiPath = 'v2/auth/w/order/submit';
const apiKey = 'MY_API_KEY';
const apiSecret = 'MY_API_SECRET';
const dt = new CkDateTime();
dt.setFromCurrentSystemTime();
const sbNonce = new StringBuilder();
sbNonce.append(dt.getAsUnixTimeStr(false));
sbNonce.append('000');
const nonce = sbNonce.getAsString();
const json = new JsonObject();
json.updateString('type', 'LIMIT');
json.updateString('symbol', 'tBTCUSD');
json.updateString('price', '15');
json.updateString('amount', '0.001');
json.updateInt('flags', 0);
const body = json.emit();
const sbSignature = new StringBuilder();
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);
const sig = crypt.macStringENC(sbSignature.getAsString());
http.setRequestHeader('bfx-apikey', apiKey);
http.setRequestHeader('bfx-signature', sig);
http.setRequestHeader('bfx-nonce', nonce);
const resp = new HttpResponse();
try {
await http.httpStrAsync('POST', 'https://api.bitfinex.com/v2/auth/w/order/submit', body, 'utf-8', 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
console.log('Response body:');
console.log(resp.bodyStr);
}