Node.js & JavaScript SDK for Evedex REST APIs & WebSockets
[TOC]
This SDK enables programmatic access to Evedex exchange 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
Init npm project
Install exchange-bot-sdk dependency
npm i @evedex/exchange-bot-sdk --saveUsage
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
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
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
Examples
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.
The first run happens automatically when you register on https://demo-exchange.evedex.com
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.
wallet(walletName: string)— Returns Wallet class instance.
Wallet method usage example
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.
account(walletName: string) — Returns WalletAccount instance.
apiKey(apiKeyName: string) — Returns user api key by config name.
apiKeyAccount(apiKeyName: string) — Returns ApiKeyAccount instance.
gateway() — Returns Gateway instance (deprecated, not recommended to use). Returns a
Gatewayclass 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.
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.
fetchMe: Fetches the current user information.
fetchPositions: Fetches a list of current user positions.
fetchOrders: Fetches a list of user orders based on the provided query parameters.
fetchAvailableBalance: Fetches the available balance for the current user.
fetchPower: Fetches user power for sell and buy sides.
fetchOpenOrders: Fetches a list of open orders for the current user.
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.
createClosePositionOrder(order)— method used to creates a signed close position order and sends it to the exchange gateway
updatePosition(query)— method used to update an open position leverage.
createLimitOrder(order)— method used to create a signed limit order and sends it to the exchange gateway.
replaceLimitOrder(order)— method used to update (replace) an open limit order.
batchReplaceLimitOrder(orderList)— method used to batch replace open limit orders. Deprecated, not recommmended to use. Instead use batchReplaceInstrumentLimitOrder methodbatchReplaceInstrumentLimitOrder(instrument, orderList)— method used to batch replace open limit orders.
batchReplaceInstrumentLimitOrder(instrument, orderList) method usage example
batchReplaceInstrumentLimitOrderResult result example
createMarketOrder(order)— method used to create a signed market order.
createStopLimitOrder(order)— method used to create a stop-limit order.
replaceStopLimitOrder(order)— method used to replace a stop-limit order.
cancelOrder(query)— method used to cancel an order.
massCancelUserOrdersById(query)— method used to cancel user orders by ids.
massCancelUserOrders(query)— method used to cancel user orders by instrument.
createTpSl(tpsl)— method used to create Take Profit/Stop Loss orders.
updateTpSl(query)— method used to update Take Profit/Stop Loss orders.
cancelTpSl(query)— method used to cancel Take Profit/Stop Loss orders.
Balance
This class used to get realtime available balance and power data and handle exchange events.
constructor(options: BalanceOptions)— method used to create aBalanceinstance.
listen()- method used to subscribe to the exchange events and fill balance state. Returns Balance class instance
unListen()- method used to unsubscribe to the exchange events and reset balance state. Returns Balance class instance
getFundingQuantity(currency)— method used to get current funding of the Balance.
getWithdrawTransferPendingQuantity()— method that returns sum of pending withdraw transfers.
getPositionList()— method that returns all positions of the Balance.
getPosition(instrument)— method that returns user position by instrument.
getOrderList()— method that returns the list of existing orders.
getTpSlList()— method that returns existing Take Profit/Stop Loss orders.
getAvailableBalance()— method that returns available balance of the account, existing positions and open orders.
getPower(instrument)— method that returns current buying and selling power (the maximum available order value).
Signals:
Balance class instance can handle realtime events from exchange recieved by websocket using signals.
onAccountUpdate()— signal of updating user data
onFundingUpdate()— signal of updating user data
onTransferUpdate()— signal of updating user transfers data
onPositionUpdate()— signal of updating user positions data
onOrderUpdate()— signal of updating user orders data
onTpSlUpdate()— signal of updating user tpsl data
onMarkPriceUpdate()— signal of updating user mark price data
Last updated