-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (91 loc) · 2.99 KB
/
index.js
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
const bot = require('./app/traderBot');
const readline = require('readline');
const helpers = require('./app/helpers');
const options = require('./config/options');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Paste your API-key: ', (answer) => {
const key = answer;
console.log(`API-key saved.`);
rl.question('Paste your API-secret: ', (answer) => {
const secret = answer;
console.log(`API-secret saved.`);
rl.close();
const traderBot = new bot(key, secret);
(async () => {
console.log(await traderBot.api('AddOrder'));
})();
});
});
/*const traderBot = new bot(key, secret);*/
async function getTickerLastTrade() {
await traderBot.api('Ticker', {pair: 'usdtzusd'})
.then((res) => console.log(res.USDTZUSD.c[0]))
.catch((rej) => console.log(rej));
}
// gets any open orders
async function getOpenOrders() {
await traderBot.api('OpenOrders')
.then((res) => console.log(res))
.catch((rej) => console.log(rej));
}
// returns true if any open order or false
async function haveOpenOrders() {
await traderBot.api('OpenOrders')
.then((res) => result = !helpers.isEmptyObject(res.open))
.catch((rej) => console.log('Грешка!'));
return result;
}
async function getBalance() {
await traderBot.api('Balance')
.then((res) => console.log(res.ZEUR))
.catch((rej) => console.log(rej));
}
async function getAssetPairs() {
await traderBot.api('AssetPairs')
.then((res) => console.log(res))
.catch((rej) => console.log(rej));
}
/*eb = equivalent balance (combined balance of all currencies)
tb = trade balance (combined balance of all equity currencies)
m = margin amount of open positions
n = unrealized net profit/loss of open positions
c = cost basis of open positions
v = current floating valuation of open positions
e = equity = trade balance + unrealized net profit/loss
mf = free margin = equity - initial margin (maximum margin available to open new positions)
ml = margin level = (equity / initial margin) * 100*/
async function getTradeBalance() {
await traderBot.api('TradeBalance', {asset: 'ETH'})
.then((res) => console.log(res))
.catch((rej) => console.log(rej));
}
async function placeBuyOrder() {
await traderBot.api('AddOrder',
{
pair: 'usdtzusd',
type: 'buy',
ordertype: 'limit',
price: options.prices.buyPrice,
volume: 100
})
.then((res) => console.log(res))
.catch((rej) => console.log(rej));
}
async function placeSellOrder() {
await traderBot.api('AddOrder',
{
pair: 'usdtzusd',
type: 'sell',
ordertype: 'limit',
price: options.prices.sellPrice,
volume: 100
})
.then((res) => console.log(res))
.catch((rej) => console.log(rej));
}
// setInterval(getTickerLastTrade, 10000);
/*
placeSellOrder();*/