-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinmate.php
218 lines (204 loc) · 8.81 KB
/
coinmate.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
namespace ccxt;
// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
use Exception as Exception; // a common import
class coinmate extends Exchange {
public function describe () {
return array_replace_recursive (parent::describe (), array (
'id' => 'coinmate',
'name' => 'CoinMate',
'countries' => array ( 'GB', 'CZ', 'EU' ), // UK, Czech Republic
'rateLimit' => 1000,
'has' => array (
'CORS' => true,
),
'urls' => array (
'logo' => 'https://user-images.githubusercontent.com/1294454/27811229-c1efb510-606c-11e7-9a36-84ba2ce412d8.jpg',
'api' => 'https://coinmate.io/api',
'www' => 'https://coinmate.io',
'doc' => array (
'http://docs.coinmate.apiary.io',
'https://coinmate.io/developers',
),
'referral' => 'https://coinmate.io?referral=YTFkM1RsOWFObVpmY1ZjMGREQmpTRnBsWjJJNVp3PT0',
),
'requiredCredentials' => array (
'apiKey' => true,
'secret' => true,
'uid' => true,
),
'api' => array (
'public' => array (
'get' => array (
'orderBook',
'ticker',
'transactions',
),
),
'private' => array (
'post' => array (
'balances',
'bitcoinWithdrawal',
'bitcoinDepositAddresses',
'buyInstant',
'buyLimit',
'cancelOrder',
'cancelOrderWithInfo',
'createVoucher',
'openOrders',
'redeemVoucher',
'sellInstant',
'sellLimit',
'transactionHistory',
'unconfirmedBitcoinDeposits',
),
),
),
'markets' => array (
'BTC/EUR' => array ( 'id' => 'BTC_EUR', 'symbol' => 'BTC/EUR', 'base' => 'BTC', 'quote' => 'EUR', 'precision' => array ( 'amount' => 4, 'price' => 2 )),
'BTC/CZK' => array ( 'id' => 'BTC_CZK', 'symbol' => 'BTC/CZK', 'base' => 'BTC', 'quote' => 'CZK', 'precision' => array ( 'amount' => 4, 'price' => 2 )),
'LTC/BTC' => array ( 'id' => 'LTC_BTC', 'symbol' => 'LTC/BTC', 'base' => 'LTC', 'quote' => 'BTC', 'precision' => array ( 'amount' => 4, 'price' => 5 )),
),
'fees' => array (
'trading' => array (
'maker' => 0.0005,
'taker' => 0.0035,
),
),
));
}
public function fetch_balance ($params = array ()) {
$response = $this->privatePostBalances ();
$balances = $response['data'];
$result = array ( 'info' => $balances );
$currencies = is_array ($this->currencies) ? array_keys ($this->currencies) : array ();
for ($i = 0; $i < count ($currencies); $i++) {
$currency = $currencies[$i];
$account = $this->account ();
if (is_array ($balances) && array_key_exists ($currency, $balances)) {
$account['free'] = $balances[$currency]['available'];
$account['used'] = $balances[$currency]['reserved'];
$account['total'] = $balances[$currency]['balance'];
}
$result[$currency] = $account;
}
return $this->parse_balance($result);
}
public function fetch_order_book ($symbol, $limit = null, $params = array ()) {
$response = $this->publicGetOrderBook (array_merge (array (
'currencyPair' => $this->market_id($symbol),
'groupByPriceLimit' => 'False',
), $params));
$orderbook = $response['data'];
$timestamp = $orderbook['timestamp'] * 1000;
return $this->parse_order_book($orderbook, $timestamp, 'bids', 'asks', 'price', 'amount');
}
public function fetch_ticker ($symbol, $params = array ()) {
$response = $this->publicGetTicker (array_merge (array (
'currencyPair' => $this->market_id($symbol),
), $params));
$ticker = $response['data'];
$timestamp = $ticker['timestamp'] * 1000;
$last = $this->safe_float($ticker, 'last');
return array (
'symbol' => $symbol,
'timestamp' => $timestamp,
'datetime' => $this->iso8601 ($timestamp),
'high' => $this->safe_float($ticker, 'high'),
'low' => $this->safe_float($ticker, 'low'),
'bid' => $this->safe_float($ticker, 'bid'),
'bidVolume' => null,
'ask' => $this->safe_float($ticker, 'ask'),
'vwap' => null,
'askVolume' => null,
'open' => null,
'close' => $last,
'last' => $last,
'previousClose' => null,
'change' => null,
'percentage' => null,
'average' => null,
'baseVolume' => $this->safe_float($ticker, 'amount'),
'quoteVolume' => null,
'info' => $ticker,
);
}
public function parse_trade ($trade, $market = null) {
if (!$market)
$market = $this->markets_by_id[$trade['currencyPair']];
return array (
'id' => $trade['transactionId'],
'info' => $trade,
'timestamp' => $trade['timestamp'],
'datetime' => $this->iso8601 ($trade['timestamp']),
'symbol' => $market['symbol'],
'type' => null,
'side' => null,
'price' => $trade['price'],
'amount' => $trade['amount'],
);
}
public function fetch_trades ($symbol, $since = null, $limit = null, $params = array ()) {
$market = $this->market ($symbol);
$response = $this->publicGetTransactions (array_merge (array (
'currencyPair' => $market['id'],
'minutesIntoHistory' => 10,
), $params));
return $this->parse_trades($response['data'], $market, $since, $limit);
}
public function create_order ($symbol, $type, $side, $amount, $price = null, $params = array ()) {
$method = 'privatePost' . $this->capitalize ($side);
$order = array (
'currencyPair' => $this->market_id($symbol),
);
if ($type === 'market') {
if ($side === 'buy')
$order['total'] = $amount; // $amount in fiat
else
$order['amount'] = $amount; // $amount in fiat
$method .= 'Instant';
} else {
$order['amount'] = $amount; // $amount in crypto
$order['price'] = $price;
$method .= $this->capitalize ($type);
}
$response = $this->$method (array_merge ($order, $params));
return array (
'info' => $response,
'id' => (string) $response['data'],
);
}
public function cancel_order ($id, $symbol = null, $params = array ()) {
return $this->privatePostCancelOrder (array ( 'orderId' => $id ));
}
public function sign ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
$url = $this->urls['api'] . '/' . $path;
if ($api === 'public') {
if ($params)
$url .= '?' . $this->urlencode ($params);
} else {
$this->check_required_credentials();
$nonce = (string) $this->nonce ();
$auth = $nonce . $this->uid . $this->apiKey;
$signature = $this->hmac ($this->encode ($auth), $this->encode ($this->secret));
$body = $this->urlencode (array_merge (array (
'clientId' => $this->uid,
'nonce' => $nonce,
'publicKey' => $this->apiKey,
'signature' => strtoupper ($signature),
), $params));
$headers = array (
'Content-Type' => 'application/x-www-form-urlencoded',
);
}
return array ( 'url' => $url, 'method' => $method, 'body' => $body, 'headers' => $headers );
}
public function request ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
$response = $this->fetch2 ($path, $api, $method, $params, $headers, $body);
if (is_array ($response) && array_key_exists ('error', $response))
if ($response['error'])
throw new ExchangeError ($this->id . ' ' . $this->json ($response));
return $response;
}
}