UNPKG

tlab-trading-toolkit

Version:

A trading toolkit for building advanced trading bots on the GDAX platform

84 lines (83 loc) 3.25 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); var ccxt = require('ccxt'); class CCXTProductMap { getExchange() { return this.exchange; } getMarket(genericProduct) { return this.exchange.markets[genericProduct]; } getExchangeProduct(genericProduct) { if (!this.exchange.markets[genericProduct]) { console.trace('Generic Product not found'); return null; } return this.exchange.markets[genericProduct]['id']; } getAvailableProducts() { return this.exchange.symbols; } getGenericProduct(exchangeProduct) { if (!this.exchange.markets_by_id[exchangeProduct]) { console.trace('Exchange Product not found'); return null; } return this.exchange.markets_by_id[exchangeProduct]['symbol']; } configureProductMap(exchangeToConfigure) { return __awaiter(this, void 0, void 0, function* () { const EXCHANGE = process.env.Exchange || exchangeToConfigure; switch (EXCHANGE) { case "Binance": this.exchange = new ccxt.binance(); break; case "GDAX": this.exchange = new ccxt.coinbasepro(); break; case "Bitfinex": this.exchange = new ccxt.bitfinex(); break; case "Bittrex": this.exchange = new ccxt.bittrex(); break; case "Poloniex": this.exchange = new ccxt.poloniex(); break; case "Gemini": this.exchange = new ccxt.gemini(); break; case "Bitmex": this.exchange = new ccxt.bitmex(); break; case "Hitbtc": this.exchange = new ccxt.hitbtc(); break; default: console.warn(EXCHANGE + ' Exchange not configured for product map '); } yield this.exchange.loadMarkets(); }); } } exports.CCXTProductMap = CCXTProductMap; class ProductMap { static configureExchange(exchange) { return __awaiter(this, void 0, void 0, function* () { let exchangeMap = new CCXTProductMap(); ; yield exchangeMap.configureProductMap(exchange); ProductMap.ExchangeMap.set(exchange, exchangeMap); }); } } ProductMap.ExchangeMap = new Map(); exports.ProductMap = ProductMap;