Skip to content

Latest commit

 

History

History
179 lines (147 loc) · 6.25 KB

DOCUMENTATION.md

File metadata and controls

179 lines (147 loc) · 6.25 KB

Classes

Driver
Ticker

Driver

Kind: global class

new Driver(config)

Param Type Description
config object An object holding the configuration
config.requires object An object with settings that a driver requires
config.requires.key boolean Set to true if the driver requires an API key; default: false
config.supports object An object with settings that a driver supports
config.supports.specificMarkets boolean Set to true if the driver supports getting specific markets; default: false

Example

// An example of a driver with an API key
class ApiKeyDriver extends Driver {
  // Indicate that this driver requires an API key.
  constructor() {
    super({
      requires: {
        key: true,
      },
    });
  }

  async fetchTickers() {
    // The API key can now be accessed through this.key.
    const tickers = await request(`http://api.example.com/tickers?key=${this.key}`);
    return tickers.map((ticker) => {
      const {
        base, quote, close, baseVolume,
      } = ticker;

      return new Ticker({
        base,
        quote,
        close,
        baseVolume,
      });
    });
  }
}

// An example of a driver without an API key
class BasicDriver extends Driver {
  async fetchTickers() {
    // Perform an API request to get the data of the exchange.
    const tickers = await request('http://api.example.com/tickers');

    // Return the data mapped to instances of the Ticker model,
    // the exact way will differ for every exchange.
    return tickers.map((ticker) => {
      const {
        base, quote, close, baseVolume,
      } = ticker;

      return new Ticker({
        base,
        quote,
        close,
        baseVolume,
      });
    });
  }
}

driver.key ⇒ string

Get the API key if it is set

Kind: instance property of Driver
Returns: string - API Key

driver.key

Set the API key

Kind: instance property of Driver

Param Type Description
key string API Key

driver.markets ⇒ Array.<string>

Get the specific markets filter

Kind: instance property of Driver
Returns: Array.<string> - ids An array of market ids

driver.markets

Set the specific markets filter

Kind: instance property of Driver

Param Type Description
ids Array.<string> An array of market ids

Driver.fetchTickers ⇒ Promise.Array.<Ticker>

Drivers must include a fetchTickers method.

Kind: static namespace of Driver
Returns: Promise.Array.<Ticker> - Returns a promise of an array with tickers.

Ticker

Kind: global class

new Ticker(params)

Ticker class

Param Type Description
params object The params
params.base string Base
[params.baseName] string The name of the base currency e.g. Ethereum.
[params.baseReference] string A unique indentifier of the base currency on a particular blockchain. For example: on the Ethereum blockchain this would be the smart contract address, on EOS this would be the token name together with the account name and on Waves this should be the AssetId. e.g. 0x0000000000000000000000000000000000000000.
params.quote string Quote
[params.quoteName] string The name of the quote currency e.g. Tether.
[params.quoteReference] string A unique indentifier of the quote currency on a particular blockchain. For example: on the Ethereum blockchain this would be the smart contract address, on EOS this would be the token name together with the account name and on Waves this should be the AssetId. e.g. 0xdac17f958d2ee523a2206206994597c13d831ec7.
[params.open] number The price of the market 24 hours ago
[params.high] number The highest price of the market in the last 24 hours
[params.low] number The lowest price of the market in the last 24 hours
params.close number The last price of the market
[params.bid] number Current highest bid of the market. The bid is the buyer of the base currency and should always be lower than or equal to the ask.
[params.ask] number Current lowest ask of the market. The ask is the seller of the base currency and should always be higher than or equal to the bid.
[params.vwap] number Volume weighted Average Price of the last 24 hours
[params.baseVolume] number The volume traded in the last 24 hours in the base currency. Which is ETH in the ETH_BTC pair for example. Base volume is only optional if quote volume is provided.
[params.quoteVolume] number The volume traded in the last 24 hours in the quote currency. Which is BTC in the ETH_BTC pair for example. Quote volume is only optional if base volume is provided.

Example

const ticker = new Ticker({
  base: 'ETH',
  quote: 'BTC',
  baseName: 'Ethereum',
  quoteName: 'Bitcoin',
  open: 0.033633,
  high: 0.033890,
  low: 0.033622,
  close: 0.033721,
  bid: 0.033701,
  ask: 0.033732,
  baseVolume: 488239,
  quoteVolume: 16463.91,
});