UNPKG

crypto-janitor

Version:

The Crypto Janitor provides a simple interface for fetching and cleaning crypto account data.

63 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const target_types_1 = require("../target.types"); const _ = require("lodash"); /** * A Kucoin Implementation of ccxtConnection */ class Kucoin extends target_types_1.CcxtConnection { /** * @description Create Kucoin instance * @param {any} creds - Kucoin API creds */ constructor(creds) { super("kucoin", creds, { requireSymbols: false }); this.quoteCurrency = "USDT"; } /** * HELPER: Format transaction * * @override ccxtConnection._formatTransaction * @param {any} transaction - Unformatted cctx unified transaction * @param {string} forceType - Override tx type * @return {Transaction} Formatted transaction */ _formatTransaction(transaction, forceType) { const formattedTx = super._formatTransaction(transaction, forceType); formattedTx.id = formattedTx.type !== "receive" ? formattedTx.id : transaction.info.walletTxId; return formattedTx; } /** * @description Fetch kucoin account orders * @override ccxtConnection.getOrders * @param {string} symbol Currency symbol (will always be undefined) * @param {number} since (Optional) Timestamp to get transactions since * @return {Array<any>} Array of withdrawal objects */ async getOrders(symbol, since) { const allTransactions = []; const now = this.connection.milliseconds(); let fetchTime = since ? since : this.connection.parse8601("2021-01-01T00:00:00Z"); while (fetchTime <= now) { try { const trades = super.getOrders(symbol, fetchTime, 200); allTransactions.push(trades); fetchTime = fetchTime + 604800000; } catch (e) { console.log(e.message); break; } } let results = await Promise.all(allTransactions); results = _.sortBy(_.flatten(results), "timestamp"); return results; } } exports.default = Kucoin; //# sourceMappingURL=kucoin.js.map