-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfybse.js
173 lines (159 loc) · 5.9 KB
/
fybse.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
"use strict";
// ---------------------------------------------------------------------------
const Exchange = require ('./base/Exchange');
const { ExchangeError } = require ('./base/errors');
// ---------------------------------------------------------------------------
module.exports = class fybse extends Exchange {
describe () {
return this.deepExtend (super.describe (), {
'id': 'fybse',
'name': 'FYB-SE',
'countries': 'SE', // Sweden
'hasCORS': false,
'rateLimit': 1500,
'urls': {
'logo': 'https://user-images.githubusercontent.com/1294454/27766512-31019772-5edb-11e7-8241-2e675e6797f1.jpg',
'api': 'https://www.fybse.se/api/SEK',
'www': 'https://www.fybse.se',
'doc': 'http://docs.fyb.apiary.io',
},
'api': {
'public': {
'get': [
'ticker',
'tickerdetailed',
'orderbook',
'trades',
],
},
'private': {
'post': [
'test',
'getaccinfo',
'getpendingorders',
'getorderhistory',
'cancelpendingorder',
'placeorder',
'withdraw',
],
},
},
'markets': {
'BTC/SEK': { 'id': 'SEK', 'symbol': 'BTC/SEK', 'base': 'BTC', 'quote': 'SEK' },
},
});
}
async fetchBalance (params = {}) {
let balance = await this.privatePostGetaccinfo ();
let btc = parseFloat (balance['btcBal']);
let symbol = this.symbols[0];
let quote = this.markets[symbol]['quote'];
let lowercase = quote.toLowerCase () + 'Bal';
let fiat = parseFloat (balance[lowercase]);
let crypto = {
'free': btc,
'used': 0.0,
'total': btc,
};
let result = { 'BTC': crypto };
result[quote] = {
'free': fiat,
'used': 0.0,
'total': fiat,
};
result['info'] = balance;
return this.parseBalance (result);
}
async fetchOrderBook (symbol, params = {}) {
let orderbook = await this.publicGetOrderbook (params);
return this.parseOrderBook (orderbook);
}
async fetchTicker (symbol, params = {}) {
let ticker = await this.publicGetTickerdetailed (params);
let timestamp = this.milliseconds ();
let last = undefined;
let volume = undefined;
if ('last' in ticker)
last = parseFloat (ticker['last']);
if ('vol' in ticker)
volume = parseFloat (ticker['vol']);
return {
'symbol': symbol,
'timestamp': timestamp,
'datetime': this.iso8601 (timestamp),
'high': undefined,
'low': undefined,
'bid': parseFloat (ticker['bid']),
'ask': parseFloat (ticker['ask']),
'vwap': undefined,
'open': undefined,
'close': undefined,
'first': undefined,
'last': last,
'change': undefined,
'percentage': undefined,
'average': undefined,
'baseVolume': volume,
'quoteVolume': undefined,
'info': ticker,
};
}
parseTrade (trade, market) {
let timestamp = parseInt (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.publicGetTrades (params);
return this.parseTrades (response, market, since, limit);
}
async createOrder (symbol, type, side, amount, price = undefined, params = {}) {
let response = await this.privatePostPlaceorder (this.extend ({
'qty': amount,
'price': price,
'type': side[0].toUpperCase (),
}, params));
return {
'info': response,
'id': response['pending_oid'],
};
}
async cancelOrder (id, symbol = undefined, params = {}) {
return await this.privatePostCancelpendingorder ({ 'orderNo': id });
}
sign (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let url = this.urls['api'] + '/' + path;
if (api == 'public') {
url += '.json';
} else {
this.checkRequiredCredentials ();
let nonce = this.nonce ();
body = this.urlencode (this.extend ({ 'timestamp': nonce }, params));
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'key': this.apiKey,
'sig': this.hmac (this.encode (body), this.encode (this.secret), 'sha1'),
};
}
return { 'url': url, 'method': method, 'body': body, 'headers': headers };
}
async request (path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
let response = await this.fetch2 (path, api, method, params, headers, body);
if (api == 'private')
if ('error' in response)
if (response['error'])
throw new ExchangeError (this.id + ' ' + this.json (response));
return response;
}
}