forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaultoro.js
212 lines (198 loc) · 7.16 KB
/
vaultoro.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
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
"use strict";
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
// ---------------------------------------------------------------------------
module.exports = class vaultoro extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'vaultoro',
'name': 'Vaultoro',
'countries': 'CH',
'rateLimit': 1000,
'version': '1',
'has': {
'CORS': true,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766880-f205e870-5ee9-11e7-8fe2-0d5b15880752.jpg',
'api': 'https://api.vaultoro.com',
'www': 'https://www.vaultoro.com',
'doc': 'https://api.vaultoro.com',
},
'api': {
'public': {
'get': [
'bidandask',
'buyorders',
'latest',
'latesttrades',
'markets',
'orderbook',
'sellorders',
'transactions/day',
'transactions/hour',
'transactions/month',
],
},
'private': {
'get': [
'balance',
'mytrades',
'orders',
],
'post': [
'buy/{symbol}/{type}',
'cancel/{id}',
'sell/{symbol}/{type}',
'withdraw',
],
},
},
});
}
async fetchMarkets () {
let result = [];
let markets = await this.publicGetMarkets ();
let market = markets['data'];
let base = market['BaseCurrency'];
let quote = market['MarketCurrency'];
let symbol = base + '/' + quote;
let baseId = base;
let quoteId = quote;
let id = market['MarketName'];
result.push ({
'id': id,
'symbol': symbol,
'base': base,
'quote': quote,
'baseId': baseId,
'quoteId': quoteId,
'info': market,
});
return result;
}
async fetchBalance (params = {}) {
await this.loadMarkets ();
let response = await this.privateGetBalance ();
let balances = response['data'];
let result = { 'info': balances };
for (let b = 0; b < balances.length; b++) {
let balance = balances[b];
let currency = balance['currency_code'];
let uppercase = currency.toUpperCase ();
let free = balance['cash'];
let used = balance['reserved'];
let total = this.sum (free, used);
let account = {
'free': free,
'used': used,
'total': total,
};
result[uppercase] = account;
}
return this.parseBalance (result);
}
async fetchOrderBook (symbol, params = {}) {
await this.loadMarkets ();
let response = await this.publicGetOrderbook (params);
let orderbook = {
'bids': response['data'][0]['b'],
'asks': response['data'][1]['s'],
};
let result = this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'Gold_Price', 'Gold_Amount');
result['bids'] = this.sortBy (result['bids'], 0, true);
return result;
}
async fetchTicker (symbol, params = {}) {
await this.loadMarkets ();
let quote = await this.publicGetBidandask (params);
let bidsLength = quote['bids'].length;
let bid = quote['bids'][bidsLength - 1];
let ask = quote['asks'][0];
let response = await this.publicGetMarkets (params);
let ticker = response['data'];
let timestamp = this.milliseconds ();
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': parseFloat (ticker['24hHigh']),
'low': parseFloat (ticker['24hLow']),
'bid': bid[0],
'ask': ask[0],
'vwap': undefined,
'open': undefined,
'close': undefined,
'first': undefined,
'last': parseFloat (ticker['LastPrice']),
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': undefined,
'quoteVolume': parseFloat (ticker['24hVolume']),
'info': ticker,
};
}
parseTrade (trade, market) {
let timestamp = this.parse8601 (trade['Time']);
return {
'id': undefined,
'info': trade,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': market['symbol'],
'order': undefined,
'type': undefined,
'side': undefined,
'price': trade['Gold_Price'],
'amount': trade['Gold_Amount'],
};
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let response = await this.publicGetTransactionsDay (params);
return this.parseTrades (response, market, since, limit);
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
await this.loadMarkets ();
let market = this.market (symbol);
let method = 'privatePost' + this.capitalize (side) + 'SymbolType';
let response = await this[method] (this.extend ({
'symbol': market['quoteId'].toLowerCase (),
'type': type,
'gld': amount,
'price': price || 1,
}, params));
return {
'info': response,
'id': response['data']['Order_ID'],
};
}
async cancelOrder (id, symbol = undefined, params = {}) {
await this.loadMarkets ();
return await this.privatePostCancelId (this.extend ({
'id': id,
}, params));
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'] + '/';
if (api == 'public') {
url += path;
} else {
this.checkRequiredCredentials ();
let nonce = this.nonce ();
url += this.version + '/' + this.implodeParams (path, params);
let query = this.extend ({
'nonce': nonce,
'apikey': this.apiKey,
}, this.omit (params, this.extractParams (path)));
url += '?' + this.urlencode (query);
headers = {
'Content-Type': 'application/json',
'X-Signature': this.hmac (this.encode (url), this.encode (this.secret)),
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
}