crypto-janitor
Version:
The Crypto Janitor provides a simple interface for fetching and cleaning crypto account data.
118 lines • 4.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveConnection = exports.CsvConnection = exports.CcxtConnection = exports.BaseConnection = exports.Nexo = exports.Kucoin = exports.Etherscan = exports.CoinbasePro = exports.Coinbase = exports.Celsius = exports.Bittrex = void 0;
/* eslint-disable max-len */
/* eslint-disable indent */
require("dotenv").config();
const target_types_1 = require("./target.types");
Object.defineProperty(exports, "BaseConnection", { enumerable: true, get: function () { return target_types_1.BaseConnection; } });
Object.defineProperty(exports, "CcxtConnection", { enumerable: true, get: function () { return target_types_1.CcxtConnection; } });
Object.defineProperty(exports, "CsvConnection", { enumerable: true, get: function () { return target_types_1.CsvConnection; } });
const targets_1 = require("./targets");
Object.defineProperty(exports, "Bittrex", { enumerable: true, get: function () { return targets_1.Bittrex; } });
Object.defineProperty(exports, "Celsius", { enumerable: true, get: function () { return targets_1.Celsius; } });
Object.defineProperty(exports, "Coinbase", { enumerable: true, get: function () { return targets_1.Coinbase; } });
Object.defineProperty(exports, "CoinbasePro", { enumerable: true, get: function () { return targets_1.CoinbasePro; } });
Object.defineProperty(exports, "Etherscan", { enumerable: true, get: function () { return targets_1.Etherscan; } });
Object.defineProperty(exports, "Kucoin", { enumerable: true, get: function () { return targets_1.Kucoin; } });
Object.defineProperty(exports, "Nexo", { enumerable: true, get: function () { return targets_1.Nexo; } });
/**
* @description Return initialized connection instance
* @param {string} name - Name of exchange
* @param {string} type - Type of connection
* @param {any} params - Params for connection instance
* @return {Promise<any>} response of test
*/
const resolveConnection = async (name, type, params) => {
if (name === undefined) {
return { error: "Must specify the name of the connection." };
}
if (type === undefined) {
return { error: "Must specify the type of the connection." };
}
let connection = null;
if (type === "api") {
if (params.credentials === undefined) {
return { error: `Must supply 'credentials' for ${name} in params` };
}
switch (name) {
case "bittrex":
connection = new targets_1.Bittrex(params.credentials);
break;
case "celsius":
connection = new targets_1.Celsius(params.credentials);
break;
case "coinbase":
connection = new targets_1.Coinbase(params.credentials);
break;
case "coinbasepro":
connection = new targets_1.CoinbasePro(params.credentials);
break;
case "kucoin":
connection = new targets_1.Kucoin(params.credentials);
break;
default:
break;
}
if (connection === null) {
return {
error: `Connecting to ${name} via API is not yet supported.`,
};
}
}
else if (type === "address") {
if (params.address === undefined) {
return {
error: "Must supply address for ledger connection in params",
};
}
if (params.chain === undefined) {
return {
error: "Must supply 'chain' for ledger connection in params",
};
}
switch (params.chain) {
case "ethereum":
connection = new targets_1.Etherscan(params.address, params.apiKey);
break;
default:
break;
}
if (connection === null) {
return {
error: `Connecting to ${params.chain} via ledger is not yet supported.`,
};
}
}
else if (type === "csv") {
if (params.fileName === undefined) {
return {
error: "Must supply 'fileName' for csv connection in params",
};
}
switch (name) {
case "nexo":
connection = new targets_1.Nexo(params.fileName, params.loadFileContents);
break;
default:
break;
}
if (connection === null) {
return {
error: `Connecting to ${name} via CSV is not yet supported.`,
};
}
}
else {
return { error: `Connecting with ${type} is not yet supported.` };
}
try {
await connection.initialize();
return { status: "success", connection };
}
catch (error) {
return { status: "failure", error: error.message };
}
};
exports.resolveConnection = resolveConnection;
//# sourceMappingURL=index.js.map