-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinspot.php
161 lines (150 loc) · 6.38 KB
/
coinspot.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
<?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
class coinspot extends Exchange {
public function describe () {
return array_replace_recursive (parent::describe (), array (
'id' => 'coinspot',
'name' => 'CoinSpot',
'countries' => 'AU', // Australia
'rateLimit' => 1000,
'has' => array (
'CORS' => false,
'createMarketOrder' => false,
),
'urls' => array (
'logo' => 'https://user-images.githubusercontent.com/1294454/28208429-3cacdf9a-6896-11e7-854e-4c79a772a30f.jpg',
'api' => array (
'public' => 'https://www.coinspot.com.au/pubapi',
'private' => 'https://www.coinspot.com.au/api',
),
'www' => 'https://www.coinspot.com.au',
'doc' => 'https://www.coinspot.com.au/api',
),
'api' => array (
'public' => array (
'get' => array (
'latest',
),
),
'private' => array (
'post' => array (
'orders',
'orders/history',
'my/coin/deposit',
'my/coin/send',
'quote/buy',
'quote/sell',
'my/balances',
'my/orders',
'my/buy',
'my/sell',
'my/buy/cancel',
'my/sell/cancel',
),
),
),
'markets' => array (
'BTC/AUD' => array ( 'id' => 'BTC', 'symbol' => 'BTC/AUD', 'base' => 'BTC', 'quote' => 'AUD' ),
'LTC/AUD' => array ( 'id' => 'LTC', 'symbol' => 'LTC/AUD', 'base' => 'LTC', 'quote' => 'AUD' ),
'DOGE/AUD' => array ( 'id' => 'DOGE', 'symbol' => 'DOGE/AUD', 'base' => 'DOGE', 'quote' => 'AUD' ),
),
));
}
public function fetch_balance ($params = array ()) {
$response = $this->privatePostMyBalances ();
$result = array ( 'info' => $response );
if (is_array ($response) && array_key_exists ('balance', $response)) {
$balances = $response['balance'];
$currencies = is_array ($balances) ? array_keys ($balances) : array ();
for ($c = 0; $c < count ($currencies); $c++) {
$currency = $currencies[$c];
$uppercase = strtoupper ($currency);
$account = array (
'free' => $balances[$currency],
'used' => 0.0,
'total' => $balances[$currency],
);
if ($uppercase === 'DRK')
$uppercase = 'DASH';
$result[$uppercase] = $account;
}
}
return $this->parse_balance($result);
}
public function fetch_order_book ($symbol, $params = array ()) {
$market = $this->market ($symbol);
$orderbook = $this->privatePostOrders (array_merge (array (
'cointype' => $market['id'],
), $params));
$result = $this->parse_order_book($orderbook, null, 'buyorders', 'sellorders', 'rate', 'amount');
$result['bids'] = $this->sort_by($result['bids'], 0, true);
$result['asks'] = $this->sort_by($result['asks'], 0);
return $result;
}
public function fetch_ticker ($symbol, $params = array ()) {
$response = $this->publicGetLatest ($params);
$id = $this->market_id($symbol);
$id = strtolower ($id);
$ticker = $response['prices'][$id];
$timestamp = $this->milliseconds ();
return array (
'symbol' => $symbol,
'timestamp' => $timestamp,
'datetime' => $this->iso8601 ($timestamp),
'high' => null,
'low' => null,
'bid' => floatval ($ticker['bid']),
'ask' => floatval ($ticker['ask']),
'vwap' => null,
'open' => null,
'close' => null,
'first' => null,
'last' => floatval ($ticker['last']),
'change' => null,
'percentage' => null,
'average' => null,
'baseVolume' => null,
'quoteVolume' => null,
'info' => $ticker,
);
}
public function fetch_trades ($symbol, $since = null, $limit = null, $params = array ()) {
return $this->privatePostOrdersHistory (array_merge (array (
'cointype' => $this->market_id($symbol),
), $params));
}
public function create_order ($market, $type, $side, $amount, $price = null, $params = array ()) {
$method = 'privatePostMy' . $this->capitalize ($side);
if ($type == 'market')
throw new ExchangeError ($this->id . ' allows limit orders only');
$order = array (
'cointype' => $this->market_id($market),
'amount' => $amount,
'rate' => $price,
);
return $this->$method (array_merge ($order, $params));
}
public function cancel_order ($id, $symbol = null, $params = array ()) {
throw new ExchangeError ($this->id . ' cancelOrder () is not fully implemented yet');
// $method = 'privatePostMyBuy';
// return $this->$method (array ( 'id' => $id ));
}
public function sign ($path, $api = 'public', $method = 'GET', $params = array (), $headers = null, $body = null) {
if (!$this->apiKey)
throw new AuthenticationError ($this->id . ' requires apiKey for all requests');
$url = $this->urls['api'][$api] . '/' . $path;
if ($api === 'private') {
$this->check_required_credentials();
$nonce = $this->nonce ();
$body = $this->json (array_merge (array ( 'nonce' => $nonce ), $params));
$headers = array (
'Content-Type' => 'application/json',
'key' => $this->apiKey,
'sign' => $this->hmac ($this->encode ($body), $this->encode ($this->secret), 'sha512'),
);
}
return array ( 'url' => $url, 'method' => $method, 'body' => $body, 'headers' => $headers );
}
}