NodeJS SDK
This wrapper facilitates the use of the tanX (previously Brine.fi) api.
tanX Connector includes utility/connector functions which can be used to interact with the tanX API. It uses axios internally to handle all requests. It includes interceptors for handling setting JWT and re-login on token expiry.
Please check out the full implementation here to find all the rest api methods, web-socket methods and examples.
Installation
First go to the tanX website and create an account with your wallet.
Install from npm
npm i @tanx-libs/tanx-connectorUsage
Check out the example files to see the complete workflow.
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
Please check out the full implementation here to find all the rest api methods, websocket methods and examples.
Last updated
Was this helpful?