Skip to content

Commit 4d59bbd

Browse files
authored
Merge pull request #1 from bitfinexcom/master
update api node
2 parents bf00a35 + 1c484b1 commit 4d59bbd

File tree

22 files changed

+1781
-192
lines changed

22 files changed

+1781
-192
lines changed

doc/rest2.md

Lines changed: 191 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ Communicates with v2 of the Bitfinex HTTP API
77

88
* [RESTv2](#RESTv2)
99
* [new RESTv2(opts)](#new_RESTv2_new)
10+
* ~~[._makePublicLegacyRequest(method, cb)](#RESTv2+_makePublicLegacyRequest) ⇒ <code>Promise</code>~~
11+
* [._makeAuthLegacyRequest(method, params, cb)](#RESTv2+_makeAuthLegacyRequest) ⇒ <code>Promise</code>
12+
* [.status(cb)](#RESTv2+status) ⇒ <code>Promise</code>
1013
* [.ticker(symbol, cb)](#RESTv2+ticker) ⇒ <code>Promise</code>
1114
* [.tickers(symbols, cb)](#RESTv2+tickers) ⇒ <code>Promise</code>
1215
* [.stats(key, context, cb)](#RESTv2+stats) ⇒ <code>Promise</code>
1316
* [.candles(opts, cb)](#RESTv2+candles) ⇒ <code>Promise</code>
1417
* [.alertList(type, cb)](#RESTv2+alertList) ⇒ <code>Promise</code>
1518
* [.alertSet(type, symbol, price)](#RESTv2+alertSet) ⇒ <code>Promise</code>
1619
* [.alertDelete(symbol, price)](#RESTv2+alertDelete) ⇒ <code>Promise</code>
17-
* [.trades(symbol, start, end, limit, cb)](#RESTv2+trades) ⇒ <code>Promise</code>
20+
* [.trades(symbol, start, end, limit, sort, cb)](#RESTv2+trades) ⇒ <code>Promise</code>
21+
* [.accountTrades(symbol, start, end, limit, sort, cb)](#RESTv2+accountTrades) ⇒ <code>Promise</code>
1822
* [.wallets(cb)](#RESTv2+wallets) ⇒ <code>Promise</code>
23+
* [.userInfo(cb)](#RESTv2+userInfo) ⇒ <code>Promise</code>
24+
* [.ledgers(symbol, start, end, limit, cb)](#RESTv2+ledgers) ⇒ <code>Promise</code>
1925
* [.activeOrders(cb)](#RESTv2+activeOrders) ⇒ <code>Promise</code>
26+
* [.movements(ccy, start, end, limit, cb)](#RESTv2+movements) ⇒ <code>Promise</code>
27+
* [.ledgers(ccy, start, end, limit, cb)](#RESTv2+ledgers) ⇒ <code>Promise</code>
2028
* [.orderHistory(symbol, start, end, limit, cb)](#RESTv2+orderHistory) ⇒ <code>Promise</code>
2129
* [.orderTrades(symbol, start, end, limit, orderID, cb)](#RESTv2+orderTrades) ⇒ <code>Promise</code>
2230
* [.positions(cb)](#RESTv2+positions) ⇒ <code>Promise</code>
@@ -42,6 +50,11 @@ Communicates with v2 of the Bitfinex HTTP API
4250
* ~~[.keyPermissions(cb)](#RESTv2+keyPermissions) ⇒ <code>Promise</code>~~
4351
* ~~[.balances(cb)](#RESTv2+balances) ⇒ <code>Promise</code>~~
4452
* ~~[.claimPosition(params, cb)](#RESTv2+claimPosition) ⇒ <code>Promise</code>~~
53+
* ~~[.closePosition(params, cb)](#RESTv2+closePosition) ⇒ <code>Promise</code>~~
54+
* [.updateSettings(settings, cb)](#RESTv2+updateSettings) ⇒ <code>Promise</code>
55+
* [.deleteSettings(keys, cb)](#RESTv2+deleteSettings) ⇒ <code>Promise</code>
56+
* [.getSettings(keys, cb)](#RESTv2+getSettings) ⇒ <code>Promise</code>
57+
* [.exchangeRate(ccy1, ccy2)](#RESTv2+exchangeRate) ⇒ <code>Promise</code>
4558

4659
<a name="new_RESTv2_new"></a>
4760

@@ -54,10 +67,52 @@ Instantiate a new REST v2 transport.
5467
| opts | <code>Object</code> | |
5568
| opts.apiKey | <code>string</code> | |
5669
| opts.apiSecret | <code>string</code> | |
70+
| opts.authToken | <code>string</code> | optional auth option |
5771
| opts.url | <code>string</code> | endpoint URL |
5872
| opts.transform | <code>boolean</code> | default false |
5973
| opts.agent | <code>Object</code> | optional node agent for connection (proxy) |
6074

75+
<a name="RESTv2+_makePublicLegacyRequest"></a>
76+
77+
### ~~resTv2._makePublicLegacyRequest(method, cb) ⇒ <code>Promise</code>~~
78+
***Deprecated***
79+
80+
Legacy REST1 public method wrapper, that also provides legacy cb
81+
support. Oh my!
82+
83+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
84+
**Returns**: <code>Promise</code> - p - use this
85+
86+
| Param | Type | Description |
87+
| --- | --- | --- |
88+
| method | <code>string</code> | REST1 method name |
89+
| cb | <code>Method</code> | optional legacy cb |
90+
91+
<a name="RESTv2+_makeAuthLegacyRequest"></a>
92+
93+
### resTv2._makeAuthLegacyRequest(method, params, cb) ⇒ <code>Promise</code>
94+
See _makePublicLegacyRequest
95+
96+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
97+
**Returns**: <code>Promise</code> - p
98+
99+
| Param | Type |
100+
| --- | --- |
101+
| method | <code>string</code> |
102+
| params | <code>Object</code> |
103+
| cb | <code>Method</code> |
104+
105+
<a name="RESTv2+status"></a>
106+
107+
### resTv2.status(cb) ⇒ <code>Promise</code>
108+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
109+
**Returns**: <code>Promise</code> - p
110+
**See**: https://docs.bitfinex.com/v2/reference#rest-public-platform-status
111+
112+
| Param | Type |
113+
| --- | --- |
114+
| cb | <code>Method</code> |
115+
61116
<a name="RESTv2+ticker"></a>
62117

63118
### resTv2.ticker(symbol, cb) ⇒ <code>Promise</code>
@@ -149,18 +204,46 @@ Instantiate a new REST v2 transport.
149204

150205
<a name="RESTv2+trades"></a>
151206

152-
### resTv2.trades(symbol, start, end, limit, cb) ⇒ <code>Promise</code>
207+
### resTv2.trades(symbol, start, end, limit, sort, cb) ⇒ <code>Promise</code>
208+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
209+
**Returns**: <code>Promise</code> - p
210+
**See**: https://docs.bitfinex.com/v2/reference#rest-public-trades
211+
212+
| Param | Type | Default | Description |
213+
| --- | --- | --- | --- |
214+
| symbol | <code>string</code> | <code>&quot;tBTCUSD&quot;</code> | |
215+
| start | <code>number</code> | <code></code> | |
216+
| end | <code>number</code> | <code></code> | |
217+
| limit | <code>number</code> | <code></code> | |
218+
| sort | <code>number</code> | <code></code> | if 1, sorts results oldest first |
219+
| cb | <code>Method</code> | | |
220+
221+
<a name="RESTv2+accountTrades"></a>
222+
223+
### resTv2.accountTrades(symbol, start, end, limit, sort, cb) ⇒ <code>Promise</code>
153224
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
154225
**Returns**: <code>Promise</code> - p
155226
**See**: https://docs.bitfinex.com/v2/reference#rest-auth-trades-hist
156227

157-
| Param | Type | Default |
158-
| --- | --- | --- |
159-
| symbol | <code>string</code> | <code>&quot;tBTCUSD&quot;</code> |
160-
| start | <code>number</code> | <code></code> |
161-
| end | <code>number</code> | <code></code> |
162-
| limit | <code>number</code> | <code></code> |
163-
| cb | <code>Method</code> | |
228+
| Param | Type | Default | Description |
229+
| --- | --- | --- | --- |
230+
| symbol | <code>string</code> | | optional, omit/leave empty for all |
231+
| start | <code>number</code> | <code></code> | |
232+
| end | <code>number</code> | <code></code> | |
233+
| limit | <code>number</code> | <code></code> | |
234+
| sort | <code>number</code> | <code></code> | if 1, sorts results oldest first |
235+
| cb | <code>Method</code> | | |
236+
237+
<a name="RESTv2+userInfo"></a>
238+
239+
### resTv2.userInfo(cb) ⇒ <code>Promise</code>
240+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
241+
**Returns**: <code>Promise</code> - p
242+
**See**: https://docs.bitfinex.com/v2/reference#rest-auth-user
243+
244+
| Param | Type |
245+
| --- | --- |
246+
| cb | <code>Method</code> |
164247

165248
<a name="RESTv2+wallets"></a>
166249

@@ -184,20 +267,50 @@ Instantiate a new REST v2 transport.
184267
| --- | --- |
185268
| cb | <code>Method</code> |
186269

270+
<a name="RESTv2+movements"></a>
271+
272+
### resTv2.movements(ccy, start, end, limit, cb) ⇒ <code>Promise</code>
273+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
274+
**Returns**: <code>Promise</code> - p
275+
**See**: https://docs.bitfinex.com/v2/reference#movements
276+
277+
| Param | Type | Default | Description |
278+
| --- | --- | --- | --- |
279+
| ccy | <code>string</code> | | i.e. ETH |
280+
| start | <code>number</code> | <code></code> | |
281+
| end | <code>number</code> | | |
282+
| limit | <code>number</code> | <code>25</code> | default 25 |
283+
| cb | <code>Method</code> | | |
284+
285+
<a name="RESTv2+ledgers"></a>
286+
287+
### resTv2.ledgers(ccy, start, end, limit, cb) ⇒ <code>Promise</code>
288+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
289+
**Returns**: <code>Promise</code> - p
290+
**See**: https://docs.bitfinex.com/v2/reference#ledgers
291+
292+
| Param | Type | Default | Description |
293+
| --- | --- | --- | --- |
294+
| ccy | <code>string</code> | | i.e. ETH |
295+
| start | <code>number</code> | <code></code> | |
296+
| end | <code>number</code> | | |
297+
| limit | <code>number</code> | <code>25</code> | default 25 |
298+
| cb | <code>Method</code> | | |
299+
187300
<a name="RESTv2+orderHistory"></a>
188301

189302
### resTv2.orderHistory(symbol, start, end, limit, cb) ⇒ <code>Promise</code>
190303
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
191304
**Returns**: <code>Promise</code> - p
192305
**See**: https://docs.bitfinex.com/v2/reference#orders-history
193306

194-
| Param | Type | Default |
195-
| --- | --- | --- |
196-
| symbol | <code>string</code> | <code>&quot;tBTCUSD&quot;</code> |
197-
| start | <code>number</code> | <code></code> |
198-
| end | <code>number</code> | <code></code> |
199-
| limit | <code>number</code> | <code></code> |
200-
| cb | <code>Method</code> | |
307+
| Param | Type | Default | Description |
308+
| --- | --- | --- | --- |
309+
| symbol | <code>string</code> | | optional, omit/leave empty for all |
310+
| start | <code>number</code> | <code></code> | |
311+
| end | <code>number</code> | <code></code> | |
312+
| limit | <code>number</code> | <code></code> | |
313+
| cb | <code>Method</code> | | |
201314

202315
<a name="RESTv2+orderTrades"></a>
203316

@@ -383,9 +496,9 @@ Get a list of valid symbol names
383496
**Returns**: <code>Promise</code> - p
384497
**See**: https://docs.bitfinex.com/v1/reference#rest-public-symbols
385498

386-
| Param | Type |
387-
| --- | --- |
388-
| cb | <code>Method</code> |
499+
| Param | Type | Description |
500+
| --- | --- | --- |
501+
| cb | <code>Method</code> | legacy callback |
389502

390503
<a name="RESTv2+symbolDetails"></a>
391504

@@ -571,3 +684,62 @@ Request your wallet balances
571684
| params.amount | <code>number</code> |
572685
| cb | <code>Method</code> |
573686

687+
<a name="RESTv2+closePosition"></a>
688+
689+
### ~~resTv2.closePosition(params, cb) ⇒ <code>Promise</code>~~
690+
***Deprecated***
691+
692+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
693+
**Returns**: <code>Promise</code> - p
694+
**See**: https://docs.bitfinex.com/v1/reference#rest-auth-close-position
695+
696+
| Param | Type |
697+
| --- | --- |
698+
| params | <code>Object</code> |
699+
| params.position_id | <code>number</code> |
700+
| cb | <code>Method</code> |
701+
702+
<a name="RESTv2+updateSettings"></a>
703+
704+
### resTv2.updateSettings(settings, cb) ⇒ <code>Promise</code>
705+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
706+
**Returns**: <code>Promise</code> - p
707+
708+
| Param | Type | Description |
709+
| --- | --- | --- |
710+
| settings | <code>Object</code> | key:value map |
711+
| cb | <code>Method</code> | |
712+
713+
<a name="RESTv2+deleteSettings"></a>
714+
715+
### resTv2.deleteSettings(keys, cb) ⇒ <code>Promise</code>
716+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
717+
**Returns**: <code>Promise</code> - p
718+
719+
| Param | Type |
720+
| --- | --- |
721+
| keys | <code>Array.&lt;string&gt;</code> |
722+
| cb | <code>Method</code> |
723+
724+
<a name="RESTv2+getSettings"></a>
725+
726+
### resTv2.getSettings(keys, cb) ⇒ <code>Promise</code>
727+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
728+
**Returns**: <code>Promise</code> - p
729+
730+
| Param | Type |
731+
| --- | --- |
732+
| keys | <code>Array.&lt;string&gt;</code> |
733+
| cb | <code>Method</code> |
734+
735+
<a name="RESTv2+exchangeRate"></a>
736+
737+
### resTv2.exchangeRate(ccy1, ccy2) ⇒ <code>Promise</code>
738+
**Kind**: instance method of <code>[RESTv2](#RESTv2)</code>
739+
**Returns**: <code>Promise</code> - p - resolves to currenct exchange rate
740+
741+
| Param | Type | Description |
742+
| --- | --- | --- |
743+
| ccy1 | <code>string</code> | i.e. BTC |
744+
| ccy2 | <code>string</code> | i.e. USD |
745+

examples/bfx.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ const bfx = new BFX({
2424
})
2525

2626
module.exports = bfx
27+
module.exports.args = {
28+
apiKey: API_KEY,
29+
apiSecret: API_SECRET,
30+
wsURL: WS_URL,
31+
restURL: REST_URL,
32+
agent
33+
}

examples/ws2/notify_ui.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ ws.on('open', () => {
1717

1818
ws.once('auth', () => {
1919
debug('authenticated')
20-
debug('generating notification')
21-
ws.notifyUI('success', 'This is a test notification sent via the WSv2 API')
20+
21+
ws.notifyUI({
22+
type: 'success',
23+
message: 'This is a test notification sent via the WSv2 API'
24+
})
25+
2226
debug('notification sent')
2327

2428
ws.close()

examples/ws2_manager.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict'
2+
3+
process.env.DEBUG = 'bfx:examples:*'
4+
5+
const _flatten = require('lodash/flatten')
6+
const debug = require('debug')('bfx:examples:ws2-manager')
7+
const bfx = require('./bfx')
8+
9+
const Manager = require('../lib/ws2_manager')
10+
const rest = bfx.rest(2, { transform: true })
11+
12+
debug('fetching symbol details...')
13+
14+
rest.symbolDetails().then(details => {
15+
const symbols = details.map(d => `t${d.pair.toUpperCase()}`)
16+
const timeFrames = ['1m', '5m', '30m', '1h', '6h']
17+
const keys = _flatten(symbols.map(s => {
18+
return timeFrames.map(tf => `trade:${tf}:${s}`)
19+
}))
20+
21+
const m = new Manager({
22+
url: bfx.args.wsURL,
23+
...bfx.args
24+
})
25+
26+
m.on('error', (err) => {
27+
debug('error: %s', err)
28+
})
29+
30+
m.once('open', () => {
31+
debug('open')
32+
33+
keys.forEach(key => {
34+
m.subscribeCandles(key)
35+
m.onCandle({ key }, (candles) => {
36+
debug('recv %d candles on channel %s', candles.length, key)
37+
})
38+
})
39+
40+
symbols.forEach(symbol => {
41+
m.subscribeTrades(symbol)
42+
m.onTrades({ symbol }, (trades) => {
43+
debug('recv %d trades on channel %s', trades.length, symbol)
44+
})
45+
})
46+
47+
symbols.forEach(symbol => {
48+
m.subscribeTicker(symbol)
49+
m.onTicker({ symbol }, (ticker) => {
50+
debug('recv ticker on channel %s: %j', symbol, ticker)
51+
})
52+
})
53+
54+
symbols.forEach(symbol => {
55+
m.subscribeOrderBook(symbol)
56+
m.onOrderBook({ symbol }, (update) => {
57+
debug('recv book update on channel %s: %j', symbol, update)
58+
})
59+
})
60+
61+
setInterval(() => {
62+
debug('num keys: %d', keys.length)
63+
debug('num sockets: %d', m.getNumSockets())
64+
debug('socket info: %j', m.getSocketInfo())
65+
}, 5000)
66+
})
67+
68+
m.openSocket()
69+
})

0 commit comments

Comments
 (0)