-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from yagop/master
Refactorized WebSocket API.
- Loading branch information
Showing
10 changed files
with
834 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
.idea | ||
/test/test_api_keys.json | ||
/build | ||
/build | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
<a name="BitfinexWS"></a> | ||
## BitfinexWS | ||
**Kind**: global class | ||
|
||
* [BitfinexWS](#BitfinexWS) | ||
* [new BitfinexWS(APIKey, APISecret)](#new_BitfinexWS_new) | ||
* _instance_ | ||
* [.subscribeOrderBook([pair], [precision], [length])](#BitfinexWS+subscribeOrderBook) | ||
* [.subscribeTrades([pair])](#BitfinexWS+subscribeTrades) | ||
* [.subscribeTicker([pair])](#BitfinexWS+subscribeTicker) | ||
* [.unsubscribe(chanId)](#BitfinexWS+unsubscribe) | ||
* [.auth()](#BitfinexWS+auth) | ||
* ["message"](#BitfinexWS+event_message) | ||
* ["open"](#BitfinexWS+event_open) | ||
* ["error"](#BitfinexWS+event_error) | ||
* ["close"](#BitfinexWS+event_close) | ||
* ["subscribed"](#BitfinexWS+event_subscribed) | ||
* ["auth"](#BitfinexWS+event_auth) | ||
* ["ps"](#BitfinexWS+event_ps) | ||
* ["pn"](#BitfinexWS+event_pn) | ||
* ["pu"](#BitfinexWS+event_pu) | ||
* ["pc"](#BitfinexWS+event_pc) | ||
* ["ws"](#BitfinexWS+event_ws) | ||
* ["ws"](#BitfinexWS+event_ws) | ||
* ["os"](#BitfinexWS+event_os) | ||
* ["on"](#BitfinexWS+event_on) | ||
* ["ou"](#BitfinexWS+event_ou) | ||
* ["oc"](#BitfinexWS+event_oc) | ||
* ["te"](#BitfinexWS+event_te) | ||
* ["tu"](#BitfinexWS+event_tu) | ||
* ["ticker"](#BitfinexWS+event_ticker) | ||
* ["trade"](#BitfinexWS+event_trade) | ||
* ["orderbook"](#BitfinexWS+event_orderbook) | ||
* _static_ | ||
* [.WebSocketURI](#BitfinexWS.WebSocketURI) : <code>String</code> | ||
|
||
<a name="new_BitfinexWS_new"></a> | ||
### new BitfinexWS(APIKey, APISecret) | ||
Handles communitaction with Bitfinex WebSocket API. | ||
|
||
|
||
| Param | Type | | ||
| --- | --- | | ||
| APIKey | <code>sting</code> | | ||
| APISecret | <code>string</code> | | ||
|
||
<a name="BitfinexWS+subscribeOrderBook"></a> | ||
### bitfinexWS.subscribeOrderBook([pair], [precision], [length]) | ||
Subscribe to Order book updates. Snapshot will be sended as multiple updates. | ||
Event will be emited as `PAIRNAME_book`. | ||
|
||
**Kind**: instance method of <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#order-books | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| [pair] | <code>string</code> | BTCUSD, LTCUSD or LTCBTC. Default BTCUSD | | ||
| [precision] | <code>string</code> | Level of price aggregation (P0, P1, P2, P3). The default is P0. | | ||
| [length] | <code>string</code> | Number of price points. 25 (default) or 100. | | ||
|
||
<a name="BitfinexWS+subscribeTrades"></a> | ||
### bitfinexWS.subscribeTrades([pair]) | ||
Subscribe to trades. Snapshot will be sended as multiple updates. | ||
Event will be emited as `PAIRNAME_trades`. | ||
|
||
**Kind**: instance method of <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#trades75 | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| [pair] | <code>string</code> | BTCUSD, LTCUSD or LTCBTC. Default BTCUSD | | ||
|
||
<a name="BitfinexWS+subscribeTicker"></a> | ||
### bitfinexWS.subscribeTicker([pair]) | ||
Subscribe to ticker updates. The ticker is a high level overview of the state | ||
of the market. It shows you the current best bid and ask, as well as the last | ||
trade price. | ||
|
||
Event will be emited as `PAIRNAME_ticker`. | ||
|
||
**Kind**: instance method of <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#ticker76 | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| [pair] | <code>string</code> | BTCUSD, LTCUSD or LTCBTC. Default BTCUSD | | ||
|
||
<a name="BitfinexWS+unsubscribe"></a> | ||
### bitfinexWS.unsubscribe(chanId) | ||
Unsubscribe to a channel. | ||
|
||
**Kind**: instance method of <code>[BitfinexWS](#BitfinexWS)</code> | ||
|
||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| chanId | <code>number</code> | ID of the channel received on `subscribed` event. | | ||
|
||
<a name="BitfinexWS+auth"></a> | ||
### bitfinexWS.auth() | ||
Autenticate the user. Will receive executed traded updates. | ||
|
||
**Kind**: instance method of <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#wallet-updates | ||
<a name="BitfinexWS+event_message"></a> | ||
### "message" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_open"></a> | ||
### "open" | ||
WebSocket connection is open. Ready to send. | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_error"></a> | ||
### "error" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_close"></a> | ||
### "close" | ||
WebSocket connection is closed. | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_subscribed"></a> | ||
### "subscribed" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
**Properties** | ||
|
||
| Name | Type | Description | | ||
| --- | --- | --- | | ||
| channel | <code>string</code> | Channel type | | ||
| pair | <code>string</code> | Currency pair. | | ||
| chanId | <code>number</code> | Channel ID sended by Bitfinex | | ||
|
||
<a name="BitfinexWS+event_auth"></a> | ||
### "auth" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_ps"></a> | ||
### "ps" | ||
position snapshot | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_pn"></a> | ||
### "pn" | ||
new position | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_pu"></a> | ||
### "pu" | ||
position update | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_pc"></a> | ||
### "pc" | ||
position close | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_ws"></a> | ||
### "ws" | ||
wallet snapshot | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_ws"></a> | ||
### "ws" | ||
wallet snapshot | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_os"></a> | ||
### "os" | ||
order snapshot | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_on"></a> | ||
### "on" | ||
new order | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_ou"></a> | ||
### "ou" | ||
order update | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_oc"></a> | ||
### "oc" | ||
order cancel | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_te"></a> | ||
### "te" | ||
trade executed | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_tu"></a> | ||
### "tu" | ||
trade execution update | ||
|
||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
<a name="BitfinexWS+event_ticker"></a> | ||
### "ticker" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| bid | <code>number</code> | | ||
| bidSize | <code>number</code> | | ||
| ask | <code>number</code> | | ||
| askSize | <code>number</code> | | ||
| dailyChange | <code>number</code> | | ||
| dailyChangePerc | <code>number</code> | | ||
| lastPrice | <code>number</code> | | ||
| volume | <code>number</code> | | ||
| high | <code>number</code> | | ||
| low | <code>number</code> | | ||
|
||
<a name="BitfinexWS+event_trade"></a> | ||
### "trade" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#trades75 | ||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| seq | <code>string</code> | | ||
| timestamp | <code>number</code> | | ||
| price | <code>number</code> | | ||
| amount | <code>number</code> | | ||
|
||
<a name="BitfinexWS+event_orderbook"></a> | ||
### "orderbook" | ||
**Kind**: event emitted by <code>[BitfinexWS](#BitfinexWS)</code> | ||
**See**: http://docs.bitfinex.com/#order-books | ||
**Properties** | ||
|
||
| Name | Type | | ||
| --- | --- | | ||
| price | <code>string</code> | | ||
| count | <code>number</code> | | ||
| amount | <code>number</code> | | ||
|
||
<a name="BitfinexWS.WebSocketURI"></a> | ||
### BitfinexWS.WebSocketURI : <code>String</code> | ||
**Kind**: static constant of <code>[BitfinexWS](#BitfinexWS)</code> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var BitfinexWS = require ('bitfinex-api-node').WS; | ||
|
||
var bws = new BitfinexWS(); | ||
|
||
bws.on('open', function () { | ||
bws.subscribeTrades('BTCUSD'); | ||
bws.subscribeOrderBook('BTCUSD'); | ||
bws.subscribeTicker('LTCBTC'); | ||
}); | ||
|
||
bws.on('trade', function (pair, trade) { | ||
console.log('Trade:', trade); | ||
}); | ||
|
||
bws.on('orderbook', function (pair, book) { | ||
console.log('Order book:', book); | ||
}); | ||
|
||
bws.on('ticker', function (pair, ticker) { | ||
console.log('Ticker:', ticker); | ||
}); | ||
|
||
bws.on('subscribed', function (data) { | ||
console.log('New subscription', data); | ||
}); | ||
|
||
bws.on('error', console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
var rest = require('./rest.js'), | ||
ws = require('./ws.js'); | ||
"use strict"; | ||
|
||
var BFX = function(api_key, api_secret){ | ||
var APIRest = require('./rest.js'); | ||
var WS = require('./ws.js'); | ||
|
||
var BFX = function (api_key, api_secret){ | ||
this.api_key = api_key; | ||
this.api_secret = api_secret; | ||
this.rest = new rest(this.api_key, this.api_secret); | ||
this.ws = new ws(this.api_key, this.api_secret); | ||
this.rest = new APIRest(this.api_key, this.api_secret); | ||
this.ws = new WS(this.api_key, this.api_secret); | ||
}; | ||
|
||
module.exports = BFX; | ||
BFX.WS = WS; | ||
BFX.APIRest = APIRest; | ||
|
||
module.exports = BFX; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.