forked from igorek17000/alunajs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddExchange.ts
96 lines (75 loc) · 1.99 KB
/
addExchange.ts
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
import inquirer from 'inquirer'
import yargs from 'yargs'
import { AlunaAccountEnum } from '../src/lib/enums/AlunaAccountEnum'
import { AlunaApiFeaturesEnum } from '../src/lib/enums/AlunaApiFeaturesEnum'
import {
bootstrapExchange,
IPromptAnswers,
} from './bootstrapExchange'
import { inquirerValidations } from './utils/inquirerValidations'
const questions = [
{
type: 'input',
name: 'exchangeName',
message: "What's the exchange name?",
validate: inquirerValidations.notNull,
help: () => '(i.e.: Bitfinex, BitMEX, Gate)',
},
{
type: 'checkbox',
message: 'Select trading options:"',
name: 'tradingFeatures',
choices: [
{ name: 'Exchange', value: AlunaAccountEnum.SPOT },
{ name: 'Margin', value: AlunaAccountEnum.MARGIN },
{ name: 'Derivatives', value: AlunaAccountEnum.DERIVATIVES },
],
validate: inquirerValidations.atLeastOne,
},
{
type: 'checkbox',
message: 'Select API features:',
name: 'apiFeatures',
choices: [
{ name: 'Provides method for editing orders', value: AlunaApiFeaturesEnum.ORDER_EDITING },
{ name: 'Provides uid for positions', value: AlunaApiFeaturesEnum.POSITION_ID },
],
},
]
export function getArgV(): any {
const { argv } = yargs
.option('exchangeName', {
alias: 'e',
description: 'Exchange Name',
type: 'string',
})
.option('tradingFeatures', {
alias: 't',
description: 'Trading Features',
type: 'string',
})
.option('apiFeatures', {
alias: 'a',
description: 'API Features',
type: 'string',
})
.help()
.alias('help', 'h')
return argv
}
export async function addExchange() {
const argv: IPromptAnswers = getArgV()
let answers
const {
exchangeName,
tradingFeatures,
apiFeatures,
} = argv
if (exchangeName && tradingFeatures && apiFeatures) {
answers = argv
} else {
answers = await inquirer.prompt(questions)
}
await bootstrapExchange(answers)
}
addExchange()