[go: up one dir, main page]

@melonproject/exchange-aggregator
TypeScript icon, indicating that this package has built-in type declarations

0.1.20 • Public • Published

Exchange aggregator

Installation

# With yarn
yarn add @melonproject/exchange-aggregator

# With npm
npm install @melonproject/exchange-aggregator

Usage example

Please note, that not all asset pairs are available on all exchanges.

import { createToken } from '@melonproject/token-math';
import { Network, exchanges, aggregateOrders, createOrderbook } from '@melonproject/exchange-aggregator';

const options = {
  network: Network.MAINNET,
  pair: {
    // The token pair is used for constructing the proper
    // requests (e.g. endpoint urls) and calculations in
    // token-math.
    base: createToken('ZRX', undefined, 18),
    quote: createToken('WETH', undefined, 18),
  },
};

const environment = constructEnvironment({
  endpoint: 'ws://localhost:8545',
});

const promises = await Promise.all([
  exchanges.radarrelay.fetch(options),
  // Some exchanges require extra configuration.
  exchanges.oasisdex.fetch({
    ...options,
    environment,
  }),
]);

// Concatenate the api responses into a single array.
const orders = [].concat(...promises);
// Aggregate all orders into a sorted orderbook with
// cummulative volume information.
const orderbook = createOrderbook(options, orders);

Package Sidebar

Install

npm i @melonproject/exchange-aggregator

Weekly Downloads

3

Version

0.1.20

License

GPL-3.0

Unpacked Size

66.2 kB

Total Files

81

Last publish

Collaborators

  • yogivan
  • fubhy