tlab-trading-toolkit
Version:
A trading toolkit for building advanced trading bots on the GDAX platform
62 lines (61 loc) • 3.7 kB
JavaScript
;
/***************************************************************************************************************************
* @license *
* Copyright 2017 Coinbase, Inc. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on *
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the *
* License for the specific language governing permissions and limitations under the License. *
***************************************************************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../lib/types");
const poloniexFactories_1 = require("../../factories/poloniexFactories");
const utils_1 = require("../utils");
const ProductMap_1 = require("../ProductMap");
exports.POLONIEX_WS_FEED = 'wss://api2.poloniex.com';
exports.POLONIEX_API_URL = 'https://poloniex.com/public';
/**
* Takes a Poloniex product name an 'GDAXifies' it, but replacing '_' with '-' and swapping the quote and base symbols
* @param poloProduct
*/
function getGenericProduct(poloProduct) {
let genericProduct = ProductMap_1.ProductMap.ExchangeMap.get('Poloniex').getGenericProduct(poloProduct);
let genericProductMeta = ProductMap_1.ProductMap.ExchangeMap.get('Poloniex').getMarket(genericProduct);
return {
id: genericProduct,
quoteCurrency: genericProductMeta.quote,
baseCurrency: genericProductMeta.base,
baseMaxSize: types_1.Big(1e6),
baseMinSize: types_1.Big(1e-6),
quoteIncrement: types_1.Big(1e-6)
};
}
exports.getGenericProduct = getGenericProduct;
let productInfo = {};
function getProductInfo(id, refresh, logger) {
if (!refresh && productInfo[id]) {
return Promise.resolve(productInfo[id]);
}
productInfo = {};
const req = poloniexFactories_1.DefaultAPI(logger).publicRequest('returnTicker');
return utils_1.handleResponse(req, null).then((tickers) => {
for (const poloProduct in tickers) {
const ticker = tickers[poloProduct];
const product = Object.assign({ poloniexId: ticker.id, poloniexSymbol: poloProduct, isFrozen: ticker.isFrozen === '1' }, getGenericProduct(poloProduct));
productInfo[ticker.id] = product;
}
return Promise.resolve(productInfo[id]);
});
}
exports.getProductInfo = getProductInfo;
function getAllProductInfo(refresh, logger) {
return getProductInfo(0, refresh, logger).then(() => {
return Promise.resolve(productInfo);
});
}
exports.getAllProductInfo = getAllProductInfo;