-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyobit.js
148 lines (138 loc) · 5.29 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
"use strict";
// ---------------------------------------------------------------------------
const liqui = require ('./liqui.js')
// ---------------------------------------------------------------------------
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;
}
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 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;
}
}