-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtomox-cli
executable file
·767 lines (704 loc) · 28.8 KB
/
tomox-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
#!/usr/bin/env node
const commander = require('commander')
const TomoXJS = require('./index')
const pjson = require('./package.json')
const { prompt } = require('inquirer')
const fs = require('fs')
const path = require('path')
const os = require('os')
const ethers = require('ethers')
const dotenv = require('dotenv')
let configPath = path.resolve(process.cwd(), '.env')
if (fs.existsSync(path.resolve(require('os').homedir(), '.tomoxjs'))) {
configPath = path.resolve(require('os').homedir(), '.tomoxjs')
}
let tomox = new TomoXJS()
commander
.version(pjson.version)
.allowUnknownOption()
.option('-C --config <path>', 'set config path. defaults to $HOME/.tomoxjs')
.description('TomoX Market CLI')
.action((params) => {
configPath = params.config || configPath
dotenv.config({ path: configPath })
if ((process.argv.indexOf('--help') < 0) && (process.argv.indexOf('init') < 0)
&& (process.argv.indexOf('config') < 0)) {
if (!process.env.DEX_URI || !process.env.TRADER_PKEY) {
console.log('DEX_URI, TRADER_PKEY env are require, please create .env file')
process.exit(1)
}
}
tomox = new TomoXJS(
process.env.DEX_URI,
process.env.DEX_WS_URI,
process.env.TRADER_PKEY)
})
if (process.argv.indexOf('--help') < 0 && process.argv.indexOf('-h') < 0) {
commander.parseAsync(process.argv).then(() => {
run()
})
} else {
run()
}
function run() {
commander
.command('init')
.description('setup/init environment')
.option('-p, --password <password>', 'password', '')
.option('-k, --keystore <keystore>', 'path to keystore file', '')
.action(async (params) => {
const questions = [{
type : 'input',
name : 'dexUri',
message : 'Enter DEX Uri (default: https://dex.tomochain.com)...',
default: 'https://dex.tomochain.com'
}, {
type : 'input',
name : 'dexWsUri',
message : 'Enter DEX WebSocket Uri (default: wss://dex.tomochain.com/socket)...',
default: 'wss://dex.tomochain.com/socket'
}]
if (!params.keystore) {
questions.push({
type : 'password',
name : 'traderPKey',
message : 'Enter trader private key (default: Random)...'
})
}
prompt(questions).then(async answers => {
try {
let tomoxjsPath = path.resolve(configPath)
let address = ''
if (params.keystore) {
let keydata = fs.readFileSync(params.keystore);
let json = JSON.parse(keydata);
let wallet = await ethers.Wallet.fromEncryptedJson(JSON.stringify(json), params.password)
answers.traderPKey = wallet.privateKey
address = wallet.address
}
if (!answers.traderPKey) {
let randomWallet = ethers.Wallet.createRandom()
answers.traderPKey = randomWallet.privateKey
address = randomWallet.address
} else {
let wallet = new ethers.Wallet(answers.traderPKey)
address = wallet.address
}
fs.writeFile(tomoxjsPath, `DEX_URI=${answers.dexUri}\nDEX_WS_URI=${answers.dexWsUri}\nTRADER_PKEY=${answers.traderPKey}\nTRADER_ADDR=${address}\n`, function (err) {
if (err) throw err;
console.log('Address:', address);
console.log('Saved!');
})
} catch (e) {
console.log(e)
}
})
})
commander
.command('create')
.description('create a trading order')
.option('-b, --baseToken <baseToken>', 'base token', '0xBD8b2Fb871F97b2d5F0A1af3bF73619b09174B2A')
.option('-q, --quoteToken <quoteToken>', 'quote token', '0x0000000000000000000000000000000000000001')
.option('-p, --price <price>', 'price', '21207')
.option('-a, --amount <amount>', 'amount', '00469')
.option('-s, --side <side>', 'side', 'BUY')
.option('-t, --type <type>', 'type', 'LO')
.option('-e, --exchangeAddress <exchangeAddress>', 'exchangeAddress')
.action(async (params) => {
await tomox.createOrder({
baseToken: params.baseToken,
quoteToken: params.quoteToken,
exchangeAddress: params.exchangeAddress,
price: params.price,
side: params.side,
type: params.type,
amount: params.amount
}).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
function collect(value, previous) {
return previous.concat([value]);
}
function parseDuration(value, previous) {
return parseInt(value)
}
function parseTerm(value, previous) {
return parseInt(value)
}
commander
.command('cancel')
.description('cancel a trading order or cancel multiple orders')
.requiredOption('-H, --hash <hash>', 'hash', collect, [])
.option('-n, --nonce <nonce>', 'nonce')
.action(async (params) => {
if (params.hash.length === 1) {
await tomox.cancelOrder(params.hash[0], params.nonce).then(data => {
console.log(data)
}).catch(e => console.log(e))
}
if (params.hash.length > 1) {
await tomox.cancelManyOrders(params.hash, params.nonce).then(data => {
console.log(data)
}).catch(e => console.log(e))
}
})
commander
.command('pairs')
.description('show trading pairs')
.action(async () => {
await tomox.getPairs().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('o-list')
.description('show user orders')
.alias('list')
.option('-b, --baseToken <baseToken>', 'base token')
.option('-q, --quoteToken <quoteToken>', 'quote token')
.option('-s, --status <status>', 'order status')
.option('-p, --page <page>', 'page')
.option('-l, --limit <limit>', 'limit')
.action(async (params) => {
await tomox.getOrders(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('o-get')
.description('show order by hash')
.alias('get')
.requiredOption('-s, --hash <hash>', 'order hash')
.action(async (params) => {
await tomox.getOrderByHash(params.hash).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('orderbook')
.description('show trading orderbook')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.action(async (params) => {
await tomox.getOrderBook(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('ohlcv')
.description('show trading OHLCV data')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.requiredOption('-i, --timeInterval <timeInterval>', 'time interval, candle size. Valid values: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 1w, 1mo (1 month)')
.action(async (params) => {
await tomox.getOHLCV(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('info')
.description('show DEX information')
.action(async () => {
let ret = {
configPath: configPath,
DEX_URI: process.env.DEX_URI,
DEX_WS_URI: process.env.DEX_WS_URI,
TRADER_ADDR: process.env.TRADER_ADDR,
TRADER_PKEY: '******'
}
await tomox.getRelayerInfo().then(data => {
ret.exchangeAddress = data.exchangeAddress
ret.fee = data.fee
ret.lendingFee = data.lendingFee
console.log(ret)
}).catch(e => {
console.log(ret)
})
})
commander
.command('trades')
.description('show trade history')
.option('-b, --baseToken <baseToken>', 'base token')
.option('-q, --quoteToken <quoteToken>', 'quote token')
.option('-l, --limit <limit>', 'limit records per page')
.option('-p, --page <page>', 'page number')
.action(async (params) => {
tomox.getTrades(params).then(data => console.log(data))
.catch(error => console.log(error))
})
commander
.command('ws-orderbook')
.description('watch trading orderbook')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.action(async (params) => {
await tomox.watchOrderBook(params).then(ws=> {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-ohlcv')
.description('watch trading OHLCV data')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.requiredOption('-u, --units <units>', 'min')
.requiredOption('-d, --duration <duration>', '1', parseDuration)
.action(async (params) => {
await tomox.watchOHLCV(params).then(ws=> {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-trades')
.description('watch trades')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.action(async (params) => {
await tomox.watchTrades(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-price-board')
.description('watch price board')
.requiredOption('-b, --baseToken <baseToken>', 'base token')
.requiredOption('-q, --quoteToken <quoteToken>', 'quote token')
.action(async (params) => {
await tomox.watchPriceBoard(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-markets')
.description('watch trading market')
.action(async () => {
await tomox.watchMarkets().then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
function collect(value, previous) {
return previous.concat([value]);
}
commander
.command('lending-hash')
.alias('l-hash')
.description('show lending order by hash')
.requiredOption('-H , --hash <hash>', 'lending hash')
.action(async (params) => {
await tomox.getLendingByHash(params.hash).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-nonce')
.description('show lending user nonce')
.action(async () => {
await tomox.getLendingNonce().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-create')
.alias('l-create')
.description('create a lending order')
.option('-c, --collateralToken <collateralToken>', 'collateral token')
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.requiredOption('-q, --quantity <quantity>', 'quantity')
.requiredOption('-i, --interest <interest>', 'interest')
.option('-e, --term <term>', 'term', '86400')
.option('-s, --side <side>', 'side', 'INVEST')
.option('-t, --type <type>', 'type', 'LO')
.option('-r, --relayerAddress <relayerAddress>', 'relayerAddress')
.option('-n, --nonce <nonce>')
.option('-u, --autoTopUp <autoTopUp>', 'auto topup', '1')
.action(async (params) => {
await tomox.createLending({
collateralToken: params.collateralToken,
lendingToken: params.lendingToken,
relayerAddress: params.relayerAddress,
quantity: params.quantity,
interest: params.interest,
term: params.term,
side: params.side,
type: params.type,
nonce: params.nonce,
autoTopUp: params.autoTopUp,
}).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('ws-lending-create')
.description('create a lending order via websocket')
.option('-c, --collateralToken <collateralToken>', 'collateral token', '0xBD8b2Fb871F97b2d5F0A1af3bF73619b09174B2A')
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token', '0x0000000000000000000000000000000000000001')
.requiredOption('-q, --quantity <quantity>', 'quantity', '2')
.requiredOption('-i, --interest <interest>', 'interest', '10')
.option('-e, --term <term>', 'term', '86400')
.option('-s, --side <side>', 'side', 'INVEST')
.option('-t, --type <type>', 'type', 'LO')
.option('-r, --relayerAddress <relayerAddress>', 'relayerAddress')
.option('-n, --nonce <nonce>')
.action(async (params) => {
await tomox.createWsLending({
collateralToken: params.collateralToken,
lendingToken: params.lendingToken,
relayerAddress: params.relayerAddress,
quantity: params.quantity,
interest: params.interest,
term: params.term,
side: params.side,
type: params.type,
nonce: params.nonce,
}).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('create-lending-repay')
.alias('repay')
.description('create repay a loan')
.option('-r, --relayerAddress <relayerAddress>')
.requiredOption('-l, --lendingToken <lendingToken>')
.requiredOption('-t, --term <term>')
.requiredOption('-i, --tradeId <tradeId>')
.option('-n, --nonce <nonce>')
.action(async (params) => {
await tomox.repayLending({
relayerAddress: params.relayerAddress,
lendingToken: params.lendingToken,
term: params.term,
tradeId: params.tradeId,
nonce: params.nonce,
}).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('create-lending-topup')
.description('create topup a loan')
.alias('topup')
.option('-r, --relayerAddress <relayerAddress>')
.requiredOption('-l, --lendingToken <lendingToken>')
.requiredOption('-t, --term <term>')
.requiredOption('-c, --collateralToken <collateralToken>')
.requiredOption('-q, --quantity <quantity>')
.requiredOption('-i, --tradeId <tradeId>')
.option('-n, --nonce <nonce>')
.action(async (params) => {
await tomox.topupLending({
relayerAddress: params.relayerAddress,
lendingToken: params.lendingToken,
term: params.term,
collateralToken: params.collateralToken,
quantity: params.quantity,
tradeId: params.tradeId,
nonce: params.nonce,
}).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-cancel')
.alias('l-cancel')
.description('cancel a lending order')
.requiredOption('-H, --cancelHash <cancelHash>')
.option('-n, --nonce <nonce>', 'nonce')
.action(async (params) => {
await tomox.cancelLending({
nonce: params.nonce,
hash: params.cancelHash
}).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-orderbook')
.description('show lending orderbook')
.requiredOption('-t, --term <term>', '60')
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
await tomox.getLendingOrderBook(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('ws-lending-orderbook')
.description('watch lending orderbook')
.requiredOption('-t, --term <term>', 'lending term', parseTerm)
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
await tomox.watchLendingOrderBook(params).then(ws=> {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-lending-trades')
.description('watch lending trades')
.requiredOption('-t, --term <term>', 'lending term', parseTerm)
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
await tomox.watchLendingTrade(params).then(ws=> {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-lending-ohlcv')
.description('watch lending OHLCV data')
.requiredOption('-t, --term <term>', 'lending term', parseTerm)
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.requiredOption('-u, --units <units>', 'min')
.requiredOption('-d, --duration <duration>', 'ohlcv duration, candle side', parseDuration)
.action(async (params) => {
await tomox.watchLendingOhlcv(params).then(ws=> {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('lending-ohlcv')
.description('get lending OHLCV data')
.requiredOption('-t, --term <term>', 'lending term')
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.requiredOption('-u, --timeInterval <timeInterval>', 'timeInterval')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.action(async (params) => {
await tomox.getLendingOhlcv(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-pairs')
.description('show lending pairs')
.action(async () => {
await tomox.getLendingPairs().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-markets')
.description('show lending markets')
.option('-t, --term <term>', 'lending term (seconds)')
.option('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
if (params.term && params.lendingToken) {
await tomox.getLendingMarket(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
} else {
await tomox.getLendingMarkets().then(data => {
console.log(data)
}).catch(e => console.log(e))
}
})
commander
.command('ws-lending-markets')
.description('watch all lending markets')
.action(async () => {
await tomox.watchLendingMarkets().then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('lending-tokens')
.alias('l-tokens')
.description('show lending tokens')
.action(async () => {
await tomox.getLendingTokens().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('collateral-tokens')
.description('show lending collateral tokens')
.action(async () => {
await tomox.getCollateralTokens().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-trades-history')
.description('show lending trades')
.option('-a, --address <address>', 'address')
.requiredOption('-t, --term <term>', 'term')
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
await tomox.getLendingTradesHistory(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-terms')
.description('show lending terms')
.action(async () => {
await tomox.getLendingTerms().then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-orders')
.alias('l-orders')
.description('show list lending orders')
.option('-a, --address <address>', 'address')
.option('-l, --lendingToken <lendingToken>', 'lendingToken')
.option('-c, --collateralToken <collateralToken>', 'collateralToken')
.option('-t, --term <term>', 'term')
.option('-s, --lendingStatus <lendingStatus>', 'lendingStatus')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.option('-O, --pageOffset <pageOffset>', 'pageOffset')
.option('-S, --pageSize <pageSize>', 'pageSize')
.action(async (params) => {
await tomox.getLendingOrders(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-trades')
.alias('l-trades')
.description('show list lending trades')
.option('-l, --lendingToken <lendingToken>', 'lendingToken')
.option('-t, --term <term>', 'term')
.option('-s, --status <status>', 'status')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.option('-O, --pageOffset <pageOffset>', 'pageOffset')
.option('-S, --pageSize <pageSize>', 'pageSize')
.action(async (params) => {
await tomox.getLendingTrades(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('ws-lending-priceboard')
.description('watch lending price board')
.requiredOption('-t, --term <term>', 'term', parseTerm)
.requiredOption('-l, --lendingToken <lendingToken>', 'lending token')
.action(async (params) => {
await tomox.watchLendingPriceBoard(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('lending-topups')
.alias('l-topups')
.description('show list topups')
.option('-a, --address <address>', 'address')
.option('-l, --lendingToken <lendingToken>', 'lendingToken')
.option('-c, --collateralToken <collateralToken>', 'collateralToken')
.option('-t, --term <term>', 'term')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.option('-O, --pageOffset <pageOffset>', 'pageOffset')
.option('-S, --pageSize <pageSize>', 'pageSize')
.action(async (params) => {
await tomox.getLendingTopups(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-repays')
.alias('l-repays')
.description('show list repays')
.option('-a, --address <address>', 'address')
.option('-l, --lendingToken <lendingToken>', 'lendingToken')
.option('-t, --term <term>', 'term')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.option('-O, --pageOffset <pageOffset>', 'pageOffset')
.option('-S, --pageSize <pageSize>', 'pageSize')
.action(async (params) => {
await tomox.getLendingRepays(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-recalls')
.alias('l-recalls')
.description('show list recall')
.option('-a, --address <address>', 'address')
.option('-l, --lendingToken <lendingToken>', 'lendingToken')
.option('-c, --collateralToken <collateralToken>', 'collateralToken')
.option('-t, --term <term>', 'term')
.option('-F, --from <from>', 'from')
.option('-T, --to <to>', 'to')
.option('-O, --pageOffset <pageOffset>', 'pageOffset')
.option('-S, --pageSize <pageSize>', 'pageSize')
.action(async (params) => {
await tomox.getLendingRecalls(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('lending-estimate')
.alias('l-estimate')
.description('estimate collateral amount')
.requiredOption('-l, --lendingToken <lendingToken>', 'lendingToken')
.requiredOption('-c, --collateralToken <collateralToken>', 'collateralToken')
.requiredOption('-a, --amount <amount>', 'amount')
.action(async (params) => {
await tomox.estimateCollateral(params).then(data => {
console.log(data)
}).catch(e => console.log(e))
})
commander
.command('ws-notification')
.description('watch user notification')
.option('-u, --userAddress <userAddress>', 'user address')
.action(async (params) => {
params.userAddress = params.userAddress || process.env.TRADER_ADDR
await tomox.watchNotification(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-orders')
.description('watch user orders')
.option('-u, --userAddress <userAddress>', 'user address')
.action(async (params) => {
params.userAddress = params.userAddress || process.env.TRADER_ADDR
await tomox.watchOrders(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander
.command('ws-lending-orders')
.description('watch user lending orders')
.option('-u, --userAddress <userAddress>', 'user address')
.action(async (params) => {
params.userAddress = params.userAddress || process.env.TRADER_ADDR
await tomox.watchLendingOrders(params).then(ws => {
ws.on('message', (message) => {
console.log('%s', message)
})
}).catch(e => console.log(e))
})
commander.parse(process.argv)
}