-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathindex.html
More file actions
249 lines (189 loc) · 18.1 KB
/
index.html
File metadata and controls
249 lines (189 loc) · 18.1 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Home - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WS2Manager.html">WS2Manager</a><ul class='methods'><li data-type='method'><a href="WS2Manager.html#.getDataChannelCount">getDataChannelCount</a></li><li data-type='method'><a href="WS2Manager.html#auth">auth</a></li><li data-type='method'><a href="WS2Manager.html#close">close</a></li><li data-type='method'><a href="WS2Manager.html#getAuthArgs">getAuthArgs</a></li><li data-type='method'><a href="WS2Manager.html#getAuthenticatedSocket">getAuthenticatedSocket</a></li><li data-type='method'><a href="WS2Manager.html#getFreeDataSocket">getFreeDataSocket</a></li><li data-type='method'><a href="WS2Manager.html#getNumSockets">getNumSockets</a></li><li data-type='method'><a href="WS2Manager.html#getSocket">getSocket</a></li><li data-type='method'><a href="WS2Manager.html#getSocketInfo">getSocketInfo</a></li><li data-type='method'><a href="WS2Manager.html#getSocketWithChannel">getSocketWithChannel</a></li><li data-type='method'><a href="WS2Manager.html#getSocketWithDataChannel">getSocketWithDataChannel</a></li><li data-type='method'><a href="WS2Manager.html#getSocketWithSubRef">getSocketWithSubRef</a></li><li data-type='method'><a href="WS2Manager.html#managedUnsubscribe">managedUnsubscribe</a></li><li data-type='method'><a href="WS2Manager.html#onCandle">onCandle</a></li><li data-type='method'><a href="WS2Manager.html#onOrderBook">onOrderBook</a></li><li data-type='method'><a href="WS2Manager.html#onTicker">onTicker</a></li><li data-type='method'><a href="WS2Manager.html#onTrades">onTrades</a></li><li data-type='method'><a href="WS2Manager.html#openSocket">openSocket</a></li><li data-type='method'><a href="WS2Manager.html#reconnect">reconnect</a></li><li data-type='method'><a href="WS2Manager.html#setAuthArgs">setAuthArgs</a></li><li data-type='method'><a href="WS2Manager.html#subscribe">subscribe</a></li><li data-type='method'><a href="WS2Manager.html#subscribeCandles">subscribeCandles</a></li><li data-type='method'><a href="WS2Manager.html#subscribeOrderBook">subscribeOrderBook</a></li><li data-type='method'><a href="WS2Manager.html#subscribeTicker">subscribeTicker</a></li><li data-type='method'><a href="WS2Manager.html#subscribeTrades">subscribeTrades</a></li><li data-type='method'><a href="WS2Manager.html#unsubscribe">unsubscribe</a></li><li data-type='method'><a href="WS2Manager.html#withAllSockets">withAllSockets</a></li></ul></li><li><a href="WSv2.html">WSv2</a><ul class='methods'><li data-type='method'><a href="WSv2.html#auth">auth</a></li><li data-type='method'><a href="WSv2.html#cancelFundingOffer">cancelFundingOffer</a></li><li data-type='method'><a href="WSv2.html#cancelOrder">cancelOrder</a></li><li data-type='method'><a href="WSv2.html#cancelOrders">cancelOrders</a></li><li data-type='method'><a href="WSv2.html#close">close</a></li><li data-type='method'><a href="WSv2.html#closeFundingCredit">closeFundingCredit</a></li><li data-type='method'><a href="WSv2.html#closeFundingLoan">closeFundingLoan</a></li><li data-type='method'><a href="WSv2.html#enableFlag">enableFlag</a></li><li data-type='method'><a href="WSv2.html#enableSequencing">enableSequencing</a></li><li data-type='method'><a href="WSv2.html#getAuthArgs">getAuthArgs</a></li><li data-type='method'><a href="WSv2.html#getCandles">getCandles</a></li><li data-type='method'><a href="WSv2.html#getChannelData">getChannelData</a></li><li data-type='method'><a href="WSv2.html#getDataChannelCount">getDataChannelCount</a></li><li data-type='method'><a href="WSv2.html#getDataChannelId">getDataChannelId</a></li><li data-type='method'><a href="WSv2.html#getLosslessOB">getLosslessOB</a></li><li data-type='method'><a href="WSv2.html#getOB">getOB</a></li><li data-type='method'><a href="WSv2.html#getURL">getURL</a></li><li data-type='method'><a href="WSv2.html#hasChannel">hasChannel</a></li><li data-type='method'><a href="WSv2.html#hasDataChannel">hasDataChannel</a></li><li data-type='method'><a href="WSv2.html#hasSubscriptionRef">hasSubscriptionRef</a></li><li data-type='method'><a href="WSv2.html#isAuthenticated">isAuthenticated</a></li><li data-type='method'><a href="WSv2.html#isFlagEnabled">isFlagEnabled</a></li><li data-type='method'><a href="WSv2.html#isOpen">isOpen</a></li><li data-type='method'><a href="WSv2.html#isReconnecting">isReconnecting</a></li><li data-type='method'><a href="WSv2.html#managedSubscribe">managedSubscribe</a></li><li data-type='method'><a href="WSv2.html#managedUnsubscribe">managedUnsubscribe</a></li><li data-type='method'><a href="WSv2.html#notifyUI">notifyUI</a></li><li data-type='method'><a href="WSv2.html#onAccountTradeEntry">onAccountTradeEntry</a></li><li data-type='method'><a href="WSv2.html#onAccountTradeUpdate">onAccountTradeUpdate</a></li><li data-type='method'><a href="WSv2.html#onBalanceInfoUpdate">onBalanceInfoUpdate</a></li><li data-type='method'><a href="WSv2.html#onCandle">onCandle</a></li><li data-type='method'><a href="WSv2.html#onFundingCreditClose">onFundingCreditClose</a></li><li data-type='method'><a href="WSv2.html#onFundingCreditNew">onFundingCreditNew</a></li><li data-type='method'><a href="WSv2.html#onFundingCreditSnapshot">onFundingCreditSnapshot</a></li><li data-type='method'><a href="WSv2.html#onFundingCreditUpdate">onFundingCreditUpdate</a></li><li data-type='method'><a href="WSv2.html#onFundingInfoUpdate">onFundingInfoUpdate</a></li><li data-type='method'><a href="WSv2.html#onFundingLoanClose">onFundingLoanClose</a></li><li data-type='method'><a href="WSv2.html#onFundingLoanNew">onFundingLoanNew</a></li><li data-type='method'><a href="WSv2.html#onFundingLoanSnapshot">onFundingLoanSnapshot</a></li><li data-type='method'><a href="WSv2.html#onFundingLoanUpdate">onFundingLoanUpdate</a></li><li data-type='method'><a href="WSv2.html#onFundingOfferClose">onFundingOfferClose</a></li><li data-type='method'><a href="WSv2.html#onFundingOfferNew">onFundingOfferNew</a></li><li data-type='method'><a href="WSv2.html#onFundingOfferSnapshot">onFundingOfferSnapshot</a></li><li data-type='method'><a href="WSv2.html#onFundingOfferUpdate">onFundingOfferUpdate</a></li><li data-type='method'><a href="WSv2.html#onFundingTradeEntry">onFundingTradeEntry</a></li><li data-type='method'><a href="WSv2.html#onFundingTradeUpdate">onFundingTradeUpdate</a></li><li data-type='method'><a href="WSv2.html#onInfoMessage">onInfoMessage</a></li><li data-type='method'><a href="WSv2.html#onMaintenanceEnd">onMaintenanceEnd</a></li><li data-type='method'><a href="WSv2.html#onMaintenanceStart">onMaintenanceStart</a></li><li data-type='method'><a href="WSv2.html#onMarginInfoUpdate">onMarginInfoUpdate</a></li><li data-type='method'><a href="WSv2.html#onMessage">onMessage</a></li><li data-type='method'><a href="WSv2.html#onNotification">onNotification</a></li><li data-type='method'><a href="WSv2.html#onOrderBook">onOrderBook</a></li><li data-type='method'><a href="WSv2.html#onOrderBookChecksum">onOrderBookChecksum</a></li><li data-type='method'><a href="WSv2.html#onOrderClose">onOrderClose</a></li><li data-type='method'><a href="WSv2.html#onOrderNew">onOrderNew</a></li><li data-type='method'><a href="WSv2.html#onOrderSnapshot">onOrderSnapshot</a></li><li data-type='method'><a href="WSv2.html#onOrderUpdate">onOrderUpdate</a></li><li data-type='method'><a href="WSv2.html#onPositionClose">onPositionClose</a></li><li data-type='method'><a href="WSv2.html#onPositionNew">onPositionNew</a></li><li data-type='method'><a href="WSv2.html#onPositionSnapshot">onPositionSnapshot</a></li><li data-type='method'><a href="WSv2.html#onPositionUpdate">onPositionUpdate</a></li><li data-type='method'><a href="WSv2.html#onServerRestart">onServerRestart</a></li><li data-type='method'><a href="WSv2.html#onStatus">onStatus</a></li><li data-type='method'><a href="WSv2.html#onTicker">onTicker</a></li><li data-type='method'><a href="WSv2.html#onTradeEntry">onTradeEntry</a></li><li data-type='method'><a href="WSv2.html#onTrades">onTrades</a></li><li data-type='method'><a href="WSv2.html#onWalletSnapshot">onWalletSnapshot</a></li><li data-type='method'><a href="WSv2.html#onWalletUpdate">onWalletUpdate</a></li><li data-type='method'><a href="WSv2.html#open">open</a></li><li data-type='method'><a href="WSv2.html#reconnect">reconnect</a></li><li data-type='method'><a href="WSv2.html#removeListeners">removeListeners</a></li><li data-type='method'><a href="WSv2.html#requestCalc">requestCalc</a></li><li data-type='method'><a href="WSv2.html#send">send</a></li><li data-type='method'><a href="WSv2.html#sequencingEnabled">sequencingEnabled</a></li><li data-type='method'><a href="WSv2.html#setAPICredentials">setAPICredentials</a></li><li data-type='method'><a href="WSv2.html#submitFundingOffer">submitFundingOffer</a></li><li data-type='method'><a href="WSv2.html#submitOrder">submitOrder</a></li><li data-type='method'><a href="WSv2.html#submitOrderMultiOp">submitOrderMultiOp</a></li><li data-type='method'><a href="WSv2.html#subscribe">subscribe</a></li><li data-type='method'><a href="WSv2.html#subscribeCandles">subscribeCandles</a></li><li data-type='method'><a href="WSv2.html#subscribeOrderBook">subscribeOrderBook</a></li><li data-type='method'><a href="WSv2.html#subscribeStatus">subscribeStatus</a></li><li data-type='method'><a href="WSv2.html#subscribeTicker">subscribeTicker</a></li><li data-type='method'><a href="WSv2.html#subscribeTrades">subscribeTrades</a></li><li data-type='method'><a href="WSv2.html#unsubscribe">unsubscribe</a></li><li data-type='method'><a href="WSv2.html#unsubscribeCandles">unsubscribeCandles</a></li><li data-type='method'><a href="WSv2.html#unsubscribeOrderBook">unsubscribeOrderBook</a></li><li data-type='method'><a href="WSv2.html#unsubscribeStatus">unsubscribeStatus</a></li><li data-type='method'><a href="WSv2.html#unsubscribeTicker">unsubscribeTicker</a></li><li data-type='method'><a href="WSv2.html#unsubscribeTrades">unsubscribeTrades</a></li><li data-type='method'><a href="WSv2.html#updateAuthArgs">updateAuthArgs</a></li><li data-type='method'><a href="WSv2.html#updateOrder">updateOrder</a></li><li data-type='method'><a href="WSv2.html#usesAgent">usesAgent</a></li></ul></li><li></li></ul><h3>Global</h3><ul><li><a href="global.html#setSigFig">setSigFig</a></li></ul>
</nav>
<div id="main">
<section class="package">
<h3> </h3>
</section>
<section class="readme usertext">
<article><h1>Bitfinex WSv2 Trading API for Node.JS - Bitcoin, Ethereum, Ripple and more</h1>
<p><a href="https://travis-ci.org/bitfinexcom/bitfinex-api-node"><img src="https://travis-ci.org/bitfinexcom/bitfinex-api-node.svg?branch=master" alt="Build Status"></a></p>
<p>A Node.JS reference implementation of the Bitfinex API</p>
<h2>Features</h2>
<ul>
<li>Official implementation</li>
<li>REST v2 API</li>
<li>WebSockets v2 API</li>
<li>WebSockets v1 API</li>
</ul>
<h2>Installation</h2>
<pre class="prettyprint source lang-bash"><code> npm i --save bitfinex-api-node
</code></pre>
<h3>Quickstart</h3>
<pre class="prettyprint source lang-js"><code>const { WSv2 } = require('bitfinex-api-node')
const ws = new WSv2({ transform: true })
// do something with ws client
</code></pre>
<h3>Docs</h3>
<p>Refer to the <a href="https://cdn.statically.io/gh/bitfinexcom/bitfinex-api-node/master/docs/index.html"><code>docs/</code></a>
folder for JSDoc-generated HTML documentation, and the <a href="/examples"><code>examples/</code></a>
folder for executable examples covering common use cases.</p>
<p>Official API documentation at <a href="https://docs.bitfinex.com/v2/reference">https://docs.bitfinex.com/v2/reference</a></p>
<h3>Examples</h3>
<p>Sending an order & tracking status:</p>
<pre class="prettyprint source lang-js"><code>const ws = bfx.ws()
ws.on('error', (err) => console.log(err))
ws.on('open', ws.auth.bind(ws))
ws.once('auth', () => {
const o = new Order({
cid: Date.now(),
symbol: 'tETHUSD',
amount: 0.1,
type: Order.type.MARKET
}, ws)
// Enable automatic updates
o.registerListeners()
o.on('update', () => {
console.log(`order updated: ${o.serialize()}`)
})
o.on('close', () => {
console.log(`order closed: ${o.status}`)
ws.close()
})
o.submit().then(() => {
console.log(`submitted order ${o.id}`)
}).catch((err) => {
console.error(err)
ws.close()
})
})
ws.open()
</code></pre>
<p>Cancel all open orders</p>
<pre class="prettyprint source lang-js"><code>const ws = bfx.ws(2)
ws.on('error', (err) => console.log(err))
ws.on('open', ws.auth.bind(ws))
ws.onOrderSnapshot({}, (orders) => {
if (orders.length === 0) {
console.log('no open orders')
return
}
console.log(`recv ${orders.length} open orders`)
ws.cancelOrders(orders).then(() => {
console.log('cancelled orders')
})
})
ws.open()
</code></pre>
<p>Subscribe to trades by pair</p>
<pre class="prettyprint source lang-js"><code>const ws = bfx.ws(2)
ws.on('error', (err) => console.log(err))
ws.on('open', () => {
ws.subscribeTrades('BTCUSD')
})
ws.onTrades({ symbol: 'tBTCUSD' }, (trades) => {
console.log(`trades: ${JSON.stringify(trades)}`)
})
ws.onTradeEntry({ symbol: 'tBTCUSD' }, (trades) => {
console.log(`te: ${JSON.stringify(trades)}`)
})
ws.open()
</code></pre>
<h2>Version 2.0.0 Breaking changes</h2>
<h3>constructor takes only an options object now, including the API keys</h3>
<p>Old:</p>
<pre class="prettyprint source lang-js"><code>new BFX(API_KEY, API_SECRET, { version: 2 })
</code></pre>
<p>since 2.0.0:</p>
<pre class="prettyprint source lang-js"><code>new BFX({ apiKey: '', apiSecret: '' })
</code></pre>
<h3><code>trade</code> and <code>orderbook</code> snapshots are emitted as nested lists</h3>
<p>To make dealing with snapshots better predictable, snapshots are emitted as an array.</p>
<h3>normalized orderbooks for R0</h3>
<p>Lists of raw orderbooks (<code>R0</code>) are ordered in the same order as <code>P0</code>, <code>P1</code>,
<code>P2</code>, <code>P3</code></p>
<h2>Testing</h2>
<pre class="prettyprint source lang-bash"><code>npm test
</code></pre>
<h2>FAQ</h2>
<h3>Order Creation Limits</h3>
<p>The base limit per-user is 1,000 orders per 5 minute interval, and is shared
between all account API connections. It increases proportionally to your trade
volume based on the following formula:</p>
<p><code>1000 + (TOTAL_PAIRS_PLATFORM * 60 * 5) / (250000000 / USER_VOL_LAST_30d)</code></p>
<p>Where <code>TOTAL_PAIRS_PLATFORM</code> is the number of pairs shared between
Ethfinex/Bitfinex (currently ~101) and <code>USER_VOL_LAST_30d</code> is in USD.</p>
<h3>'on' Packet Guarantees</h3>
<p>No; if your order fills immediately, the first packet referencing the order
will be an <code>oc</code> signaling the order has closed. If the order fills partially
immediately after creation, an <code>on</code> packet will arrive with a status of
<code>PARTIALLY FILLED...</code></p>
<p>For example, if you submit a <code>LIMIT</code> buy for 0.2 BTC and it is added to the
order book, an <code>on</code> packet will arrive via ws2. After a partial fill of 0.1
BTC, an <code>ou</code> packet will arrive, followed by a final <code>oc</code> after the remaining
0.1 BTC fills.</p>
<p>On the other hand, if the order fills immediately for 0.2 BTC, you will only
receive an <code>oc</code> packet.</p>
<h3>Nonce too small</h3>
<p>I make multiple parallel request and I receive an error that the nonce is too
small. What does it mean?</p>
<p>Nonces are used to guard against replay attacks. When multiple HTTP requests
arrive at the API with the wrong nonce, e.g. because of an async timing issue,
the API will reject the request.</p>
<p>If you need to go parallel, you have to use multiple API keys right now.</p>
<h3><code>te</code> vs <code>tu</code> Messages</h3>
<p>A <code>te</code> packet is sent first to the client immediately after a trade has been
matched & executed, followed by a <code>tu</code> message once it has completed processing.
During times of high load, the <code>tu</code> message may be noticably delayed, and as
such only the <code>te</code> message should be used for a realtime feed.</p>
<h3>Sequencing</h3>
<p>If you enable sequencing on v2 of the WS API, each incoming packet will have a
public sequence number at the end, along with an auth sequence number in the
case of channel <code>0</code> packets. The public seq numbers increment on each packet,
and the auth seq numbers increment on each authenticated action (new orders,
etc). These values allow you to verify that no packets have been missed/dropped,
since they always increase monotonically.</p>
<h3>Differences Between R* and P* Order Books</h3>
<p>Order books with precision <code>R0</code> are considered 'raw' and contain entries for
each order submitted to the book, whereas <code>P*</code> books contain entries for each
price level (which aggregate orders).</p>
<h3>Contributing</h3>
<ol>
<li>Fork it</li>
<li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
<li>Commit your changes (<code>git commit -am 'Add some feature'</code>)</li>
<li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
<li>Create a new Pull Request</li>
</ol></article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a> on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>