172 lines
6.6 KiB
JavaScript
172 lines
6.6 KiB
JavaScript
'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',
|
|
'referral': 'https://www.coinspot.com.au/register?code=PJURCU',
|
|
},
|
|
'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', 'baseId': 'btc', 'quoteId': 'aud' },
|
|
'LTC/AUD': { 'id': 'ltc', 'symbol': 'LTC/AUD', 'base': 'LTC', 'quote': 'AUD', 'baseId': 'ltc', 'quoteId': 'aud' },
|
|
'DOGE/AUD': { 'id': 'doge', 'symbol': 'DOGE/AUD', 'base': 'DOGE', 'quote': 'AUD', 'baseId': 'doge', 'quoteId': 'aud' },
|
|
},
|
|
'commonCurrencies': {
|
|
'DRK': 'DASH',
|
|
},
|
|
});
|
|
}
|
|
|
|
async fetchBalance (params = {}) {
|
|
await this.loadMarkets ();
|
|
const response = await this.privatePostMyBalances (params);
|
|
const result = { 'info': response };
|
|
const balances = this.safeValue (response, 'balance', {});
|
|
const currencyIds = Object.keys (balances);
|
|
for (let i = 0; i < currencyIds.length; i++) {
|
|
const currencyId = currencyIds[i];
|
|
const code = this.safeCurrencyCode (currencyId);
|
|
const account = this.account ();
|
|
account['total'] = this.safeFloat (balances, currencyId);
|
|
result[code] = account;
|
|
}
|
|
return this.parseBalance (result);
|
|
}
|
|
|
|
async fetchOrderBook (symbol, limit = undefined, params = {}) {
|
|
await this.loadMarkets ();
|
|
const market = this.market (symbol);
|
|
const request = {
|
|
'cointype': market['id'],
|
|
};
|
|
const orderbook = await this.privatePostOrders (this.extend (request, params));
|
|
return this.parseOrderBook (orderbook, undefined, 'buyorders', 'sellorders', 'rate', 'amount');
|
|
}
|
|
|
|
async fetchTicker (symbol, params = {}) {
|
|
await this.loadMarkets ();
|
|
const response = await this.publicGetLatest (params);
|
|
let id = this.marketId (symbol);
|
|
id = id.toLowerCase ();
|
|
const ticker = response['prices'][id];
|
|
const timestamp = this.milliseconds ();
|
|
const 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,
|
|
};
|
|
}
|
|
|
|
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
|
|
await this.loadMarkets ();
|
|
const market = this.market (symbol);
|
|
const request = {
|
|
'cointype': market['id'],
|
|
};
|
|
const response = await this.privatePostOrdersHistory (this.extend (request, params));
|
|
const trades = this.safeValue (response, 'orders', []);
|
|
return this.parseTrades (trades, market, since, limit);
|
|
}
|
|
|
|
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
|
|
await this.loadMarkets ();
|
|
const method = 'privatePostMy' + this.capitalize (side);
|
|
if (type === 'market') {
|
|
throw new ExchangeError (this.id + ' allows limit orders only');
|
|
}
|
|
const request = {
|
|
'cointype': this.marketId (symbol),
|
|
'amount': amount,
|
|
'rate': price,
|
|
};
|
|
return await this[method] (this.extend (request, 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');
|
|
}
|
|
const url = this.urls['api'][api] + '/' + path;
|
|
if (api === 'private') {
|
|
this.checkRequiredCredentials ();
|
|
const 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 };
|
|
}
|
|
};
|