gitlabEdit

Node.js & JavaScript SDK for Evedex REST APIs & WebSockets

[TOC]

This SDK enables programmatic access to Evedex exchangearrow-up-right services, including market data streaming, account metrics, and order management.

  • Integration sdk with Evedex REST APIs and WebSockets.

  • TypeScript support (with type declarations for most API requests & responses).

  • Auth with wallet private keys or with API keys

  • Realtime balances, positions, orderbook, and order state updates with cache management.

  • Methods for working with orders by wallet account: create replace cancel orders.

  • Includes internally sign request payloads for orders, positions and withdraw methods

Installation

  1. Init npm project

  2. Install exchange-bot-sdk dependency

npm i @evedex/exchange-bot-sdk --save

Usage

Initialize container

You can use demo (for testing purposes) or production environments. For initializing container you need to pass websocket instance.

If you are using Node environment you need to install ws additionally:

And use it during initialize container method

DEMO TRADING ENVIRONMENT

PRODUCTION ENVIRONMENT

Initialize account

Api key account

ApiKeyAccount is designed to read user account state, including: balances, positions, orders.

You can create api key if you already logged in to evedex exchange.

Go to profile menu by clicking on avatar at the upper right corner => go to settings => API => create API key

chevron-rightInit examplehashtag

Wallet account

WalletAccout has all posibilities to read user account state and also includes:

  • Methods to work with orders (create, replace, cancel, mass cancel) with signing them internally

  • Methods to work with positions

  • Methods to work with balances

chevron-rightInit examplehashtag

Balance

Balance instance is designed for calculate available user balance and handle exchange events.

Methods with get prefix returns cached state, here is list of this methods:

  • getFundingQuantity(currency) —

  • getPositionList() —

  • getPosition(instrument) —

  • getOrderList() —

  • getTpSlList() —

  • getAvailableBalance() —

  • getPower(instrument) —

Methods with fetch prefix are used for retrieving data from REST API:

  • fetchTpSlList(query) — Fetches TP/SL list

  • fetchMe() — Fetches user info

  • fetchPositions() — Fetches positions

  • fetchOrders(orderListQuery) — Fetches orders

  • fetchAvailableBalance() — Fetches available balance

  • fetchOpenOrders() — Fetches open orders

Balance listen method subscribes for exchange events: updates positions, orders, funding, tpsl.

Signals are disgned for handling events:

  • onAccountUpdate

  • onFundingUpdate

  • onPositionUpdate

  • onOrderUpdate

  • onTpSlUpdate

chevron-rightSamplehashtag

Examples

chevron-rightFull example of sdk usage:hashtag

How to get test USDT in Development environment

For your convenience there's a test faucet that immediately deposits 1000 USDT to your smart-account in Development environment.

  1. The first run happens automatically when you register on https://demo-exchange.evedex.com

  2. After that you can once in a while request test funds using the button "Request Demo Funds" in the bottom-right of the Exchange screen.

Methods tree

Container

  • constructor(config: ContainerConfig) — Initialize container instance.

chevron-rightInit container usage examplehashtag
  • wallet(walletName: string) — Returns Wallet class instance.

chevron-rightWallet method usage examplehashtag

The Wallet class provides methods for interacting with an Ethereum wallet using the ethers library.

Method Explanations:

  • getChainId(): Returns the chain ID of the Ethereum network, either from the provided options.chain string or by querying the signer's provider.

  • getAddress(): Returns the Ethereum address associated with the wallet.

  • solidityPackedKeccak256(types, values): Computes the Solidity-packed Keccak-256 hash of the provided types and values.

  • getBytes(value): Returns the bytes representation of the provided value string.

  • serializeSignature(signature): Serializes the provided signature string into a format suitable for transmission.

  • signMessage(message): Signs the provided message string or Uint8Array using the wallet's private key.

  • signTypedData(domain, types, value): Signs the provided domain, types, and value using the wallet's private key, according to the EIP-712 typed data specification.

chevron-rightAccount method usage examplehashtag
  • apiKey(apiKeyName: string) — Returns user api key by config name.

chevron-rightapiKey method usage examplehashtag
chevron-rightapiKeyAccount method usage examplehashtag
  • gateway() — Returns Gateway instance (deprecated, not recommended to use). Returns a Gateway class instance.

  • closeWsConnection() — Close centrifuge websocket connection.

ApiKeyAccount

The ApiKeyAccount class represents an API key account, which provides methods for interacting with an exchange gateway.

To initialize ApiKeyAccount you need to pass your API key to container config.

Class Methods

Getters:

  • gateway: Returns the gateway instance (deprecated, not recommended to use).

  • authGateway: Returns the authentication gateway (deprecated, not recommended to use).

  • exchangeGateway: Returns the exchange gateway (deprecated, not recommended to use).

  • wsGateway: Returns the WebSocket gateway (deprecated, not recommended to use).

  • exchangeAccount: Returns the exchange account associated with the API key.

chevron-rightexchangeAccount method usage examplehashtag

exchangeAccount result example

  • session: Returns the session associated with the API key account. In case of api ey account returns api key.

Methods:

  • getBalance: Returns a new Balance class instance for the API key account.

  • fetchTpSlList: Fetches a list of Take Profit and Stop Loss (TpSl) orders based on the provided query parameters.

chevron-rightfetchTpSlList method usage examplehashtag

tpslList result example

  • fetchMe: Fetches the current user information.

chevron-rightfetchMe method usage examplehashtag

fetchMe result example

  • fetchPositions: Fetches a list of current user positions.

chevron-rightfetchPositions method usage examplehashtag

fetchPositions result example

  • fetchOrders: Fetches a list of user orders based on the provided query parameters.

chevron-rightfetchOrders method usage examplehashtag

fetchOrders result example

  • fetchAvailableBalance: Fetches the available balance for the current user.

chevron-rightfetchAvailableBalance method usage examplehashtag

fetchAvailableBalance result example

  • fetchPower: Fetches user power for sell and buy sides.

chevron-rightfetchPower method usage examplehashtag

fetchPower result example

  • fetchOpenOrders: Fetches a list of open orders for the current user.

chevron-rightfetchOpenOrders method usage examplehashtag

fetchOpenOrders result example

WalletAccount (extends SessionAccount)

This class extends the SessionAccount class, which extends the ApiKeyAccount.

WalletAccount contains ApiKeyAccount methods and provides methods for executing various trading actions.

To initialize WalletAccount you need to pass your wallet private key to container config.

Class Methods

  • createWithdraw(withdraw) — method used to create a signed withdrawal request and sends it to the exchange gateway.

chevron-rightcreateWithdraw method usage examplehashtag

createWithdraw result example

  • createClosePositionOrder(order) — method used to creates a signed close position order and sends it to the exchange gateway

chevron-rightcreateWithdraw method usage examplehashtag

createClosePositionOrder result example

  • updatePosition(query) — method used to update an open position leverage.

chevron-rightcreateWithdraw method usage examplehashtag

updatePosition result example

  • createLimitOrder(order) — method used to create a signed limit order and sends it to the exchange gateway.

chevron-rightcreateLimitOrder(order) method usage examplehashtag

createLimitOrder result example

  • replaceLimitOrder(order) — method used to update (replace) an open limit order.

chevron-rightreplaceLimitOrder(order) method usage examplehashtag

replaceLimitOrder result example

  • batchReplaceLimitOrder(orderList) — method used to batch replace open limit orders. Deprecated, not recommmended to use. Instead use batchReplaceInstrumentLimitOrder method

  • batchReplaceInstrumentLimitOrder(instrument, orderList) — method used to batch replace open limit orders.

chevron-rightbatchReplaceInstrumentLimitOrder(instrument, orderList) method usage examplehashtag

batchReplaceInstrumentLimitOrderResult result example

  • createMarketOrder(order) — method used to create a signed market order.

chevron-rightcreateMarketOrder(order) method usage examplehashtag

createMarketOrder result example

  • createStopLimitOrder(order) — method used to create a stop-limit order.

chevron-rightcreateStopLimitOrder(order) method usage examplehashtag

createStopLimitOrder result example

  • replaceStopLimitOrder(order) — method used to replace a stop-limit order.

chevron-rightreplaceStopLimitOrder(order) method usage examplehashtag

replaceStopLimitOrder result example

  • cancelOrder(query) — method used to cancel an order.

chevron-rightcancelOrder(query) method usage examplehashtag

cancelOrder result example

  • massCancelUserOrdersById(query) — method used to cancel user orders by ids.

chevron-rightmassCancelUserOrdersById(query) method usage examplehashtag

massCancelUserOrdersById result example

  • massCancelUserOrders(query) — method used to cancel user orders by instrument.

chevron-rightmassCancelUserOrders(query) method usage examplehashtag

massCancelUserOrders result example

  • createTpSl(tpsl) — method used to create Take Profit/Stop Loss orders.

chevron-rightcreateTpSl(tpsl) method usage examplehashtag

createTpSl result example

  • updateTpSl(query) — method used to update Take Profit/Stop Loss orders.

chevron-rightupdateTpSl(query) method usage examplehashtag

updateTpSl result example

  • cancelTpSl(query) — method used to cancel Take Profit/Stop Loss orders.

chevron-rightcancelTpSl(query) method usage examplehashtag

cancelTpSl result example

Balance

This class used to get realtime available balance and power data and handle exchange events.

  • constructor(options: BalanceOptions) — method used to create a Balance instance.

chevron-rightInit Balance usage examplehashtag
  • listen() - method used to subscribe to the exchange events and fill balance state. Returns Balance class instance

chevron-rightlisten() usage examplehashtag
  • unListen() - method used to unsubscribe to the exchange events and reset balance state. Returns Balance class instance

chevron-rightunListen() usage examplehashtag
  • getFundingQuantity(currency) — method used to get current funding of the Balance.

chevron-rightgetFundingQuantity() usage examplehashtag
  • getWithdrawTransferPendingQuantity() — method that returns sum of pending withdraw transfers.

chevron-rightgetWithdrawTransferPendingQuantity() usage examplehashtag
  • getPositionList() — method that returns all positions of the Balance.

chevron-rightgetPositionList() usage examplehashtag

getPositionList result example

  • getPosition(instrument) — method that returns user position by instrument.

chevron-rightgetPosition(instrument) usage examplehashtag

getPosition result example

  • getOrderList() — method that returns the list of existing orders.

chevron-rightgetOrderList() usage examplehashtag

getOrderList() result example

  • getTpSlList() — method that returns existing Take Profit/Stop Loss orders.

chevron-rightgetTpSlList() usage examplehashtag

getTpSlList() result example

  • getAvailableBalance() — method that returns available balance of the account, existing positions and open orders.

chevron-rightgetAvailableBalance() usage examplehashtag

getAvailableBalance() result example

  • getPower(instrument) — method that returns current buying and selling power (the maximum available order value).

chevron-rightgetPower(instrument) usage examplehashtag

getPower(instrument) result example

Signals:

Balance class instance can handle realtime events from exchange recieved by websocket using signals.

  • onAccountUpdate() — signal of updating user data

chevron-rightonAccountUpdate() usage examplehashtag

onAccountUpdate() event payload example

  • onFundingUpdate() — signal of updating user data

chevron-rightonFundingUpdate() usage examplehashtag

onFundingUpdate() event payload example

  • onTransferUpdate() — signal of updating user transfers data

chevron-rightonTransferUpdate() usage examplehashtag

onTransferUpdate() event payload example

  • onPositionUpdate() — signal of updating user positions data

chevron-rightonPositionUpdate() usage examplehashtag

onPositionUpdate() event payload example

  • onOrderUpdate() — signal of updating user orders data

chevron-rightonOrderUpdate() usage examplehashtag

onOrderUpdate() event payload example

  • onTpSlUpdate() — signal of updating user tpsl data

chevron-rightonTpSlUpdate() usage examplehashtag

onTpSlUpdate() event payload example

  • onMarkPriceUpdate() — signal of updating user mark price data

chevron-rightonMarkPriceUpdate() usage examplehashtag

onMarkPriceUpdate() event payload example

Last updated