-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaymium.js
212 lines (199 loc) · 7.84 KB
/
paymium.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');
const { ExchangeError } = require ('./base/errors');
// ---------------------------------------------------------------------------
module.exports = class paymium extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'paymium',
'name': 'Paymium',
'countries': [ 'FR', 'EU' ],
'rateLimit': 2000,
'version': 'v1',
'has': {
'CORS': true,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27790564-a945a9d4-5ff9-11e7-9d2d-b635763f2f24.jpg',
'api': 'https://paymium.com/api',
'www': 'https://www.paymium.com',
'doc': [
'https://github.com/Paymium/api-documentation',
'https://www.paymium.com/page/developers',
],
},
'api': {
'public': {
'get': [
'countries',
'data/{id}/ticker',
'data/{id}/trades',
'data/{id}/depth',
'bitcoin_charts/{id}/trades',
'bitcoin_charts/{id}/depth',
],
},
'private': {
'get': [
'merchant/get_payment/{UUID}',
'user',
'user/addresses',
'user/addresses/{btc_address}',
'user/orders',
'user/orders/{UUID}',
'user/price_alerts',
],
'post': [
'user/orders',
'user/addresses',
'user/payment_requests',
'user/price_alerts',
'merchant/create_payment',
],
'delete': [
'user/orders/{UUID}/cancel',
'user/price_alerts/{id}',
],
},
},
'markets': {
'BTC/EUR': { 'id': 'eur', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR' },
},
'fees': {
'trading': {
'maker': 0.0059,
'taker': 0.0059,
},
},
});
}
async fetchBalance (params = {}) {
let balances = await this.privateGetUser ();
let result = { 'info': balances };
let currencies = Object.keys (this.currencies);
for (let i = 0; i < currencies.length; i++) {
let currency = currencies[i];
let lowercase = currency.toLowerCase ();
let account = this.account ();
let balance = 'balance_' + lowercase;
let locked = 'locked_' + lowercase;
if (balance in balances)
account['free'] = balances[balance];
if (locked in balances)
account['used'] = balances[locked];
account['total'] = this.sum (account['free'], account['used']);
result[currency] = account;
}
return this.parseBalance (result);
}
async fetchOrderBook (symbol, limit = undefined, params = {}) {
let orderbook = await this.publicGetDataIdDepth (this.extend ({
'id': this.marketId (symbol),
}, params));
let result = this.parseOrderBook (orderbook, undefined, 'bids', 'asks', 'price', 'amount');
result['bids'] = this.sortBy (result['bids'], 0, true);
return result;
}
async fetchTicker (symbol, params = {}) {
let ticker = await this.publicGetDataIdTicker (this.extend ({
'id': this.marketId (symbol),
}, params));
let timestamp = ticker['at'] * 1000;
let vwap = parseFloat (ticker['vwap']);
let baseVolume = parseFloat (ticker['volume']);
let quoteVolume = baseVolume * vwap;
let last = this.safeFloat (ticker, 'price');
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': this.safeFloat (ticker, 'high'),
'low': this.safeFloat (ticker, 'low'),
'bid': this.safeFloat (ticker, 'bid'),
'bidVolume': undefined,
'ask': this.safeFloat (ticker, 'ask'),
'askVolume': undefined,
'vwap': vwap,
'open': this.safeFloat (ticker, 'open'),
'close': last,
'last': last,
'previousClose': undefined,
'change': undefined,
'percentage': this.safeFloat (ticker, 'variation'),
'average': undefined,
'baseVolume': baseVolume,
'quoteVolume': quoteVolume,
'info': ticker,
};
}
parseTrade (trade, market) {
let timestamp = parseInt (trade['created_at_int']) * 1000;
let volume = 'traded_' + market['base'].toLowerCase ();
return {
'info': trade,
'id': trade['uuid'],
'order': undefined,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': market['symbol'],
'type': undefined,
'side': trade['side'],
'price': trade['price'],
'amount': trade[volume],
};
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
let market = this.market (symbol);
let response = await this.publicGetDataIdTrades (this.extend ({
'id': market['id'],
}, params));
return this.parseTrades (response, market, since, limit);
}
async createOrder (market, type, side, amount, price = undefined, params = {}) {
let order = {
'type': this.capitalize (type) + 'Order',
'currency': this.marketId (market),
'direction': side,
'amount': amount,
};
if (type === 'market')
order['price'] = price;
let response = await this.privatePostUserOrders (this.extend (order, params));
return {
'info': response,
'id': response['uuid'],
};
}
async cancelOrder (id, symbol = undefined, params = {}) {
return await this.privatePostCancelOrder (this.extend ({
'orderNumber': id,
}, params));
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'] + '/' + this.version + '/' + this.implodeParams (path, params);
let query = this.omit (params, this.extractParams (path));
if (api === 'public') {
if (Object.keys (query).length)
url += '?' + this.urlencode (query);
} else {
this.checkRequiredCredentials ();
body = this.json (params);
let nonce = this.nonce ().toString ();
let auth = nonce + url + body;
headers = {
'Api-Key': this.apiKey,
'Api-Signature': this.hmac (this.encode (auth), this.encode (this.secret)),
'Api-Nonce': nonce,
'Content-Type': 'application/json',
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let response = await this.fetch2 (path, api, method, params, headers, body);
if ('errors' in response)
throw new ExchangeError (this.id + ' ' + this.json (response));
return response;
}
};