-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyobit.js
200 lines (187 loc) · 6.89 KB
/
yobit.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
"use strict";
// ---------------------------------------------------------------------------
const liqui = require ('./liqui.js')
const { ExchangeError, InsufficientFunds, DDoSProtection } = require ('./base/errors')
// ---------------------------------------------------------------------------
module.exports = class yobit extends liqui {
describe () {
return this.deepExtend (super.describe (), {
'id': 'yobit',
'name': 'YoBit',
'countries': 'RU',
'rateLimit': 3000, // responses are cached every 2 seconds
'version': '3',
'hasCORS': false,
'hasWithdraw': true,
'hasFetchTickers': false,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766910-cdcbfdae-5eea-11e7-9859-03fea873272d.jpg',
'api': {
'public': 'https://yobit.net/api',
'private': 'https://yobit.net/tapi',
},
'www': 'https://www.yobit.net',
'doc': 'https://www.yobit.net/en/api/',
},
'api': {
'public': {
'get': [
'depth/{pair}',
'info',
'ticker/{pair}',
'trades/{pair}',
],
},
'private': {
'post': [
'ActiveOrders',
'CancelOrder',
'GetDepositAddress',
'getInfo',
'OrderInfo',
'Trade',
'TradeHistory',
'WithdrawCoinsToAddress',
],
},
},
'fees': {
'trading': {
'maker': 0.002,
'taker': 0.002,
},
'funding': 0.0,
},
});
}
commonCurrencyCode (currency) {
let substitutions = {
'AIR': 'AirCoin',
'ANI': 'ANICoin',
'ANT': 'AntsCoin',
'ATM': 'Autumncoin',
'BCC': 'BCH',
'BTS': 'Bitshares2',
'DCT': 'Discount',
'DGD': 'DarkGoldCoin',
'ICN': 'iCoin',
'LIZI': 'LiZi',
'LUN': 'LunarCoin',
'NAV': 'NavajoCoin',
'OMG': 'OMGame',
'PAY': 'EPAY',
'REP': 'Republicoin',
};
if (currency in substitutions)
return substitutions[currency];
return currency;
}
currencyId (commonCode) {
let substitutions = {
'AirCoin': 'AIR',
'ANICoin': 'ANI',
'AntsCoin': 'ANT',
'Autumncoin': 'ATM',
'BCH': 'BCC',
'Bitshares2': 'BTS',
'Discount': 'DCT',
'DarkGoldCoin': 'DGD',
'iCoin': 'ICN',
'LiZi': 'LIZI',
'LunarCoin': 'LUN',
'NavajoCoin': 'NAV',
'OMGame': 'OMG',
'EPAY': 'PAY',
'Republicoin': 'REP',
};
if (commonCode in substitutions)
return substitutions[commonCode];
return commonCode;
}
async fetchBalance (params = {}) {
await this.loadMarkets ();
let response = await this.privatePostGetInfo ();
let balances = response['return'];
let result = { 'info': balances };
let sides = { 'free': 'funds', 'total': 'funds_incl_orders' };
let keys = Object.keys (sides);
for (let i = 0; i < keys.length; i++) {
let key = keys[i];
let side = sides[key];
if (side in balances) {
let currencies = Object.keys (balances[side]);
for (let j = 0; j < currencies.length; j++) {
let lowercase = currencies[j];
let uppercase = lowercase.toUpperCase ();
let currency = this.commonCurrencyCode (uppercase);
let account = undefined;
if (currency in result) {
account = result[currency];
} else {
account = this.account ();
}
account[key] = balances[side][lowercase];
if (account['total'] && account['free'])
account['used'] = account['total'] - account['free'];
result[currency] = account;
}
}
}
return this.parseBalance (result);
}
async createDepositAddress (currency, params = {}) {
let response = await this.fetchDepositAddress (currency, this.extend ({
'need_new': 1,
}, params));
return {
'currency': currency,
'address': response['address'],
'status': 'ok',
'info': response['info'],
};
}
async fetchDepositAddress (currency, params = {}) {
let currencyId = this.currencyId (currency);
let request = {
'coinName': currencyId,
'need_new': 0,
};
let response = await this.privatePostGetDepositAddress (this.extend (request, params));
let address = this.safeString (response['return'], 'address');
return {
'currency': currency,
'address': address,
'status': 'ok',
'info': response,
};
}
async withdraw (currency, amount, address, params = {}) {
await this.loadMarkets ();
let response = await this.privatePostWithdrawCoinsToAddress (this.extend ({
'coinName': currency,
'amount': amount,
'address': address,
}, params));
return {
'info': response,
'id': undefined,
};
}
async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let response = await this.fetch2 (path, api, method, params, headers, body);
if ('success' in response) {
if (!response['success']) {
if (response['error'].indexOf ('Insufficient funds') >= 0) { // not enougTh is a typo inside Liqui's own API...
throw new InsufficientFunds (this.id + ' ' + this.json (response));
} else if (response['error'] == 'Requests too often') {
throw new DDoSProtection (this.id + ' ' + this.json (response));
} else if ((response['error'] == 'not available') || (response['error'] == 'external service unavailable')) {
throw new DDoSProtection (this.id + ' ' + this.json (response));
} else {
throw new ExchangeError (this.id + ' ' + this.json (response));
}
}
}
return response;
}
}