Software development kit

Use our official SDK libraries and access our products with easy steps

Installation

npm install @exchange-gate.io/eg-sdk-js
yarn add @exchange-gate.io/eg-sdk-js

Rest client usage

import { ExchangeGate } from '@exchange-gate.io/eg-sdk-js';


const egRest = new ExchangeGate.Rest(API_KEY);

Realtime client usage

import { ExchangeGate } from '@exchange-gate.io/eg-sdk-js';


const egRealtime = new ExchangeGate.Realtime(API_KEY);

Socket events

Available events

error, connect, disconnect, connectAbort, close, connecting, kickOut, subscribe, subscribeFail, unsubscribe, subscribeStateChange, subscribeRequest

Listening events

const socketEvents = ['connect', 'connecting', 'error', 'disconnect', 'close'];
for (const socketEvent of socketEvents) {
    egRealtime.onSocketEvent(socketEvent, (e) => {
        console.log('onSocketEvent', socketEvent, e);
    });
}

Remote Procedure Call's

Any of REST API methods also available over WS as RPC

const rpcClient = egRealtime.rpc;

Streams

Subscribe stream events
(Example using ExchangeGate account subscription details stream)

const streamSubscription = egRealtime.stream.subscriptionDetails();
const streamConsumerA = streamSubscription.consumer();
const streamConsumerB = streamSubscription.consumer();

(async () => {
    for await (const event of streamConsumerA) {
        console.log('event-A', event.name, event.data);
    }
    console.log('stream-A closed');
})();

(async () => {
    for await (const event of streamConsumerB) {
        console.log('event-B', event.name, event.data);
    }
    console.log('stream-B closed');
})();

Kill consumer-A but preserve subscription and any other consumers

streamConsumerA.kill();

UnSubscribe stream and close all stream consumers

streamSubscription.close();
// OR
egRealtime.stream.subscriptionDetails().close();

!NOTE! It is safe to issue stream subscription multiple times within single connection

egRealtime.stream.subscriptionDetails();
// this will be same subscription - no double spend
egRealtime.stream.subscriptionDetails();

Disconnect from socket server

egRealtime.disconnect();

Follow our products sections

For specific API interaction, follow our products sections