crypto-janitor
Version:
The Crypto Janitor provides a simple interface for fetching and cleaning crypto account data.
135 lines • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A base class to support general connection operations
*/
class BaseConnection {
/**
* Create BaseConnection instance
* @param {string} name - Name of connection (Ex: coinbase)
* @param {string} type - Type of connection (Ex: api)
* @param {any} params - (Optional) Additional paramaters
*/
constructor(name, type, params = {}) {
this.stableCoins = ["USDC", "USDT"];
this.fiatCurrencies = ["USD"];
this.stableCurrencies = ["USD", "USDC", "USDT"];
this.name = name;
this.type = type;
this.connection = null;
this.initialized = false;
this.symbols = [];
this.requireSymbols = params.requireSymbols
? params.requireSymbols
: false;
this.requireUsdValuation = params.requireUsdValuation
? params.requireUsdValuation
: true;
}
/**
* JSON object representing connection
* @return {any}
*/
toJSON() {
const baseJSON = {
name: this.name,
type: this.type,
params: {},
};
if (this.credentials) {
const updatedParams = baseJSON.params;
updatedParams.credentials = this.credentials;
baseJSON.params = updatedParams;
}
return baseJSON;
}
/**
* HELPER: Convert buy/sell to swap if no fiat is involved in order
*
* @param {any} order - Order instance
* @return {Order} Reformatted Order
*/
_attemptedSwapConversion(order) {
if (!this.fiatCurrencies.includes(order.quoteCurrency)) {
if (order.type === "sell") {
const tempBC = order.baseCurrency;
const tempBQ = order.baseQuantity;
const tempBP = order.baseUsdPrice;
order.baseCurrency = order.quoteCurrency;
order.baseQuantity = order.quoteQuantity;
order.baseUsdPrice = order.quoteUsdPrice;
order.quoteCurrency = tempBC;
order.quoteQuantity = tempBQ;
order.quoteUsdPrice = tempBP;
order.quotePrice = order.baseUsdPrice / order.quoteUsdPrice;
}
order.type = "swap";
}
return order;
}
/**
* Initialize exchange by fetching balances and loading markets
* @return {void}
*/
initialize() {
throw Error(`NotImplementedError: ${this.name}.initialize() has not been implemented.`);
}
/**
* Fetch Account Balances
* @return {void}
*/
getBalances() {
throw Error(`NotImplementedError: ${this.name}.getBalances() has not been implemented.`);
}
/**
* Fetch Account Withdrawals
* @return {void}
*/
getWithdrawals() {
throw Error(`NotImplementedError: ${this.name}.getWithdrawals() has not been implemented.`);
}
/**
* Fetch Account Deposits
* @return {void}
*/
getDeposits() {
throw Error(`NotImplementedError: ${this.name}.getDeposits() has not been implemented.`);
}
/**
* Fetch Account Orders
* @return {void}
*/
getOrders() {
throw Error(`NotImplementedError: ${this.name}.getOrders() has not been implemented.`);
}
/**
* Fetch all account ledger (withdrawals, deposits, and orders)
* @return {void}
*/
getLedger() {
throw Error(`NotImplementedError: ${this.name}.getLedger() has not been implemented.`);
}
/**
* Fetch account transactions (withdrawals, deposits, and orders)
* @return {void}
*/
getTransactions() {
throw Error(`NotImplementedError: ${this.name}.getTransactions() has not been implemented.`);
}
/**
* Fetch all account transactions (withdrawals, deposits, and orders)
* @return {void}
*/
getAllTransactions() {
throw Error(`NotImplementedError: ${this.name}.getAllTransactions() has not been implemented.`);
}
/**
* Fetch all account transactions (withdrawals, deposits, and orders)
* @return {void}
*/
getTxUsdVal() {
throw Error(`NotImplementedError: ${this.name}.getTxUsdVal() has not been implemented.`);
}
}
exports.default = BaseConnection;
//# sourceMappingURL=base.js.map