2.2.3 β€’ Published 7 months ago

@coinsamba/js-exchanges-connector v2.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

js-exchanges-connector

An open source JavaScript library for fetching cryptocurrency exchanges

Advantages

  • Zero Dependencies: This library has no external dependencies, making it lightweight and reducing security risks
  • Simple and consistent API across all supported exchanges
  • Typescript support

Instalation

yarn add @coinsamba/js-exchanges-connector

or

npm i @coinsamba/js-exchanges-connector

Usage

Import your favorite exchange connector

import { gateio } from '@coinsamba/js-exchanges-connector';

Getters: all connectors have this same getters used to verify if the connector have an implementation of desired method.

/**
 * will return true if this exchange has the method that return all tickers with all available quote
 */
console.log(gateio.hasAllTickers);

/**
 * will return true if this exchange has the method that return all tickers with specific quote as argument
 */
console.log(gateio.hasAllTickersByQuote);
import { bybit, binance } from '@coinsamba/js-exchanges-connector';

bybit.getTicker('BTC', 'USDT').then(ticker => console.log(ticker));
// will return the ticker in the specified market
// {
//     exchangeId: "bybit",
//     base: "BTC",
//     quote: "USDT",
//     last: 100000,
//     ask: 100000,
//     bid: 100000,
//     vol: 16,
// }

bybit.getBook('BTC', 'USDT').then(book => console.log(book));
// will return orderbook of specified market
// {
//     asks: [{price: 1000, amount: 1}],
//     bids: [{price: 1000, amount: 1}],
// }


bybit.getAllTickersByQuote('USDT').then(tickers => console.log(tickers));
// will return all tickers in the specified market
// [
//     {
//         exchangeId: "bybit",
//         base: "BTC",
//         quote: "USDT",
//         last: 100000,
//         ask: 100000,
//         bid: 100000,
//         vol: 16,
//     },
//     {
//         exchangeId: "bybit",
//         base: "ETH",
//         quote: "USDT",
//         last: 100000,
//         ask: 100000,
//         bid: 100000,
//         vol: 16,
//     }
// ]


binance.getAllTickers().then(tickers => console.log(tickers));
// will return all tickers in all markets
// [
//     {
//         exchangeId: "binance",
//         base: "BTC",
//         quote: "BRL",
//         last: 100000,
//         ask: 100000,
//         bid: 100000,
//         vol: 16,
//     },
//     {
//         exchangeId: "binance",
//         base: "ETH",
//         quote: "BTC",
//         last: 100000,
//         ask: 100000,
//         bid: 100000,
//         vol: 16,
//     }
// ]

Custom fetcher

You can use a custom fetcher, just create a class that implement ICustomFetcher interface, and call FetcherHandler.setFetcher(new MyFetcher()); to start using your custom fetcher. This is cool because you can define proxy or any different strategy to fetch the exchanges APIs.

import {
  FetcherHandler,
} from "@coinsamba/js-exchanges-connector";
import {
  FetcherArgs,
  FetcherRequisitionMethods,
  ICustomFetcher,
} from "@coinsamba/js-exchanges-connector/types";
import Axios, { AxiosError } from "axios";

export class MyFetcher implements ICustomFetcher {
  private parseAxiosError(e: AxiosError) {
    let message = `E - ${e.code}`;
    if (e.response) {
      message += ` - ${e.response.status} - ${e.config!.url} ${
        typeof e.response.data === "object"
          ? `- ${JSON.stringify(e.response.data)}`
          : ""
      }`;
    } else {
      message += ` - ${e.config!.url}`;
    }
    return new Error(message);
  }

  // fetch must handle with get and post methods
  // must be able to receive string paramter and handle as GET method
  async fetch<ResponseType>(args: FetcherArgs): Promise<ResponseType> {
    try {
      if (typeof args == "string") {
        const { data } = await Axios.get<ResponseType>(args);
        return data;
      } else {
        const { data } = await Axios.request<ResponseType>({
          headers: args.headers,
          url: args.url,
          method: args.method,
          [args.method === FetcherRequisitionMethods.GET ? "params" : "data"]:
            args.data,
        });
        return data;
      }
    } catch (error: any) {
      throw this.parseAxiosError(error as unknown as AxiosError);
    }
  }
}


FetcherHandler.setFetcher(new MyFetcher());

Who is using?

  • Coinsamba

Implementations

idgetTickergetAllTickersgetAllTickersByQuotegetBook
binance_us πŸ‡ΊπŸ‡Έβœ“βœ“βœ“
binance πŸŒβœ“βœ“βœ“
bisq πŸŒβœ“βœ“
bitbayβœ“βœ“
bitblue πŸ‡§πŸ‡·βœ“βœ“
bitcointoyou πŸ‡§πŸ‡·βœ“βœ“
bitcointrade πŸ‡§πŸ‡·βœ“βœ“
bitget πŸŒβœ“βœ“
bitmonedero πŸ‡¦πŸ‡·βœ“βœ“
bitnuvem πŸ‡§πŸ‡·βœ“βœ“
bitpreco πŸ‡§πŸ‡·βœ“βœ“βœ“
bitso πŸ‡²πŸ‡½βœ“βœ“
bitstampβœ“βœ“
brasilbitcoin πŸ‡§πŸ‡·βœ“βœ“βœ“
buda πŸ‡¨πŸ‡΄πŸ‡΅πŸ‡ͺπŸ‡¦πŸ‡·πŸ‡¨πŸ‡±βœ“βœ“
bybit πŸŒβœ“βœ“βœ“
cexio πŸŒβœ“βœ“βœ“
citcoin πŸ‡§πŸ‡·βœ“βœ“
coinbase_proβœ“βœ“
coinext πŸ‡§πŸ‡·βœ“βœ“βœ“
coinsbank πŸŒβœ“βœ“
cryptomarket πŸ‡¦πŸ‡·βœ“βœ“
decrypto πŸ‡¦πŸ‡·βœ“
digitra πŸ‡§πŸ‡·βœ“βœ“βœ“
exmo πŸŒβœ“βœ“βœ“
flowbtc πŸ‡§πŸ‡·βœ“βœ“βœ“
foxbit πŸ‡§πŸ‡·βœ“βœ“βœ“
gateio πŸŒβœ“βœ“βœ“
isbit πŸ‡²πŸ‡½βœ“βœ“
isistrade πŸ‡§πŸ‡·βœ“βœ“
kraken πŸŒβœ“βœ“
kucoin πŸŒβœ“βœ“βœ“
luno πŸ‡ΏπŸ‡¦βœ“βœ“
mercadobitcoin πŸ‡§πŸ‡·βœ“βœ“βœ“
novadax πŸ‡§πŸ‡·βœ“βœ“βœ“
noxbitcoin πŸ‡§πŸ‡·βœ“
okx πŸŒβœ“βœ“βœ“
pagcripto_otc πŸ‡§πŸ‡·βœ“βœ“
pagcripto πŸ‡§πŸ‡·βœ“βœ“βœ“
paxos πŸŒβœ“βœ“
poloniex πŸŒβœ“βœ“βœ“
quidax πŸ‡³πŸ‡¬βœ“βœ“
satoshitango πŸ‡¦πŸ‡·βœ“βœ“
trubit πŸŒβœ“βœ“βœ“
upcambio πŸ‡§πŸ‡·βœ“βœ“

Known Whitelabel Platforms

  • alphapoint
  • bnb
  • peatio
  • upex
2.2.1

10 months ago

2.2.3

7 months ago

2.2.2

7 months ago

2.1.18

10 months ago

2.1.19

10 months ago

2.1.20

10 months ago

2.1.17

2 years ago

2.1.16

2 years ago

2.1.15

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.1.9

2 years ago

2.1.14

2 years ago

2.1.12

2 years ago

2.1.13

2 years ago

2.1.10

2 years ago

2.1.11

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.0

2 years ago

1.4.6

3 years ago

1.4.5

3 years ago

1.4.4

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.2.8

3 years ago

1.1.9

3 years ago

1.2.7

3 years ago

1.1.8

3 years ago

1.2.6

3 years ago

1.1.7

3 years ago

1.2.5

3 years ago

1.1.6

3 years ago

1.2.4

3 years ago

1.1.5

3 years ago

1.2.3

3 years ago

1.1.4

3 years ago

1.3.1

3 years ago

1.2.2

3 years ago

1.1.3

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.1.2

3 years ago

1.2.9

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.0

4 years ago