xud
Version:
Exchange Union Daemon
68 lines • 3.22 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.handler = exports.builder = exports.describe = exports.command = exports.displayLimits = void 0;
const cli_table3_1 = __importDefault(require("cli-table3"));
const safe_1 = __importDefault(require("colors/safe"));
const xudrpc_pb_1 = require("../../proto/xudrpc_pb");
const command_1 = require("../command");
const utils_1 = require("../utils");
const HEADERS = [
safe_1.default.blue('Currency'),
safe_1.default.blue('Max Buy'),
safe_1.default.blue('Max Sell'),
safe_1.default.blue('Reserved Buy'),
safe_1.default.blue('Reserved Sell'),
];
const formatTradingLimits = (tradingLimits) => {
const formatted = [];
tradingLimits.limitsMap.forEach((tradingLimitElement) => {
const currency = tradingLimitElement[0];
const tradingLimit = tradingLimitElement[1];
const row = [];
row.push(currency, `${utils_1.satsToCoinsStr(tradingLimit.maxBuy)}`, `${utils_1.satsToCoinsStr(tradingLimit.maxSell)}`, `${utils_1.satsToCoinsStr(tradingLimit.reservedBuy)}`, `${utils_1.satsToCoinsStr(tradingLimit.reservedSell)}`);
formatted.push(row);
});
return formatted;
};
const createTable = () => {
const table = new cli_table3_1.default({
head: HEADERS,
});
return table;
};
exports.displayLimits = (limits) => {
const table = createTable();
const formatted = formatTradingLimits(limits);
formatted.forEach(limits => table.push(limits));
console.log(safe_1.default.underline(safe_1.default.bold('\nTrading Limits:')));
console.log(table.toString());
};
exports.command = 'tradinglimits [currency]';
exports.describe = 'trading limits for a given currency';
exports.builder = (argv) => argv
.option('currency', {
describe: 'the currency to query for',
type: 'string',
})
.example('$0 tradinglimits', 'get the trading limits for all currencies')
.example('$0 tradinglimits BTC', 'get the trading limits for BTC');
exports.handler = (argv) => __awaiter(void 0, void 0, void 0, function* () {
const request = new xudrpc_pb_1.TradingLimitsRequest();
if (argv.currency) {
request.setCurrency(argv.currency.toUpperCase());
}
(yield command_1.loadXudClient(argv)).tradingLimits(request, command_1.callback(argv, exports.displayLimits));
});
//# sourceMappingURL=tradinglimits.js.map