-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoinfloor.js
190 lines (176 loc) · 7.01 KB
/
coinfloor.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
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
"use strict";
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
const { ExchangeError } = require ('./base/errors');
// ---------------------------------------------------------------------------
module.exports = class coinfloor extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'coinfloor',
'name': 'coinfloor',
'rateLimit': 1000,
'countries': 'UK',
'hasCORS': false,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/28246081-623fc164-6a1c-11e7-913f-bac0d5576c90.jpg',
'api': 'https://webapi.coinfloor.co.uk:8090/bist',
'www': 'https://www.coinfloor.co.uk',
'doc': [
'https://github.com/coinfloor/api',
'https://www.coinfloor.co.uk/api',
],
},
'requiredCredentials': {
'apiKey': true,
'secret': true,
'uid': true,
},
'api': {
'public': {
'get': [
'{id}/ticker/',
'{id}/order_book/',
'{id}/transactions/',
],
},
'private': {
'post': [
'{id}/balance/',
'{id}/user_transactions/',
'{id}/open_orders/',
'{id}/cancel_order/',
'{id}/buy/',
'{id}/sell/',
'{id}/buy_market/',
'{id}/sell_market/',
'{id}/estimate_sell_market/',
'{id}/estimate_buy_market/',
],
},
},
'markets': {
'BTC/GBP': { 'id': 'XBT/GBP', 'symbol': 'BTC/GBP', 'base': 'BTC', 'quote': 'GBP' },
'BTC/EUR': { 'id': 'XBT/EUR', 'symbol': 'BTC/EUR', 'base': 'BTC', 'quote': 'EUR' },
'BTC/USD': { 'id': 'XBT/USD', 'symbol': 'BTC/USD', 'base': 'BTC', 'quote': 'USD' },
'BTC/PLN': { 'id': 'XBT/PLN', 'symbol': 'BTC/PLN', 'base': 'BTC', 'quote': 'PLN' },
'BCH/GBP': { 'id': 'BCH/GBP', 'symbol': 'BCH/GBP', 'base': 'BCH', 'quote': 'GBP' },
},
});
}
fetchBalance (params = {}) {
let symbol = undefined;
if ('symbol' in params)
symbol = params['symbol'];
if ('id' in params)
symbol = params['id'];
if (!symbol)
throw new ExchangeError (this.id + ' fetchBalance requires a symbol param');
// todo parse balance
return this.privatePostIdBalance ({
'id': this.marketId (symbol),
});
}
async fetchOrderBook (symbol, params = {}) {
let orderbook = await this.publicGetIdOrderBook (this.extend ({
'id': this.marketId (symbol),
}, params));
return this.parseOrderBook (orderbook);
}
parseTicker (ticker, market = undefined) {
// rewrite to get the timestamp from HTTP headers
let timestamp = this.milliseconds ();
let symbol = undefined;
if (market)
symbol = market['symbol'];
let vwap = this.safeFloat (ticker, 'vwap');
let baseVolume = parseFloat (ticker['volume']);
let quoteVolume = undefined;
if (typeof vwap !== 'undefined') {
quoteVolume = baseVolume * vwap;
}
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': parseFloat (ticker['high']),
'low': parseFloat (ticker['low']),
'bid': parseFloat (ticker['bid']),
'ask': parseFloat (ticker['ask']),
'vwap': vwap,
'open': undefined,
'close': undefined,
'first': undefined,
'last': parseFloat (ticker['last']),
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': baseVolume,
'quoteVolume': quoteVolume,
'info': ticker,
};
}
async fetchTicker (symbol, params = {}) {
let market = this.market (symbol);
let ticker = await this.publicGetIdTicker (this.extend ({
'id': market['id'],
}, params));
return this.parseTicker (ticker, market);
}
parseTrade (trade, market) {
let timestamp = trade['date'] * 1000;
return {
'info': trade,
'id': trade['tid'].toString (),
'order': undefined,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'symbol': market['symbol'],
'type': undefined,
'side': undefined,
'price': parseFloat (trade['price']),
'amount': parseFloat (trade['amount']),
};
}
async fetchTrades (symbol, since = undefined, limit = undefined, params = {}) {
let market = this.market (symbol);
let response = await this.publicGetIdTransactions (this.extend ({
'id': market['id'],
}, params));
return this.parseTrades (response, market, since, limit);
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
let order = { 'id': this.marketId (symbol) };
let method = 'privatePostId' + this.capitalize (side);
if (type == 'market') {
order['quantity'] = amount;
method += 'Market';
} else {
order['price'] = price;
order['amount'] = amount;
}
return this[method] (this.extend (order, params));
}
async cancelOrder (id, symbol = undefined, params = {}) {
return await this.privatePostIdCancelOrder ({ 'id': id });
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
// curl -k -u '[User ID]/[API key]:[Passphrase]' https://webapi.coinfloor.co.uk:8090/bist/XBT/GBP/balance/
let url = this.urls['api'] + '/' + this.implodeParams (path, params);
let query = this.omit (params, this.extractParams (path));
if (api == 'public') {
if (Object.keys (query).length)
url += '?' + this.urlencode (query);
} else {
this.checkRequiredCredentials ();
let nonce = this.nonce ();
body = this.urlencode (this.extend ({ 'nonce': nonce }, query));
let auth = this.uid + '/' + this.apiKey + ':' + this.password;
let signature = this.stringToBase64 (auth);
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + signature,
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
}