Socket
Book a DemoInstallSign in
Socket

notbank

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notbank

The Notbank for Node.js

2.1.0
latest
Source
npmnpm
Version published
Weekly downloads
170
66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Notbank Node SDK

main page

sign up in Notbank.

Installation

To install Notbank use npm

npm install notbank

Documentation

This sdk makes use of the api of Notbank.

Quick start

Rest client

// client
const client = NotbankClient.Factory.createRestClient();

// authentication
await client.authenticateUser({
  ApiPublicKey: "my-public-key",
  ApiSecretKey: "my-secret-key",
  UserId: "xxxx"
});

handling errors

try {
  const response = await accountService.getAccountPositions({
    AccountId: 13,
    IncludePending: true,
  });
} catch (err) {
  const error = err as NotbankError;
  // handle error
}

Put order at the top of book example

const client = NotbankClient.Factory.createRestClient();
await client.authenticateUser({
  ApiPublicKey: "my-public-key",
  ApiSecretKey: "my-secret-key",
  UserId: "xxxx",
});
var accountId = 235;

// get USDT user balance (also known as position)
var positions = await client
  .getAccountService()
  .getAccountPositions({ AccountId: accountId });
var productSymbol = "USDT";
var usdtPosition = positions
  .filter(position => position.ProductSymbol === productSymbol)
  .pop();
if (!usdtPosition) {
  throw new Error("no usdt position");
}

// define quantityToSpend (between all usdt_balance and half usdt_balance)
var myUsdtBalance = usdtPosition.Amount;
var randomFraction = Math.random();
var halfMyBalance = myUsdtBalance / 2;
var atLeastHalfMyBalance = myUsdtBalance - randomFraction * halfMyBalance;
var quantityToSpend = atLeastHalfMyBalance;

var marketPair = "BTCUSDT";

// define orderPrice (around market top)
var btcUsdtOrderbook = await client
  .getTradingService()
  .getOrderBook({ Market_Pair: marketPair, Depth: 5, Level: 2 });
var randomSmallFraction = (Math.random() * 90 + 10) / 1000;
var topBid = btcUsdtOrderbook.bids[0];
var orderPrice = topBid.price + randomSmallFraction;
// TODO: handle tick size
var orderQuantity = quantityToSpend / orderPrice;

// send order
var instruments = await client.getInstrumentService().getInstruments();
var btcUsdtInstrument = instruments.filter(
  pair => pair.Symbol === marketPair
)[0];
var orderResult = await client.getTradingService().sendOrder({
  InstrumentId: btcUsdtInstrument.InstrumentId,
  AccountId: accountId,
  TimeInForce: TimeInForce.GTC,
  Side: OrderSide.Buy,
  OrderType: OrderTypeInt.Limit,
  Quantity: orderQuantity,
  LimitPrice: orderPrice
});

// handle order result
if (orderResult.Status === "Rejected") {
  // order was rejected
  console.log("order rejected");
  console.log(orderResult.Message);
  return;
}
// order was accepted
console.log("orderId,", orderResult.OrderId);

// cancel order
await client.getTradingService().cancelOrder({
  AccountId: accountId,
  OrderId: orderResult.OrderId
});
return orderResult.OrderId;

websocket client

The websocket client can be instanced with auto reconnection active. If done, then the restarting websocket will reconnect forever when the connection goes down unexpectedly, re-authenticating if it was authenticated, and re-subscribing to already stablished subscriptions. While reconnecting, calls to the websocket will throw. For subscriptions, reconnection will call again the snapshot hooks.

client = NotbankClient.Factory.createWebsocketClient({
  withReconnect: true
});
await client.connect();
await client.authenticateUser({
  ApiPublicKey: "my-public-key",
  ApiSecretKey: "my-secret-key",
  UserId: "xxxx"
});
// ...
client.close();

DevOps

How to build

Run the following npm script

npm run build

This command will compile the library's code from Typescript to Javascript including its type declarations to be used in NodeJS and a bundle version for Browser.

Keywords

api

FAQs

Package last updated on 04 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.