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
npmi@tanx-libs/tanx-connector
Usage
Check out the example files to see the complete workflow.
Quick examples:
REST API Example
// rest_api.tsimport { AxiosError } from'axios';import*as dotenv from'dotenv';import { Client, isAuthenticationError, CreateOrderNonceBody, Response,} from'@tanx-libs/tanx-connector';dotenv.config();constmain=async () => {// load your privateKey and walletAddressconstprivateKey=process.env.PRIVATE_KEY;constethAddress=process.env.ETH_ADDRESS;if (privateKey && ethAddress) {// handle in try catch blocktry {// create a rest client instance (you can pass baseUrl if it has changed)constclient=newClient();//you can use public endpoints right awayconsttest=awaitclient.testConnection();constcandleStick=awaitclient.getCandlestick({ market:'ethusdc', period:120, });// login to use private endpointsconstloginRes=awaitclient.completeLogin(ethAddress, privateKey);// create an order nonceconstnonceBody:CreateOrderNonceBody= { market:'btcusdt', ord_type:'market', price:29580.51, side:'buy', volume:0.0001, };// create order (private)constorder=awaitclient.createCompleteOrder(nonceBody, privateKey);constorders=awaitclient.listOrders();console.log(orders.payload[0]);// get profile info (private)constprofile=awaitclient.getProfileInfo();console.log(profile.payload.username); } catch (e) {// Error: AuthenticationError | AxiosErrorif (isAuthenticationError(e)) {console.log(e); } else {console.log(e asAxiosError<Response<string>>); } } }};main();
Websocket Example
// websocket.tsimport { Client, WsClient } from'../src';import*as dotenv from'dotenv';import { isAuthenticationError } from'@tanx-libs/tanx-connector';dotenv.config();constmain=async () => {try {constprivateKey=process.env.PRIVATE_KEY;constethAddress=process.env.ETH_ADDRESS;// create a rest client instance if you need to create a private websocketconstclient=newClient();if (privateKey && ethAddress) {// create a public websocket instanceconstwsClient=newWsClient('public');// check to see if connectedawaitwsClient.connect();// subscribe to streamsawaitwsClient.subscribe(['btcusdc.trades','btcusdc.ob-inc','btcusdc.kline-5m', ]);// unsubscribe to streamsawaitwsClient.unsubscribe(['btcusdc.trades']);// operate on ws memberwsClient.ws.on('message', (data) => {console.log(data.toString()); });awaitwsClient.disconnect();// login to get jwt access tokenconstloginRes=awaitclient.completeLogin(ethAddress, privateKey);// create a private websocket instanceconstwsClientPrivate=newWsClient('private',loginRes.token.access);// check if connectedawaitwsClientPrivate.connect();// subscribe to streamsawaitwsClientPrivate.subscribe(['trade','order']);// operate on ws memberwsClientPrivate.ws.on('message', (data) => {console.log(data.toString()); }); } } catch (e) {if (isAuthenticationError(e)) {console.log(e); } else {console.log(e); } }};main();
Github repo
Please check out the full implementation here to find all the rest api methods, websocket methods and examples.