NodeJS SDK
This wrapper facilitates the use of the tanX (previously Brine.fi) api.
Installation
npm i @tanx-libs/tanx-connectorUsage
Quick examples:
REST API Example
// rest_api.ts
import { AxiosError } from 'axios';
import * as dotenv from 'dotenv';
import {
Client,
isAuthenticationError,
CreateOrderNonceBody,
Response,
} from '@tanx-libs/tanx-connector';
dotenv.config();
const main = async () => {
// load your privateKey and walletAddress
const privateKey = process.env.PRIVATE_KEY;
const ethAddress = process.env.ETH_ADDRESS;
if (privateKey && ethAddress) {
// handle in try catch block
try {
// create a rest client instance (you can pass baseUrl if it has changed)
const client = new Client();
//you can use public endpoints right away
const test = await client.testConnection();
const candleStick = await client.getCandlestick({
market: 'ethusdc',
period: 120,
});
// login to use private endpoints
const loginRes = await client.completeLogin(ethAddress, privateKey);
// create an order nonce
const nonceBody: CreateOrderNonceBody = {
market: 'btcusdt',
ord_type: 'market',
price: 29580.51,
side: 'buy',
volume: 0.0001,
};
// create order (private)
const order = await client.createCompleteOrder(nonceBody, privateKey);
const orders = await client.listOrders();
console.log(orders.payload[0]);
// get profile info (private)
const profile = await client.getProfileInfo();
console.log(profile.payload.username);
} catch (e) {
// Error: AuthenticationError | AxiosError
if (isAuthenticationError(e)) {
console.log(e);
} else {
console.log(e as AxiosError<Response<string>>);
}
}
}
};
main();Websocket Example
Github repo
Last updated