Numbers Prefer Multiplication

    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    Exchange connector

    An API to simplify interaction with token Exchanges.

    Importing the package

    import exchangeConnector, { supportedExchanges, NETWORKS, exchanges } from '@rgbk/exchange-connector'

    How to use it

    You can instantiate a new exchange using the exchangeConnector function, passing the exchange name as first parameter and an options object as second parameter. The available options are: networkdId (defaults to 1), httpUrl and wsUrl. Supported relayers do not need the API's http url and websocket url to be specified, but they are needed when instantiating a 0x standard relayer.

    To take advantage of the singleton, recommended is to have a separate file exporting a ExchangeConnector instance, and to import the instance in the files where we plan to use it.


    // exchangeConnector.js
    import ExchangeConnector from '@rgbk/exchange-connector'
    export default new ExchangeConnector()
    // someOtherFile.js
    import { supportedExchanges, NETWORKS } from '@rgbk/exchange-connector'
    import connector from './exchangeConnector.js'
    const ethfinex = connector.getExchange(supportedExchanges.ETHFINEX, {
      networkId: NETWORKS.KOVAN
    const tickersKovan = await ethfinex.http.getTickers({
      symbols: ['ZRXETH']

    Some methods require specific parameters to be passed, these are saved under a public property options on the class instance.

    import {
    } from '@rgbk/exchange-connector'
    import connector from './exchangeConnector.js'
    const ethfinex = connector.getExchange(supportedExchanges.ETHFINEX, {
      networkId: NETWORKS.KOVAN
    const orders = await ethfinex.http.getOrders({
      symbols: 'ZRXETH',
      precision: ethfinex.options.OrderPrecisions.P4

    The first websocket method that gets invoked will create the connection, which is reused by subsequent calls. A callback is to be passed to these calls as a second parameter to be able to receive the data. All the websocket methods return an unsubscribe function that removes the even listener added to the connection.

    To close the websocket connection, you can call the close() method.

    const unsubscribe = await
      { symbols: 'ZRXETH' },
      (error, data) => (error ? console.error(error) : console.log(data))
    // later when you wish to stop listening

    'RAW' exchange classes will return data unfiltered and unformatted from the API, while non RAW ones will return the data formatted.


    Available Scripts

    In the project directory, you can run:

    yarn build

    Builds the app for production to the dist folder.

    yarn test:unit

    Runs tests with Jest.

    yarn test:unit:watch

    Runs tests with Jest watching for changes.

    yarn lint

    Lints all typescript files.


    When developing the package locally, make sure to run yarn bootstrap in the root directory of the monorepo, and build the package before running it in other packages.


    Read our contribution guidelines.




    npm i @rgbk/exchange-connector

    DownloadsWeekly Downloads






    Unpacked Size

    341 kB

    Total Files


    Last publish


    • gabrigo
    • vshjxyz