@nexex/cli
Version:
56 lines • 2.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const orderbook_client_1 = require("@nexex/orderbook-client");
const command_1 = require("@oclif/command");
const cli_table3_1 = __importDefault(require("cli-table3"));
const prompts_1 = __importDefault(require("prompts"));
const Token_1 = require("./model/Token");
const WalletBase_1 = __importDefault(require("./WalletBase"));
class MarketBase extends WalletBase_1.default {
initObClient(flags) {
const { endpoint } = flags;
this.obClient = new orderbook_client_1.OrderbookRestClient({ url: endpoint });
return this.obClient;
}
async queryMarkets(flags) {
return this.obClient.markets();
}
async getMarket(flags) {
const markets = await this.queryMarkets(flags);
const { market: marketInput, showAddr } = flags;
if (markets.findIndex(market => marketInput && market.marketId === marketInput) >= 0) {
return marketInput;
}
else {
//ask user
const table = new cli_table3_1.default({
head: ['', 'Market']
// colWidths: [10, 100, 100]
});
markets.forEach(({ base, quote }, idx) => {
const baseToken = new Token_1.Token(base.symbol, base.addr);
const quoteToken = new Token_1.Token(quote.symbol, quote.addr);
table.push([idx, `${baseToken.toString(showAddr)}-${quoteToken.toString(showAddr)}`]);
});
console.log(table.toString());
const response = await prompts_1.default({
type: 'number',
name: 'marketId',
initial: 0,
min: 0,
max: markets.length - 1,
message: `Select a market`
}, { onCancel: () => this.exit(1) });
return markets[response.marketId].marketId;
}
}
}
MarketBase.flags = {
...WalletBase_1.default.flags,
market: command_1.flags.string()
};
exports.default = MarketBase;
//# sourceMappingURL=MarketBase.js.map