npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@exchange-gate.io/eg-sdk-js

v2.0.0

Published

Exchange-Gate.IO javascript browser/nodeJS SDK

Downloads

2

Readme

ExchangeGate Javascript SDK

This ExchangeGate SDK library supports web browsers and NodeJS.

Installation

NPM (or Yarn)

You can use any NPM-compatible package manager, including NPM itself and Yarn.

npm i @exchange-gate.io/eg-sdk-js

Then:

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

Or, if you're not using ES6 modules:

const ExchangeGate = require('@exchange-gate.io/eg-sdk-js').ExchangeGate;

REST API

Initialize Rest Client

const egRest = new ExchangeGate.Rest(API_KEY);

Public trades snapshot

Fetch latest x100 public trades

const publicTrades = await egRest.fetchPublicTradesSnapshot('binance', 'btc-usdt');

Order Book snapshot

Fetch OrderBook snapshot x100 Bids/Asks

const orderBook = await egRest.fetchOrderBookSnapshot('binance', 'btc-usdt');

Exchanger markets

Fetch available Exchanger Markets

const exchangerMarkets = await egRest.fetchExchangerMarkets();

Price ticker

Fetch price ticker for selected markets based from last trade price

const priceTicker = await egRest.fetchPriceTicker('binance', ['btc-usdt', 'btc-eth']);

OrderBook ticker

Fetch order book ticker for selected markets based from best bid/ask

const orderBookTicker = await egRest.fetchOrderBookTicker('binance', ['btc-usdt', 'btc-eth']);

Wallet balance

Fetch Exchanger account wallet balance

const walletBalance = await egRest.fetchWalletBalance('binance', 'btc-usdt');

Open orders

Fetch Exchanger account open orders

const openOrders = await egRest.fetchOpenOrders('binance', 'btc-usdt');

My trades

Fetch Exchanger account trades

const myTrades = await egRest.fetchMyTrades('binance', 'btc-usdt');

Market order

Create Market order

const side = 'buy'; // sell
const marketOrder = await egRest.createMarketOrder('binance', 'btc-usdt', side, amount);

Limit order

Create Limit order

const side = 'buy'; // sell
const limitOrder = await egRest.createLimitOrder('binance', 'btc-usdt', side, amount, limitPrice);

Cancel order

Cancel open order

const order = await egRest.cancelOrder('binance', 'btc-usdt', uuid);

REALTIME

Initialize Realtime Client

const egRealtime = new ExchangeGate.Realtime(API_KEY);

Socket events

Listen for socket 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 (RPC) over WebSocket's

Any of REST API methods also available over WS as RPC

const publicTrades = await egRealtime.rpc.fetchPublicTradesSnapshot('binance', 'btc-usdt');

STREAMS

Public trades

Subscribe public trades stream

const streamSubscription = egRealtime.stream.publicTrades('binance', 'btc-usdt');
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.publicTrades('binance', 'btc-usdt').close();

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

egRealtime.stream.publicTrades('binance', 'btc-usdt');
// this will be same subscription - no double spend
egRealtime.stream.publicTrades('binance', 'btc-usdt');

Disconnect from socket server

egRealtime.disconnect();

Order book

Subscribe order book stream.
Always verified and synchronized with server snapshot, even after dropped connection silently sync's back to guarantee bid/ask precision;
emitTimeoutMs - default 500, set to 0 for realtime.

const streamSubscription = egRealtime.stream.orderBook('binance', 'btc-usdt', emitTimeoutMs);
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

Price ticker

Subscribe market price ticker stream.
Price ticker for selected markets based from last trade price, published once per second

const streamSubscription = egRealtime.stream.priceTicker('binance', ['btc-usdt', 'btc-eth']);
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

OrderBook ticker

Subscribe market order book ticker stream.
Order book ticker for selected markets based from best bid/ask, published once per second

const streamSubscription = egRealtime.stream.orderBookTicker('binance', ['btc-usdt', 'btc-eth']);
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

My trades

Subscribe my trades stream

const streamSubscription = egRealtime.stream.myTrades('binance', 'btc-usdt');
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

Open orders

Subscribe Open orders stream.
New orders or any existing order changes

const streamSubscription = egRealtime.stream.openOrders('binance', 'btc-usdt');
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

Wallet balance

Subscribe Wallet balance stream.

const streamSubscription = egRealtime.stream.walletBalance('binance', 'btc-usdt');
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();

Subscription details

Subscribe Subscription details stream.
Remaining credits, available/used socket connections

const streamSubscription = egRealtime.stream.subscriptionDetails();
(async () => {
    for await (const event of streamSubscription.consumer()) {
        console.log('event', event.name, event.data);
    }
})();