-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyobit.php
198 lines (186 loc) · 7.14 KB
/
yobit.php
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
<?php
namespace ccxt;
include_once ('liqui.php');
class yobit extends liqui {
public function describe () {
return array_replace_recursive (parent::describe (), array (
'id' => 'yobit',
'name' => 'YoBit',
'countries' => 'RU',
'rateLimit' => 3000, // responses are cached every 2 seconds
'version' => '3',
'hasCORS' => false,
'hasWithdraw' => true,
'hasFetchTickers' => false,
'urls' => array (
'logo' => 'https://user-images.githubusercontent.com/1294454/27766910-cdcbfdae-5eea-11e7-9859-03fea873272d.jpg',
'api' => array (
'public' => 'https://yobit.net/api',
'private' => 'https://yobit.net/tapi',
),
'www' => 'https://www.yobit.net',
'doc' => 'https://www.yobit.net/en/api/',
),
'api' => array (
'public' => array (
'get' => array (
'depth/{pair}',
'info',
'ticker/{pair}',
'trades/{pair}',
),
),
'private' => array (
'post' => array (
'ActiveOrders',
'CancelOrder',
'GetDepositAddress',
'getInfo',
'OrderInfo',
'Trade',
'TradeHistory',
'WithdrawCoinsToAddress',
),
),
),
'fees' => array (
'trading' => array (
'maker' => 0.002,
'taker' => 0.002,
),
'funding' => 0.0,
),
));
}
public function common_currency_code ($currency) {
$substitutions = array (
'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 (array_key_exists ($currency, $substitutions))
return $substitutions[$currency];
return $currency;
}
public function currency_id ($commonCode) {
$substitutions = array (
'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 (array_key_exists ($commonCode, $substitutions))
return $substitutions[$commonCode];
return $commonCode;
}
public function fetch_balance ($params = array ()) {
$this->load_markets();
$response = $this->privatePostGetInfo ();
$balances = $response['return'];
$result = array ( 'info' => $balances );
$sides = array ( 'free' => 'funds', 'total' => 'funds_incl_orders' );
$keys = array_keys ($sides);
for ($i = 0; $i < count ($keys); $i++) {
$key = $keys[$i];
$side = $sides[$key];
if (array_key_exists ($side, $balances)) {
$currencies = array_keys ($balances[$side]);
for ($j = 0; $j < count ($currencies); $j++) {
$lowercase = $currencies[$j];
$uppercase = strtoupper ($lowercase);
$currency = $this->common_currency_code($uppercase);
$account = null;
if (array_key_exists ($currency, $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->parse_balance($result);
}
public function create_deposit_address ($currency, $params = array ()) {
$response = $this->fetch_deposit_address ($currency, array_merge (array (
'need_new' => 1,
), $params));
return array (
'currency' => $currency,
'address' => $response['address'],
'status' => 'ok',
'info' => $response['info'],
);
}
public function fetch_deposit_address ($currency, $params = array ()) {
$currencyId = $this->currency_id ($currency);
$request = array (
'coinName' => $currencyId,
'need_new' => 0,
);
$response = $this->privatePostGetDepositAddress (array_merge ($request, $params));
$address = $this->safe_string($response['return'], 'address');
return array (
'currency' => $currency,
'address' => $address,
'status' => 'ok',
'info' => $response,
);
}
public function withdraw ($currency, $amount, $address, $params = array ()) {
$this->load_markets();
$response = $this->privatePostWithdrawCoinsToAddress (array_merge (array (
'coinName' => $currency,
'amount' => $amount,
'address' => $address,
), $params));
return array (
'info' => $response,
'id' => null,
);
}
public function request ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
$response = $this->fetch2 ($path, $api, $method, $params, $headers, $body);
if (array_key_exists ('success', $response)) {
if (!$response['success']) {
if (mb_strpos ($response['error'], 'Insufficient funds') !== false) { // 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;
}
}
?>