Options
All
  • Public
  • Public/Protected
  • All
Menu

@neon-exchange/api-client-typescript - v5.0.27

api-client-typescript

Official TypeScript client for interacting with the Nash Exchange.

To test your integrations, Nash provides a public sandbox environment at https://app.sandbox.nash.io.

NOTE: In sandbox, testnet funds are automatically sent to new accounts. The sandbox environment is reset every couple of days.

Installation

yarn add @neon-exchange/api-client-typescript

Getting started

To get started you need to create an API key. You can find instructions on how to do so on our wiki page.

Remember, API Keys contain sensitive infomation, if you are using version control be careful not to store the key in the repository.

Usage

import {
  Client,
  EnvironmentConfiguration
} from '@neon-exchange/api-client-typescript'

const nash = new Client(EnvironmentConfiguration.sandbox)

const run = async () => {
  const markets = await nash.listMarkets()
  console.log(markets)
}

run()

Note: You can use either EnvironmentConfiguration.production or EnvironmentConfiguration.sandbox.

Authentication

Most Nash API requests require the client to be authenticated. This is needed to sign the payloads being sent over the wire.

import {
  Client,
  EnvironmentConfiguration,
  CryptoCurrency
} from '@neon-exchange/api-client-typescript'

const nash = new Client(EnvironmentConfiguration.sandbox)

const run = async () => {
  try {
    await nash.login(require('PATH_TO_KEY.json'))
    const balance = await nash.getAccountBalance(CryptoCurrency.NEO)
    console.log(balance)
  } catch (e) {
    console.error(e)
  }
}

run()

Websockets

You can use websockets subscriptions like this:

import {
  Client,
  EnvironmentConfiguration
} from '@neon-exchange/api-client-typescript'

const nash = new Client(EnvironmentConfiguration.sandbox)
await nash.login(require('PATH_TO_KEY.json'))

const connection = nash.createSocketConnection()

// Getting the orderbook for the neo_eth marked
connection.onUpdatedOrderbook(
  { marketName: 'neo_eth' },
  {
    onResult: ({
      data: {
        updatedOrderBook: { bids, asks }
      }
    }) => {
      console.log(`updated bids ${bids.length}`)
      console.log(`updated asks ${asks.length}`)
    }
  }
)

// Getting the user orderobok for all markets
connection.onUpdatedAccountOrders(
  {},
  {
    onResult: ({ data: { updatedAccountOrders } }) => {
      console.log(`Updated orders: {updatedAccountOrders.length}`)
    }
  }
)

See also the websockets example.

Managing API key policies

For more information on how to set up policies for API keys, consult the API key policies wiki page.

Generated using TypeDoc