-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinspot.js
162 lines (151 loc) · 6.03 KB
/
coinspot.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
'use strict';
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
const { ExchangeError, AuthenticationError, NotSupported } = require ('./base/errors');
// ---------------------------------------------------------------------------
module.exports = class coinspot extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'coinspot',
'name': 'CoinSpot',
'countries': [ 'AU' ], // Australia
'rateLimit': 1000,
'has': {
'CORS': false,
'createMarketOrder': false,
},
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/28208429-3cacdf9a-6896-11e7-854e-4c79a772a30f.jpg',
'api': {
'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': {
'public': {
'get': [
'latest',
],
},
'private': {
'post': [
'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': {
'BTC/AUD': { 'id': 'BTC', 'symbol': 'BTC/AUD', 'base': 'BTC', 'quote': 'AUD' },
'LTC/AUD': { 'id': 'LTC', 'symbol': 'LTC/AUD', 'base': 'LTC', 'quote': 'AUD' },
'DOGE/AUD': { 'id': 'DOGE', 'symbol': 'DOGE/AUD', 'base': 'DOGE', 'quote': 'AUD' },
},
});
}
async fetchBalance (params = {}) {
let response = await this.privatePostMyBalances ();
let result = { 'info': response };
if ('balance' in response) {
let balances = response['balance'];
let currencies = Object.keys (balances);
for (let c = 0; c < currencies.length; c++) {
let currency = currencies[c];
let uppercase = currency.toUpperCase ();
let account = {
'free': balances[currency],
'used': 0.0,
'total': balances[currency],
};
if (uppercase === 'DRK')
uppercase = 'DASH';
result[uppercase] = account;
}
}
return this.parseBalance (result);
}
async fetchOrderBook (symbol, limit = undefined, params = {}) {
let market = this.market (symbol);
let orderbook = await this.privatePostOrders (this.extend ({
'cointype': market['id'],
}, params));
return this.parseOrderBook (orderbook, undefined, 'buyorders', 'sellorders', 'rate', 'amount');
}
async fetchTicker (symbol, params = {}) {
let response = await this.publicGetLatest (params);
let id = this.marketId (symbol);
id = id.toLowerCase ();
let ticker = response['prices'][id];
let timestamp = this.milliseconds ();
let last = this.safeFloat (ticker, 'last');
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': undefined,
'low': undefined,
'bid': this.safeFloat (ticker, 'bid'),
'bidVolume': undefined,
'ask': this.safeFloat (ticker, 'ask'),
'askVolume': undefined,
'vwap': undefined,
'open': undefined,
'close': last,
'last': last,
'previousClose': undefined,
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': undefined,
'quoteVolume': undefined,
'info': ticker,
};
}
fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
return this.privatePostOrdersHistory (this.extend ({
'cointype': this.marketId (symbol),
}, params));
}
createOrder (symbol, type, side, amount, price = undefined, params = {}) {
let method = 'privatePostMy' + this.capitalize (side);
if (type === 'market')
throw new ExchangeError (this.id + ' allows limit orders only');
let order = {
'cointype': this.marketId (symbol),
'amount': amount,
'rate': price,
};
return this[method] (this.extend (order, params));
}
async cancelOrder (id, symbol = undefined, params = {}) {
throw new NotSupported (this.id + ' cancelOrder () is not fully implemented yet');
// let method = 'privatePostMyBuy';
// return await this[method] ({ 'id': id });
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
if (!this.apiKey)
throw new AuthenticationError (this.id + ' requires apiKey for all requests');
let url = this.urls['api'][api] + '/' + path;
if (api === 'private') {
this.checkRequiredCredentials ();
let nonce = this.nonce ();
body = this.json (this.extend ({ 'nonce': nonce }, params));
headers = {
'Content-Type': 'application/json',
'key': this.apiKey,
'sign': this.hmac (this.encode (body), this.encode (this.secret), 'sha512'),
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
};