Git Product home page Git Product logo

cexio-exchange-plus's Introduction

2024-02-07 Repository Deprecated And Archived

Following the recent rebrand of CEX.IO Exchange Plus to CEX.IO Spot Trading, new repository for the official the official Node.js client for CEX.IO Spot Trading API was created https://github.com/cex-io-exchange/cexio-spot-trading

CEX.IO Exchange Plus

The official Node.js client for CEX.IO Exchange Plus API (https://docs.plus.cex.io)

Features

  • Easy to use, requires only key-secret pair to setup
  • Handle all transport work, just call required action
  • Popular protocols supported, REST and WebSocket onboard

Installation

npm install @cex-io/cexio-exchange-plus

Rest client

const { RestClient } = require('@cex-io/cexio-exchange-plus')
const defaultClient = new RestClient()
const authenticatedClient = new RestClient(apiKey, apiSecret, options)

Arguments for RestClient are optional. For private actions you need to generate apiKey and apiSecret pair from UI terminal.

  • apiKey string - Api key for specific account.
  • apiSecret string - Api secret for specific account.
  • options object - Additional settings for client.

Available client options described below, they all are optional:

  • apiLimit integer - Rate limit value for apiKey. Default is 300. Client will check requests count and prevent from spam the server. You can ask to increase this limit.
  • timeout integer - Request timeout in milliseconds. Default is 30000.
  • rejectUnauthorized boolean - This option useful when you test demo env. Default is true.
  • host string - Can be changed to test your bot on demo environment. Default is 'https://api.plus.cex.io/'
  • apiUrlPublic string - Use a concrete url for public API calls. This option overrides host value. Default is 'https://api.plus.cex.io/rest-public/'
  • apiUrl string - Use a concrete url for private API calls. This option overrides host value. Default is 'https://api.plus.cex.io/rest/'

Public actions

To make a public request use async callPublic(action, params) method. This method return Promise which resolves with server response. If some error was occurred then method rejects with status code and error description.

For more details check api reference.

const { RestClient } = require('@cex-io/cexio-exchange-plus')

const client = new RestClient()

try {
  const res = await client.callPublic('get_ticker')
  console.log(res)
} catch (err) {
  console.log(err)
}
{ error: 'Bad Request', statusCode: 400 }
{ error: 'Unexpected error', statusCode: 500 }

Private actions

To make private api calls use async callPrivate(action, params). It's similar to public method but requires apiKey and apiSecret arguments to client initialization. Each private request is signed with HMAC sha256 so if key is incorrect or signature is wrong client will return rejected promise with error like this { error: 'Authorization Failed', statusCode: 401 }

const { RestClient } = require('@cex-io/cexio-exchange-plus')

const key = '_account_api_key_'
const secret = '_account_api_secret_'
const action = 'get_my_orders'
const params = {
  pair: 'BTC-USD'
}

const client = new RestClient(key, secret)

try {
  const res = await client.callPrivate(action, params)
  console.log(res)
} catch (err) {
  console.error(err)
}

Success response example:

{ ok: 'ok', data: { ... } }

WebSocket client

const { WebsocketClient } = require('@cex-io/cexio-exchange-plus')
const ws = new WebsocketClient(apiKey, apiSecret, options)

To init the WebsocketClient you must pass apiKey and apiSecret arguments. You can generate them in UI terminal.

  • apiKey string - Api key for specific account.
  • apiSecret string - Api secret for specific account.
  • options object - Additional settings for client.

Available client options described below, they all are optional:

  • wsReplyTimeout integer - Request timeout in milliseconds. Default is 30000.
  • rejectUnauthorized boolean - This option useful when you test demo env. Default is true.
  • host string - Can be changed to test your bot on demo environment. Default is 'wss://api.plus.cex.io/'
  • apiUrlPublic string - Use a concrete url for public WS calls. This option overrides host value. Default is 'wss://api.plus.cex.io/ws-public/'
  • apiUrl string - Use a concrete url for private WS calls. This option overrides host value. Default is 'wss://api.plus.cex.io/ws/'

Call Private actions

To send request to the server you need to connect and auth first. Everything is under the hood and all you need is call async ws.connect() method. After that you can invoke async ws.callPrivate(action, params) method which returns Promise with server response. If some error was occurred then method rejects with status code and error description.

  const { WebsocketClient } = require('@cex-io/cexio-exchange-plus')
  const ws = new WebsocketClient(apiKey, apiSecret, options)

  await ws.connect() // connect and auth on the server

  const res = await ws.callPrivate(action, params)
  console.log('result:', res)

  ws.disconnect() // close connection

Subscribe to updates

The WebsocketClient allows you to receive updates. The following types of updates are available: account_update, executionReport, order_book_increment, tradeUpdate, etc. You can get more details about them in documentation.

const { WebsocketClient } = require('@cex-io/cexio-exchange-plus')
const ws = new WebsocketClient(apiKey, apiSecret)

try {
  await ws.connect()

  ws.subscribe('executionReport', msg => {
    console.log('executionReport:', msg)
  })

  ws.subscribe('account_update', msg => {
    console.log('account_update:', msg)
  })
} catch (err) {
  console.error(err)
}

cexio-exchange-plus's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

cexio-exchange-plus's Issues

Inconsistencies between 2 ways methods

I don't know where to open this since this is more of something about the API itself and not specifically the nodejs wrapper.
However it seems that the methods do_deposit_funds_from_wallet & do_withdrawal_funds_to_wallet do differ in the answer about 1 parameter:

  • do_withdrawal_funds_to_wallet takes an optional accountId as a parameter & gives an optional accountId in the answer
  • do_deposit_funds_from_wallet takes an optional accountId as a parameter and doesn't return any

Shouldn't both have the same signature: either return the original accountId or don't return it in the answer ?

referring to

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.