(async) Parameters:
+ Example
+ ws.closeFundingCredit({ id: 1234 })
-
-
-
-
- Name
-
-
- Type
+ws.onFundingCreditClose({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding credit status: ', resp.status)
+})
-
-
- Description
-
-
-
+ Parameters:
-
-
- args
-
-
-
-
-
-object
-
-
-
-
-
-
-
-
-
- params
- Properties
-
-
@@ -2223,8 +2197,6 @@ Properties
Type
- Attributes
-
@@ -2237,40 +2209,33 @@ Properties
- audit
+ payload
-boolean
+FundingCredit
+|
+object
+|
-
-
+Array
+|
-
-
-
- <optional>
-
+number
-
-
-
+
- if true, an error is emitted on invalid seq
-
-
-
-
-
+
-
+ funding credit class,
+object literal, array or ID to cancel
@@ -2290,30 +2255,20 @@ Properties
-
-
-Returns:
+Throws:
-
-
+
+
+
an error if not authenticated
+
+
-
-
- Type
-
-
-
-Promise
+
-
-
-
@@ -2322,7 +2277,7 @@ Returns:
- getAuthArgs() → {object}
+ closeFundingLoan(payload)
@@ -2334,7 +2289,7 @@ getAuthArg
Source:
@@ -2368,9 +2323,11 @@ getAuthArg
See:
@@ -2383,7 +2340,9 @@ getAuthArg
-
Fetch the current default auth parameters
+
Cancels funding loan by ID. Emits an error if not authenticated.
+The ID can be passed as a number, key/value pair object literal,
+an instance of FundingLoan class or an array
@@ -2394,15 +2353,74 @@ getAuthArg
+ Example
+
+ ws.closeFundingLoan({ id: 1234 })
+
+ws.onFundingLoanClose({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding loan status: ', resp.status)
+})
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ payload
+
+
+
+
+
+FundingLoan
+|
+object
+|
+Array
+|
+number
+
+
+
+
+ funding loan class,
+object literal, array or ID to cancel
+
+
+
+
@@ -2410,37 +2428,36 @@ getAuthArg
-Returns:
-
-
-
-
- Type
-
-
+
+
+
+Throws:
+
-object
+
+
+
an error if not authenticated
+
+
-
-
+
+
- getCandles(key) → {Array}
+ (async) enableFlag(flag) → {Promise}
@@ -2452,7 +2469,7 @@ getCandles<
Source:
@@ -2482,6 +2499,13 @@ getCandles<
+
+ See:
+
+
+
@@ -2492,8 +2516,7 @@ getCandles<
-
Fetch a reference to the full set of synced candles for the specified key.
-Set managedCandles: true
in the constructor to use.
+
Enables a configuration flag.
@@ -2506,21 +2529,14 @@ getCandles<
Example
- const ws = new WSv2({ managedCandles: true })
-
- ws.on('open', async () => {
- ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => {
- const candles = ws.getCandles('trade:1m:tBTCUSD')
-
- if (!candles) return
-
- console.log('%d candles in dataset', candles.length)
- })
+ const ws = new WSv2()
- ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' })
- })
+ws.on('open', async () => {
+ await ws.enableFlag(WSv2.flags.CHECKSUM)
+ console.log('ob checkums enabled')
+})
- await ws.open()
+await ws.open()
@@ -2550,13 +2566,13 @@ Parameters:
- key
+ flag
-string
+number
@@ -2566,7 +2582,7 @@ Parameters:
- key for candle set
+ flag to update, as numeric value
@@ -2592,7 +2608,7 @@ Returns:
-
candles - empty array if none exist
+
p
@@ -2603,7 +2619,7 @@ Returns:
-Array
+Promise
@@ -2618,7 +2634,7 @@ Returns:
- getChannelData(opts) → {object}
+ (async) enableSequencing(args) → {Promise}
@@ -2630,7 +2646,7 @@ getChan
Source:
@@ -2660,6 +2676,13 @@ getChan
+
+ See:
+
+
+
@@ -2670,7 +2693,9 @@ getChan
-
Fetch a channel definition
+
Configures the seq flag to enable sequencing (packet number) for this
+connection. When enabled, the seq number will be the last value of
+channel packet arrays.
@@ -2708,7 +2733,7 @@ Parameters:
- opts
+ args
@@ -2724,7 +2749,7 @@ Parameters:
- options
+ params
Properties
@@ -2752,108 +2777,13 @@ Properties
- chanId
-
-
-
-
-
-number
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- channel ID
-
-
-
-
-
-
- channel
-
-
-
-
-
-string
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- channel name
-
-
-
-
-
-
- symbol
-
-
-
-
-
-string
-
-
-
-
-
-
-
-
- <optional>
-
-
-
-
-
-
-
-
-
-
- match by symbol
-
-
-
-
-
-
- key
+ audit
-string
+boolean
@@ -2873,7 +2803,7 @@ Properties
- match by key (for candle channels)
+ if true, an error is emitted on invalid seq
@@ -2906,7 +2836,7 @@ Returns:
-
chanData - null if not found
+
p
@@ -2917,7 +2847,7 @@ Returns:
-object
+Promise
@@ -2932,7 +2862,7 @@ Returns:
- getDataChannelCount() → {number}
+ getAuthArgs() → {object}
@@ -2944,7 +2874,7 @@ ge
Source:
@@ -2978,13 +2908,9 @@ ge
See:
@@ -2997,8 +2923,7 @@ ge
-
Get the total number of data channels this instance is currently
-subscribed too.
+
Fetch the current default auth parameters
@@ -3029,7 +2954,7 @@ Returns:
@@ -3040,7 +2965,7 @@ Returns:
-number
+object
@@ -3055,7 +2980,7 @@ Returns:
- getDataChannelId(type, filter) → {number}
+ getCandles(key) → {Array}
@@ -3067,7 +2992,7 @@ getDa
Source:
@@ -3107,7 +3032,8 @@ getDa
-
Fetch the ID of a channel matched by type and channel data filter
+
Fetch a reference to the full set of synced candles for the specified key.
+Set managedCandles: true
in the constructor to use.
@@ -3118,6 +3044,25 @@ getDa
+ Example
+
+ const ws = new WSv2({ managedCandles: true })
+
+ ws.on('open', async () => {
+ ws.onCandles({ key: 'trade:1m:tBTCUSD' }, () => {
+ const candles = ws.getCandles('trade:1m:tBTCUSD')
+
+ if (!candles) return
+
+ console.log('%d candles in dataset', candles.length)
+ })
+
+ ws.subscribeCandles({ key: 'trade:1m:tBTCUSD' })
+ })
+
+ await ws.open()
+
+
Parameters:
@@ -3145,7 +3090,7 @@ Parameters:
- type
+ key
@@ -3161,30 +3106,7 @@ Parameters:
- channel type
-
-
-
-
-
-
- filter
-
-
-
-
-
-object
-
-
-
-
-
-
-
-
-
- to be matched against channel data
+ key for candle set
@@ -3210,7 +3132,7 @@ Returns:
-
channelID
+
candles - empty array if none exist
@@ -3221,7 +3143,7 @@ Returns:
-number
+Array
@@ -3236,7 +3158,7 @@ Returns:
- getLosslessOB(symbol) → {OrderBook}
+ getChannelData(opts) → {object}
@@ -3248,7 +3170,7 @@ getLossl
Source:
@@ -3288,10 +3210,7 @@ getLossl
-
Returns an up-to-date lossless copy of the order book for the specified symbol, or
-null if no OB is managed for that symbol. All amounts and prices are in original
-string format.
-
Set manageOrderBooks: true
in the constructor to use.
+
Fetch a channel definition
@@ -3329,13 +3248,13 @@ Parameters:
- symbol
+ opts
-string
+object
@@ -3345,171 +3264,130 @@ Parameters:
- symbol for order book
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Returns:
+ options
+ Properties
+
+
+
+
-
-
ob - null if not found
-
-
-
-
-
-
- Type
-
-
+ Name
-OrderBook
-
-
-
-
-
-
-
+ Type
-
-
-
-
- getOB(symbol) → {OrderBook}
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
+ Attributes
+
-
+
-
+ Description
+
+
+
-
+
+
+ chanId
+
-
+
+
+
+number
-
-
+
+
-
+
+
+
-
+
-
+
+
+
-
+
-
+ channel ID
+
-
-
-
+
+
+ channel
+
-
-
-
Returns an up-to-date copy of the order book for the specified symbol, or
-null if no OB is managed for that symbol.
-
Set managedOrderBooks: true
in the constructor to use.
-
-
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ channel name
+
- Example
- const ws = new WSv2({ managedOrderBooks: true })
-
- ws.on('open', async () => {
- ws.onOrderBook({ symbol: 'tBTCUSD' }, () => {
- const book = ws.getOB('tBTCUSD')
-
- if (!book) return
-
- const spread = book.midPrice()
- console.log('spread for tBTCUSD: %f', spread)
- })
-
- ws.subscribeOrderBook({ symbol: 'tBTCUSD' })
- })
-
- await ws.open()
+
+
+ symbol
+
+
+
+
+string
- Parameters:
-
+
+
-
-
-
-
- Name
-
+
+
+
+ <optional>
+
- Type
+
-
+
+
+
-
+
- Description
-
-
+ match by symbol
+
-
- symbol
+ key
@@ -3522,10 +3400,27 @@ Parameters:
+
+
+ <optional>
+
+
+
+
+
+
+
- symbol for order book
+ match by key (for candle channels)
+
+
+
+
+
+
+
@@ -3551,7 +3446,7 @@ Returns:
-
ob - null if not found
+
chanData - null if not found
@@ -3562,7 +3457,7 @@ Returns:
-OrderBook
+object
@@ -3577,7 +3472,7 @@ Returns:
- getURL() → {string}
+ getDataChannelCount() → {number}
@@ -3589,7 +3484,7 @@ getURLSource:
@@ -3619,6 +3514,19 @@ getURLSee:
+
+
+
@@ -3628,6 +3536,11 @@ getURL
+ Get the total number of data channels this instance is currently
+subscribed too.
+
+
@@ -3656,7 +3569,7 @@ Returns:
@@ -3667,7 +3580,7 @@ Returns:
-string
+number
@@ -3682,7 +3595,7 @@ Returns:
- hasChannel(chanId) → {boolean}
+ getDataChannelId(type, filter) → {number}
@@ -3694,7 +3607,7 @@ hasChannel<
Source:
@@ -3734,7 +3647,7 @@ hasChannel<
-
Check if the instance is subscribed to the specified channel ID
+
Fetch the ID of a channel matched by type and channel data filter
@@ -3772,13 +3685,13 @@ Parameters:
- chanId
+ type
-number
+string
@@ -3788,7 +3701,30 @@ Parameters:
- ID of channel to query
+ channel type
+
+
+
+
+
+
+ filter
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+ to be matched against channel data
@@ -3814,7 +3750,7 @@ Returns:
-
isSubscribed
+
channelID
@@ -3825,7 +3761,7 @@ Returns:
-boolean
+number
@@ -3840,7 +3776,7 @@ Returns:
- hasDataChannel(type, filter) → {boolean}
+ getLosslessOB(symbol) → {OrderBook}
@@ -3852,7 +3788,7 @@ hasData
Source:
@@ -3892,8 +3828,10 @@ hasData
-
Check if the instance is subscribed to a data channel matching the
-specified type and filter.
+
Returns an up-to-date lossless copy of the order book for the specified symbol, or
+null if no OB is managed for that symbol. All amounts and prices are in original
+string format.
+
Set manageOrderBooks: true
in the constructor to use.
@@ -3931,7 +3869,7 @@ Parameters:
- type
+ symbol
@@ -3947,30 +3885,7 @@ Parameters:
- channel type
-
-
-
-
-
-
- filter
-
-
-
-
-
-object
-
-
-
-
-
-
-
-
-
- to be matched against channel data
+ symbol for order book
@@ -3996,7 +3911,7 @@ Returns:
-
hasChannel
+
ob - null if not found
@@ -4007,7 +3922,7 @@ Returns:
-boolean
+OrderBook
@@ -4022,7 +3937,7 @@ Returns:
- hasSubscriptionRef(channel, identifier) → {boolean}
+ getOB(symbol) → {OrderBook}
@@ -4034,7 +3949,7 @@ has
Source:
@@ -4064,13 +3979,6 @@ has
-
- See:
-
-
-
@@ -4081,7 +3989,9 @@ has
-
Check if a channel/identifier pair has been subscribed too
+
Returns an up-to-date copy of the order book for the specified symbol, or
+null if no OB is managed for that symbol.
+
Set managedOrderBooks: true
in the constructor to use.
@@ -4092,6 +4002,26 @@ has
+ Example
+
+ const ws = new WSv2({ managedOrderBooks: true })
+
+ ws.on('open', async () => {
+ ws.onOrderBook({ symbol: 'tBTCUSD' }, () => {
+ const book = ws.getOB('tBTCUSD')
+
+ if (!book) return
+
+ const spread = book.midPrice()
+ console.log('spread for tBTCUSD: %f', spread)
+ })
+
+ ws.subscribeOrderBook({ symbol: 'tBTCUSD' })
+ })
+
+ await ws.open()
+
+
Parameters:
@@ -4119,30 +4049,7 @@ Parameters:
- channel
-
-
-
-
-
-string
-
-
-
-
-
-
-
-
-
- channel type
-
-
-
-
-
-
- identifier
+ symbol
@@ -4158,7 +4065,7 @@ Parameters:
- unique identifier for the reference
+ symbol for order book
@@ -4184,7 +4091,7 @@ Returns:
-
hasRef
+
ob - null if not found
@@ -4195,7 +4102,7 @@ Returns:
-boolean
+OrderBook
@@ -4210,7 +4117,7 @@ Returns:
- isAuthenticated() → {boolean}
+ getURL() → {string}
@@ -4222,7 +4129,7 @@ isAuth
Source:
@@ -4289,7 +4196,7 @@ Returns:
@@ -4300,7 +4207,7 @@ Returns:
-boolean
+string
@@ -4315,7 +4222,7 @@ Returns:
- isFlagEnabled(flag) → {boolean}
+ hasChannel(chanId) → {boolean}
@@ -4327,7 +4234,7 @@ isFlagEn
Source:
@@ -4357,13 +4264,6 @@ isFlagEn
-
- See:
-
-
-
@@ -4374,7 +4274,7 @@ isFlagEn
-
Checks local state, relies on successful server config responses
+
Check if the instance is subscribed to the specified channel ID
@@ -4412,7 +4312,7 @@ Parameters:
- flag
+ chanId
@@ -4428,7 +4328,7 @@ Parameters:
- flag to check for
+ ID of channel to query
@@ -4454,112 +4354,7 @@ Returns:
-
-
-
-
-
- Type
-
-
-
-boolean
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- isOpen() → {boolean}
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-Returns:
-
-
-
@@ -4585,7 +4380,7 @@ Returns:
- isReconnecting() → {boolean}
+ hasDataChannel(type, filter) → {boolean}
@@ -4597,7 +4392,752 @@ isRecon
Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Check if the instance is subscribed to a data channel matching the
+specified type and filter.
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ type
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ channel type
+
+
+
+
+
+
+ filter
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+ to be matched against channel data
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ hasSubscriptionRef(channel, identifier) → {boolean}
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Check if a channel/identifier pair has been subscribed too
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ channel
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ channel type
+
+
+
+
+
+
+ identifier
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ unique identifier for the reference
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ isAuthenticated() → {boolean}
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ isFlagEnabled(flag) → {boolean}
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Checks local state, relies on successful server config responses
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ flag
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ flag to check for
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ isOpen() → {boolean}
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ isReconnecting() → {boolean}
+
+
+
+
+
+
+
+
+
+ Source:
+
@@ -5125,7 +5665,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ apiSecret
-
-
- sequencingEnabled() → {boolean}
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+string
-
-
+
+
-
+
-
+
-
+ API secret
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -17168,30 +17899,6 @@ sequ
-
-
-Returns:
-
-
-
-
-
-
-
-
- Type
-
-
-
-boolean
-
-
-
-
-
-
@@ -17200,7 +17907,7 @@ Returns:
- setAPICredentials(apiKey, apiSecret)
+ (async) submitFundingOffer(payload)
@@ -17212,7 +17919,7 @@ setA
Source:
@@ -17246,7 +17953,11 @@ setA
See:
@@ -17259,8 +17970,9 @@ setA
-
Update the internal API credentials, used on subsequent WSv2#auth
-calls
+
Sends a new funding offer to the server. Emits an error if not
+authenticated. The funding offer can be either key/value pair object
+literal, an instance of FundingOffer class or an array
@@ -17271,6 +17983,24 @@ setA
+ Example
+
+ const fo = new FundingOffer({
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '50',
+ rate: '0.001',
+ period: 2,
+ flags: 0
+}, ws)
+
+ws.submitFundingOffer(fo)
+
+ws.onFundingOfferNew({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding offer status: ', resp.status)
+})
+
+
Parameters:
@@ -17298,13 +18028,16 @@ Parameters:
- apiKey
+ payload
-string
+FundingOffer
+|
+
+Array
@@ -17314,35 +18047,16 @@ Parameters:
- API key
+ funding offer object model or array
+
+
-
-
- apiSecret
-
-
-
-
-
-string
-
-
-
-
-
-
-
- API secret
-
-
-
-
@@ -17353,10 +18067,18 @@ Parameters:
+Throws:
+
+
+
+
an error if not authenticated
+
+
+
@@ -17568,7 +18290,7 @@ (async)
Source:
@@ -20058,7 +20780,7 @@ (async) up
Source:
@@ -20462,7 +21184,7 @@ (constant)
Source:
@@ -20669,7 +21391,7 @@ (constant) W
Source:
@@ -20830,7 +21552,7 @@ (constant) WS
Source:
@@ -21112,6 +21834,186 @@ Returns:
+ cancelFundingOffer(payload)
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Cancels funding offer by ID. Emits an error if not authenticated.
+The ID can be passed as a number, key/value pair object literal,
+an instance of FundingOffer class or an array
+
+
+
+
+
+
+
+
+
+
+ Example
+
+ ws.cancelFundingOffer({ id: 1234 })
+
+ws.onFundingOfferClose({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding offer status: ', resp.status)
+})
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ payload
+
+
+
+
+
+FundingOffer
+|
+
+object
+|
+
+Array
+|
+
+number
+
+
+
+
+
+
+
+
+
+ funding offer model,
+array or ID to cancel
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Throws:
+
+
+
+
+
+
an error if not authenticated
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
(async) cancelOrder(order) → {Promise}
@@ -21124,7 +22026,7 @@ (async) ca
Source:
@@ -21211,19 +22113,191 @@ Parameters:
- order
+ order
+
+
+
+
+
+object
+|
+
+Array
+|
+
+number
+
+
+
+
+
+
+
+
+
+ order model, array, or ID to be cancelled
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+
+
+
+ Type
+
+
+
+Promise
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (async) cancelOrders(orders) → {Promise}
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Cancels multiple orders, returns a promise that resolves once all
+operations are confirmed.
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ orders
-object
+Array.<object>
|
-Array
+Array.<Array>
|
-number
+Array.<number>
@@ -21233,7 +22307,8 @@ Parameters:
- order model, array, or ID to be cancelled
+ array of order models, arrays
+or IDs to be cancelled
@@ -21285,7 +22360,7 @@ Returns:
- (async) cancelOrders(orders) → {Promise}
+ (async) close(code, reason) → {Promise}
@@ -21297,7 +22372,7 @@ (async) c
Source:
@@ -21327,13 +22402,6 @@ (async) c
-
- See:
-
-
-
@@ -21344,8 +22412,8 @@ (async) c
-
Cancels multiple orders, returns a promise that resolves once all
-operations are confirmed.
+
Closes the active connection. If there is none, rejects with a promise.
+Resolves on success
@@ -21383,19 +22451,36 @@ Parameters:
- orders
+ code
-Array.<object>
-|
+number
-Array.<Array>
-|
-Array.<number>
+
+
+
+
+
+
+
+ passed to ws
+
+
+
+
+
+
+ reason
+
+
+
+
+
+string
@@ -21405,8 +22490,7 @@ Parameters:
- array of order models, arrays
-or IDs to be cancelled
+ passed to ws
@@ -21458,7 +22542,7 @@ Returns:
- (async) close(code, reason) → {Promise}
+ closeFundingCredit(payload)
@@ -21470,7 +22554,7 @@ (async) closeSource:
@@ -21500,6 +22584,17 @@ (async) closeSee:
+
+
+
@@ -21510,8 +22605,9 @@ (async) close
- Closes the active connection. If there is none, rejects with a promise.
-Resolves on success
+ Cancels funding credit by ID. Emits an error if not authenticated.
+The ID can be passed as a number, key/value pair object literal,
+an instance of FundingCredit class or an array
@@ -21522,6 +22618,15 @@ (async) closeExample
+
+ ws.closeFundingCredit({ id: 1234 })
+
+ws.onFundingCreditClose({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding credit status: ', resp.status)
+})
+
+
Parameters:
@@ -21549,12 +22654,21 @@ Parameters:
- code
+ payload
+FundingCredit
+|
+
+object
+|
+
+Array
+|
+
number
@@ -21565,20 +22679,177 @@ Parameters:
- passed to ws
+ funding credit class,
+object literal, array or ID to cancel
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Throws:
+
+
+
+
+
+
an error if not authenticated
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ closeFundingLoan(payload)
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ See:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Cancels funding loan by ID. Emits an error if not authenticated.
+The ID can be passed as a number, key/value pair object literal,
+an instance of FundingLoan class or an array
+
+
+
+
+
+
+
+
+
+
+ Example
+
+ ws.closeFundingLoan({ id: 1234 })
+
+ws.onFundingLoanClose({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding loan status: ', resp.status)
+})
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
- reason
+ payload
-string
+FundingLoan
+|
+
+object
+|
+
+Array
+|
+
+number
@@ -21588,7 +22859,8 @@ Parameters:
- passed to ws
+ funding loan class,
+object literal, array or ID to cancel
@@ -21608,30 +22880,20 @@ Parameters:
-
-
-Returns:
+Throws:
-
-
+
+
+
an error if not authenticated
+
+
-
-
- Type
-
-
-
-Promise
+
-
-
-
@@ -23945,7 +25207,7 @@ isAuth
Source:
@@ -24215,7 +25477,7 @@ isOpenSource:
@@ -24320,7 +25582,7 @@ isRecon
Source:
@@ -24848,7 +26110,7 @@ notifyUISource:
@@ -25226,7 +26488,7 @@ on
Source:
@@ -25522,7 +26784,7 @@ o
Source:
@@ -25818,7 +27080,7 @@ on
Source:
@@ -26045,7 +27307,7 @@ onCandleSource:
@@ -26310,7 +27572,7 @@ o
Source:
@@ -26570,7 +27832,7 @@ onF
Source:
@@ -26830,7 +28092,7 @@ Source:
@@ -27093,7 +28355,7 @@
Source:
@@ -27353,7 +28615,7 @@ on
Source:
@@ -27580,7 +28842,7 @@ onF
Source:
@@ -27840,7 +29102,7 @@ onFun
Source:
@@ -28100,7 +29362,7 @@
Source:
@@ -28363,7 +29625,7 @@ on
Source:
@@ -28623,7 +29885,7 @@ on
Source:
@@ -28883,7 +30145,7 @@ onFu
Source:
@@ -29143,7 +30405,7 @@ Source:
@@ -29406,7 +30668,7 @@ o
Source:
@@ -29666,7 +30928,7 @@ on
Source:
@@ -29926,7 +31188,7 @@ o
Source:
@@ -30186,7 +31448,7 @@ onInfoMe
Source:
@@ -30619,7 +31881,7 @@ onM
Source:
@@ -30846,7 +32108,7 @@ onMessageSource:
@@ -31069,7 +32331,7 @@ onNotif
Source:
@@ -31329,7 +32591,7 @@ onOrderBoo
Source:
@@ -31656,7 +32918,7 @@ on
Source:
@@ -31983,7 +33245,7 @@ onOrderCl
Source:
@@ -32344,7 +33606,7 @@ onOrderNew<
Source:
@@ -32705,7 +33967,7 @@ onOrde
Source:
@@ -33069,7 +34331,7 @@ onOrderU
Source:
@@ -33430,7 +34692,7 @@ onPosi
Source:
@@ -33690,7 +34952,7 @@ onPositi
Source:
@@ -33950,7 +35212,7 @@ onP
Source:
@@ -34212,7 +35474,7 @@ onPos
Source:
@@ -34609,7 +35871,7 @@ onStatusSource:
@@ -34871,7 +36133,7 @@ onTickerSource:
@@ -35136,7 +36398,7 @@ onTradeEn
Source:
@@ -35436,7 +36698,7 @@ onTradesSource:
@@ -35737,7 +36999,7 @@ onWal
Source:
@@ -35964,7 +37226,7 @@ onWalle
Source:
@@ -36451,7 +37713,290 @@ remove
-
Remove all listeners by callback group ID
+
Remove all listeners by callback group ID
+
+
+
+
+
+
+
+
+
+
+ Example
+
+ await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 })
+await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 })
+await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 })
+
+// ...
+
+ws.removeListeners(42)
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ cbGID
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ callback group to remove
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ requestCalc(prefixes)
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Request a calc operation to be performed on the specified indexes
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ prefixes
+
+
+
+
+
+Array.<string>
+
+
+
+
+
+
+
+
+
+ desired prefixes to be calculated
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ send(msg)
+
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Send a packet to the WS server
@@ -36462,17 +38007,6 @@ remove
- Example
-
- await ws.subscribeTrades({ symbol: 'tBTCUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tLEOUSD', cbGID: 42 })
-await ws.subscribeTrades({ symbol: 'tETHUSD', cbGID: 42 })
-
-// ...
-
-ws.removeListeners(42)
-
-
Parameters:
@@ -36500,13 +38034,13 @@ Parameters:
- cbGID
+ msg
-string
+*
@@ -36516,7 +38050,7 @@ Parameters:
- callback group to remove
+ packet, gets stringified
@@ -36546,7 +38080,7 @@ Parameters:
- requestCalc(prefixes)
+ sequencingEnabled() → {boolean}
@@ -36558,7 +38092,7 @@ requestCal
Source:
@@ -36597,9 +38131,6 @@ requestCal
-
-
Request a calc operation to be performed on the specified indexes
-
@@ -36611,53 +38142,10 @@ requestCal
- Parameters:
-
-
-
-
-
- Name
-
- Type
-
-
-
- Description
-
-
-
-
-
-
-
-
- prefixes
-
-
-
-
-
-Array.<string>
-
-
-
-
-
-
-
-
-
- desired prefixes to be calculated
-
-
-
-
-
@@ -36667,13 +38155,28 @@ Parameters:
+Returns:
+
+
+
+
+ Type
+
+
+
+boolean
+
+
+
@@ -36682,7 +38185,7 @@ Parameters:
- send(msg)
+ setAPICredentials(apiKey, apiSecret)
@@ -36694,7 +38197,7 @@ sendSource:
@@ -36724,6 +38227,13 @@ sendSee:
+
+
+
@@ -36734,7 +38244,8 @@ send
- Send a packet to the WS server
+ Update the internal API credentials, used on subsequent WSv2#auth
+calls
@@ -36772,13 +38283,13 @@ Parameters:
- msg
+ apiKey
-*
+string
@@ -36788,93 +38299,35 @@ Parameters:
- packet, gets stringified
+ API key
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+ apiSecret
-
-
- sequencingEnabled() → {boolean}
-
-
-
-
-
-
-
-
-
- Source:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+string
-
-
+
+
-
+
-
+
-
+ API secret
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -36891,30 +38344,6 @@ sequ
-
-
-Returns:
-
-
-
-
-
-
-
-
- Type
-
-
-
-boolean
-
-
-
-
-
-
@@ -36923,7 +38352,7 @@ Returns:
- setAPICredentials(apiKey, apiSecret)
+ (async) submitFundingOffer(payload)
@@ -36935,7 +38364,7 @@ setA
Source:
@@ -36969,7 +38398,11 @@ setA
See:
@@ -36982,8 +38415,9 @@ setA
-
Update the internal API credentials, used on subsequent WSv2#auth
-calls
+
Sends a new funding offer to the server. Emits an error if not
+authenticated. The funding offer can be either key/value pair object
+literal, an instance of FundingOffer class or an array
@@ -36994,6 +38428,24 @@ setA
+ Example
+
+ const fo = new FundingOffer({
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '50',
+ rate: '0.001',
+ period: 2,
+ flags: 0
+}, ws)
+
+ws.submitFundingOffer(fo)
+
+ws.onFundingOfferNew({ symbol: 'fUSD' }, (resp) => {
+ console.log('Funding offer status: ', resp.status)
+})
+
+
Parameters:
@@ -37021,13 +38473,16 @@ Parameters:
- apiKey
+ payload
-string
+FundingOffer
+|
+
+Array
@@ -37037,35 +38492,16 @@ Parameters:
- API key
+ funding offer object model or array
+
+
-
-
- apiSecret
-
-
-
-
-
-string
-
-
-
-
-
-
-
- API secret
-
-
-
-
@@ -37076,10 +38512,18 @@ Parameters:
+Throws:
+
+
+
+
an error if not authenticated
+
+
+
@@ -37291,7 +38735,7 @@ (async)
Source:
@@ -39781,7 +41225,7 @@ (async) up
Source:
@@ -40056,7 +41500,7 @@ Returns:
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/global.html b/docs/global.html
index fe35a918..c71737e0 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -343,6 +343,242 @@
Type Definitions
+
FundingOffer
+
+
+
+
+
+
+
+
+ Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Properties:
+
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ type
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ offer type i.e. LIMIT, FRRDELTAVAR
+
+
+
+
+
+
+ symbol
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ symbol i.e. fUSD, fBTC
+
+
+
+
+
+
+ amount
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ positive for buy, negative for sell i.e. '50'
+
+
+
+
+
+
+ rate
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+ rate of the offer
+
+
+
+
+
+
+ period
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ Time period of offer. Min:2, Max:30 days
+
+
+
+
+
+
+ flags
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+ flags
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Type:
+
+
+
+
+
+
+
+
+
PromiseThrottle
@@ -484,7 +720,7 @@
Type:
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/index.html b/docs/index.html
index 37ca0cff..3de29ad9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -77,9 +77,9 @@
Quickstart
// do something with ws client
Docs
-
See docs/ws2.md
for WS2 API methods,
-and docs/usage.md
for a basic usage guide. For executable
-examples, refer to the examples/
folder.
+
Refer to the docs/
+folder for JSDoc-generated HTML documentation, and the examples/
+folder for executable examples covering common use cases.
Official API documentation at https://docs.bitfinex.com/v2/reference
Examples
Sending an order & tracking status:
@@ -236,7 +236,7 @@
Contributing
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/transports_ws2.js.html b/docs/transports_ws2.js.html
index 5208ed65..e1f8fb12 100644
--- a/docs/transports_ws2.js.html
+++ b/docs/transports_ws2.js.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -1458,11 +1458,11 @@
transports/ws2.js
this._infoListeners[code].forEach(cb => cb(msg))
}
- if (code === WSv2.INFO_CODES.SERVER_RESTART) {
+ if (code === WSv2.info.SERVER_RESTART) {
debug('server restarted, please reconnect')
- } else if (code === WSv2.INFO_CODES.MAINTENANCE_START) {
+ } else if (code === WSv2.info.MAINTENANCE_START) {
debug('server maintenance period started!')
- } else if (code === WSv2.INFO_CODES.MAINTENANCE_END) {
+ } else if (code === WSv2.info.MAINTENANCE_END) {
debug('server maintenance period ended!')
}
}
@@ -1975,6 +1975,160 @@
transports/ws2.js
return this._getEventPromise(`order-new-${packet.cid}`)
}
+ /**
+ * @typedef {object} FundingOffer
+ * @property {string} type - offer type i.e. LIMIT, FRRDELTAVAR
+ * @property {string} symbol - symbol i.e. fUSD, fBTC
+ * @property {string} amount - positive for buy, negative for sell i.e. '50'
+ * @property {string} rate - rate of the offer
+ * @property {number} period - Time period of offer. Min:2, Max:30 days
+ * @property {number} flags - flags
+ */
+
+ /**
+ * Sends a new funding offer to the server. Emits an error if not
+ * authenticated. The funding offer can be either key/value pair object
+ * literal, an instance of FundingOffer class or an array
+ *
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingCredit
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingOffer|Array} payload - funding offer object model or array
+ * @throws an error if not authenticated
+ * @example
+ * const fo = new FundingOffer({
+ * type: 'LIMIT',
+ * symbol: 'fUSD',
+ * amount: '50',
+ * rate: '0.001',
+ * period: 2,
+ * flags: 0
+ * }, ws)
+ *
+ * ws.submitFundingOffer(fo)
+ *
+ * ws.onFundingOfferNew({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding offer status: ', resp.status)
+ * })
+ */
+ async submitFundingOffer (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const packet = (
+ payload instanceof FundingOffer
+ ? payload
+ : new FundingOffer(payload)
+ ).toNewOfferPacket()
+
+ if (this._affCode) {
+ packet.meta.aff_code = packet.meta.aff_code || this._affCode
+ }
+
+ this.send([0, 'fon', null, packet])
+ }
+
+ /**
+ * Cancels funding offer by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingOffer class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#closeFundingCredit
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingOffer|object|Array|number} payload - funding offer model,
+ * array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.cancelFundingOffer({ id: 1234 })
+ *
+ * ws.onFundingOfferClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding offer status: ', resp.status)
+ * })
+ */
+ cancelFundingOffer (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'foc', null, { id }])
+ }
+
+ /**
+ * Cancels funding loan by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingLoan class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingCredit
+ *
+ * @param {FundingLoan|object|Array|number} payload - funding loan class,
+ * object literal, array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.closeFundingLoan({ id: 1234 })
+ *
+ * ws.onFundingLoanClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding loan status: ', resp.status)
+ * })
+ */
+ closeFundingLoan (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'flc', null, { id }])
+ }
+
+ /**
+ * Cancels funding credit by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingCredit class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingCredit|object|Array|number} payload - funding credit class,
+ * object literal, array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.closeFundingCredit({ id: 1234 })
+ *
+ * ws.onFundingCreditClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding credit status: ', resp.status)
+ * })
+ */
+ closeFundingCredit (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'fcc', null, { id }])
+ }
+
/**
* Send a changeset to update an order in-place while maintaining position in
* the price queue. The changeset must contain the order ID, and supports a
@@ -2352,9 +2506,8 @@
transports/ws2.js
* @param {Function} cb - callback
* @see https://docs.bitfinex.com/v2/reference#ws-public-trades
*/
- onAccountTradeEntry ({ pair, symbol, cbGID }, cb) {
- const id = pair || symbol || ''
- this._registerListener('auth-te', { 1: id }, Trade, cbGID, cb)
+ onAccountTradeEntry ({ symbol, cbGID }, cb) {
+ this._registerListener('auth-te', { 1: symbol }, Trade, cbGID, cb)
}
/**
@@ -2367,9 +2520,8 @@
transports/ws2.js
* @param {Function} cb - callback
* @see https://docs.bitfinex.com/v2/reference#ws-auth-trades
*/
- onAccountTradeUpdate ({ pair, symbol, cbGID }, cb) {
- const id = pair || symbol || ''
- this._registerListener('auth-tu', { 1: id }, Trade, cbGID, cb)
+ onAccountTradeUpdate ({ symbol, cbGID }, cb) {
+ this._registerListener('auth-tu', { 1: symbol }, Trade, cbGID, cb)
}
/**
@@ -2864,7 +3016,7 @@
transports/ws2.js
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/util_precision.js.html b/docs/util_precision.js.html
index 2c4cc4fa..a76def98 100644
--- a/docs/util_precision.js.html
+++ b/docs/util_precision.js.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -103,7 +103,7 @@
util/precision.js
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/util_ws2.js.html b/docs/util_ws2.js.html
index 4cb138ee..2ecb8202 100644
--- a/docs/util_ws2.js.html
+++ b/docs/util_ws2.js.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -69,7 +69,7 @@
util/ws2.js
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/docs/ws2_manager.js.html b/docs/ws2_manager.js.html
index bd680b80..590c028b 100644
--- a/docs/ws2_manager.js.html
+++ b/docs/ws2_manager.js.html
@@ -27,7 +27,7 @@
- Home Classes Global
+ Home Classes Global
@@ -616,7 +616,7 @@
ws2_manager.js
- Documentation generated by JSDoc 3.6.3 on Tue Mar 10 2020 21:05:28 GMT+0700 (Indochina Time) using the docdash theme.
+ Documentation generated by JSDoc 3.6.4 on Fri Jun 05 2020 17:26:26 GMT+0300 (Eastern European Summer Time) using the docdash theme.
diff --git a/examples/ws2/cancel_funding_offer.js b/examples/ws2/cancel_funding_offer.js
new file mode 100644
index 00000000..0f374064
--- /dev/null
+++ b/examples/ws2/cancel_funding_offer.js
@@ -0,0 +1,24 @@
+const { WSv2 } = require('../..')
+// from 'bitfinex-api-node' module
+// const { WSv2 } = require('bitfinex-api-node')
+
+;(async () => {
+ const ws2 = new WSv2({
+ apiKey: '
',
+ apiSecret: ''
+ // you can obtain your keys from https://www.bitfinex.com/api
+ })
+
+ try {
+ await ws2.open()
+ await ws2.auth()
+
+ ws2.onFundingOfferClose({}, (resp) => {
+ console.log('onFundingOfferClose: ', resp)
+ })
+
+ ws2.cancelFundingOffer('')
+ } catch (error) {
+ console.log('error: ', error)
+ }
+})()
diff --git a/examples/ws2/close_funding_credit.js b/examples/ws2/close_funding_credit.js
new file mode 100644
index 00000000..00d2cf6a
--- /dev/null
+++ b/examples/ws2/close_funding_credit.js
@@ -0,0 +1,24 @@
+const { WSv2 } = require('../..')
+// from 'bitfinex-api-node' module
+// const { WSv2 } = require('bitfinex-api-node')
+
+;(async () => {
+ const ws2 = new WSv2({
+ apiKey: '',
+ apiSecret: ''
+ // you can obtain your keys from https://www.bitfinex.com/api
+ })
+
+ try {
+ await ws2.open()
+ await ws2.auth()
+
+ ws2.onFundingCreditClose({}, (resp) => {
+ console.log('onFundingCreditClose: ', resp)
+ })
+
+ ws2.closeFundingCredit('')
+ } catch (error) {
+ console.log('error: ', error)
+ }
+})()
diff --git a/examples/ws2/close_funding_loan.js b/examples/ws2/close_funding_loan.js
new file mode 100644
index 00000000..11228335
--- /dev/null
+++ b/examples/ws2/close_funding_loan.js
@@ -0,0 +1,24 @@
+const { WSv2 } = require('../..')
+// from 'bitfinex-api-node' module
+// const { WSv2 } = require('bitfinex-api-node')
+
+;(async () => {
+ const ws2 = new WSv2({
+ apiKey: '',
+ apiSecret: ''
+ // you can obtain your keys from https://www.bitfinex.com/api
+ })
+
+ try {
+ await ws2.open()
+ await ws2.auth()
+
+ ws2.onFundingLoanClose({}, (resp) => {
+ console.log('onFundingLoanClose: ', resp)
+ })
+
+ ws2.closeFundingLoan('')
+ } catch (error) {
+ console.log('error: ', error)
+ }
+})()
diff --git a/examples/ws2/submit_funding_offer.js b/examples/ws2/submit_funding_offer.js
new file mode 100644
index 00000000..4b79545d
--- /dev/null
+++ b/examples/ws2/submit_funding_offer.js
@@ -0,0 +1,32 @@
+const { FundingOffer } = require('bfx-api-node-models')
+const { WSv2 } = require('../..')
+// from 'bitfinex-api-node' module
+// const { WSv2 } = require('bitfinex-api-node')
+
+;(async () => {
+ const ws2 = new WSv2({
+ apiKey: '',
+ apiSecret: ''
+ // you can obtain your keys from https://www.bitfinex.com/api
+ })
+
+ try {
+ await ws2.open()
+ await ws2.auth()
+
+ ws2.onFundingOfferNew({ symbol: 'fUSD' }, (resp) => {
+ console.log('onFundingOfferNew:', resp)
+ })
+
+ ws2.submitFundingOffer(new FundingOffer({
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '-50',
+ rate: '0.001',
+ period: 2,
+ flags: 0
+ }))
+ } catch (error) {
+ console.log('error: ', error)
+ }
+})()
diff --git a/lib/transports/ws2.js b/lib/transports/ws2.js
index facba4d0..22dcce78 100644
--- a/lib/transports/ws2.js
+++ b/lib/transports/ws2.js
@@ -1931,6 +1931,164 @@ class WSv2 extends EventEmitter {
return this._getEventPromise(`order-new-${packet.cid}`)
}
+ /**
+ * @typedef {object} FundingOffer
+ * @property {string} type - offer type i.e. LIMIT, FRRDELTAVAR
+ * @property {string} symbol - symbol i.e. fUSD, fBTC
+ * @property {string} amount - positive for buy, negative for sell i.e. '50'
+ * @property {string} rate - rate of the offer
+ * @property {number} period - Time period of offer. Min:2, Max:30 days
+ * @property {number} flags - flags
+ */
+
+ /**
+ * Sends a new funding offer to the server. Emits an error if not
+ * authenticated. The funding offer can be either key/value pair object
+ * literal, an instance of FundingOffer class or an array
+ *
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingCredit
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingOffer|Array} payload - funding offer object model or array
+ * @throws an error if not authenticated
+ * @example
+ * const fo = new FundingOffer({
+ * type: 'LIMIT',
+ * symbol: 'fUSD',
+ * amount: '50',
+ * rate: '0.001',
+ * period: 2,
+ * flags: 0
+ * }, ws)
+ *
+ * ws.submitFundingOffer(fo)
+ *
+ * ws.onFundingOfferNew({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding offer status: ', resp.status)
+ * })
+ */
+ async submitFundingOffer (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const packet = (
+ payload instanceof FundingOffer
+ ? payload
+ : new FundingOffer(payload)
+ ).toNewOfferPacket()
+
+ if (this._affCode) {
+ packet.meta.aff_code = packet.meta.aff_code || this._affCode
+ }
+
+ this.send([0, 'fon', null, packet])
+ }
+
+ /**
+ * Cancels funding offer by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingOffer class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#closeFundingCredit
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingOffer|object|Array|number} payload - funding offer model,
+ * array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.cancelFundingOffer({ id: 1234 })
+ *
+ * ws.onFundingOfferClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding offer status: ', resp.status)
+ * })
+ */
+ cancelFundingOffer (payload) {
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'foc', null, { id }])
+ }
+
+ /**
+ * Cancels funding loan by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingLoan class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingCredit
+ *
+ * @param {FundingLoan|object|Array|number} payload - funding loan class,
+ * object literal, array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.closeFundingLoan({ id: 1234 })
+ *
+ * ws.onFundingLoanClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding loan status: ', resp.status)
+ * })
+ */
+ closeFundingLoan (payload) {
+ throw new Error('coming soon') // TODO: remove after socket input is implemented
+ // eslint-disable-next-line
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'flc', null, { id }])
+ }
+
+ /**
+ * Cancels funding credit by ID. Emits an error if not authenticated.
+ * The ID can be passed as a number, key/value pair object literal,
+ * an instance of FundingCredit class or an array
+ *
+ * @see WSv2#submitFundingOffer
+ * @see WSv2#cancelFundingOffer
+ * @see WSv2#closeFundingLoan
+ *
+ * @param {FundingCredit|object|Array|number} payload - funding credit class,
+ * object literal, array or ID to cancel
+ * @throws an error if not authenticated
+ * @example
+ * ws.closeFundingCredit({ id: 1234 })
+ *
+ * ws.onFundingCreditClose({ symbol: 'fUSD' }, (resp) => {
+ * console.log('Funding credit status: ', resp.status)
+ * })
+ */
+ closeFundingCredit (payload) {
+ throw new Error('coming soon') // TODO: remove after socket input is implemented
+ // eslint-disable-next-line
+ if (!this._isAuthenticated) {
+ throw new Error('not authenticated')
+ }
+
+ const id = _isNumber(payload)
+ ? payload
+ : Array.isArray(payload)
+ ? payload[0]
+ : payload.id
+
+ this.send([0, 'fcc', null, { id }])
+ }
+
/**
* Send a changeset to update an order in-place while maintaining position in
* the price queue. The changeset must contain the order ID, and supports a
diff --git a/package.json b/package.json
index 291d28f2..fbad1c12 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "bitfinex-api-node",
- "version": "4.0.14",
+ "version": "4.0.15",
"description": "Node reference library for Bitfinex API",
"engines": {
"node": ">=8.3.0"
diff --git a/test/lib/transports/ws2-integration.js b/test/lib/transports/ws2-integration.js
index 23d58abd..58bb76ab 100644
--- a/test/lib/transports/ws2-integration.js
+++ b/test/lib/transports/ws2-integration.js
@@ -4,7 +4,7 @@
const assert = require('assert')
const Promise = require('bluebird')
const WSv2 = require('../../../lib/transports/ws2')
-const { Order } = require('bfx-api-node-models')
+const { Order, FundingOffer } = require('bfx-api-node-models')
const { MockWSv2Server } = require('bfx-api-mock-srv')
const API_KEY = 'dummy'
@@ -224,6 +224,210 @@ describe('WSv2 integration', () => {
})
})
+ describe('submitFundingOffer', () => {
+ const testCases = {
+ 'as class instance': {
+ payload: new FundingOffer({
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '50',
+ rate: '0.001',
+ period: 2,
+ flags: 0
+ }),
+ expectedResult: {
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '50.00000000',
+ rate: '0.00100000',
+ period: 2,
+ flags: 0
+ }
+ },
+ 'as object literal': {
+ payload: {
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '60',
+ rate: '0.003',
+ period: 7,
+ flags: 0
+ },
+ expectedResult: {
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '60.00000000',
+ rate: '0.00300000',
+ period: 7,
+ flags: 0
+ }
+ },
+ 'as array': {
+ payload: [
+ null, 'fUSD', null, null, '55', null, 'LIMIT', null, null, 0,
+ null, null, null, null, '0.002', 4
+ ],
+ expectedResult: {
+ type: 'LIMIT',
+ symbol: 'fUSD',
+ amount: '55.00000000',
+ rate: '0.00200000',
+ period: 4,
+ flags: 0
+ }
+ }
+ }
+
+ Object.keys(testCases).forEach((scenario) => {
+ it(scenario, async () => {
+ let sentPackets = 0
+ wss = new MockWSv2Server()
+ ws = createTestWSv2Instance()
+
+ await ws.open()
+ await ws.auth()
+
+ ws._ws.send = (msgJSON) => {
+ const msg = JSON.parse(msgJSON)
+ assert.strictEqual(msg[1], 'fon')
+ assert.deepStrictEqual(msg[3], testCases[scenario].expectedResult)
+ sentPackets++
+ }
+
+ ws.submitFundingOffer(testCases[scenario].payload)
+ assert.strictEqual(sentPackets, 1)
+ })
+ })
+ })
+
+ describe('cancelFundingOffer', () => {
+ const testCases = {
+ 'as class instance': {
+ payload: new FundingOffer({ id: 123 }),
+ expectedResult: { id: 123 }
+ },
+ 'as object literal': {
+ payload: { id: 124 },
+ expectedResult: { id: 124 }
+ },
+ 'as number': {
+ payload: 125,
+ expectedResult: { id: 125 }
+ },
+ 'as array': {
+ payload: [126],
+ expectedResult: { id: 126 }
+ }
+ }
+
+ Object.keys(testCases).forEach((scenario) => {
+ it(scenario, async () => {
+ let sentPackets = 0
+ wss = new MockWSv2Server()
+ ws = createTestWSv2Instance()
+
+ await ws.open()
+ await ws.auth()
+
+ ws._ws.send = (msgJSON) => {
+ const msg = JSON.parse(msgJSON)
+ assert.strictEqual(msg[1], 'foc')
+ assert.deepStrictEqual(msg[3], testCases[scenario].expectedResult)
+ sentPackets++
+ }
+
+ ws.cancelFundingOffer(testCases[scenario].payload)
+ assert.strictEqual(sentPackets, 1)
+ })
+ })
+ })
+
+ // TODO: unskip when socket input is implemented
+ describe.skip('closeFundingLoan', () => {
+ const testCases = {
+ 'as class instance': {
+ payload: new FundingOffer({ id: 123 }),
+ expectedResult: { id: 123 }
+ },
+ 'as object literal': {
+ payload: { id: 124 },
+ expectedResult: { id: 124 }
+ },
+ 'as number': {
+ payload: 125,
+ expectedResult: { id: 125 }
+ },
+ 'as array': {
+ payload: [126],
+ expectedResult: { id: 126 }
+ }
+ }
+
+ Object.keys(testCases).forEach((scenario) => {
+ it(scenario, async () => {
+ let sentPackets = 0
+ wss = new MockWSv2Server()
+ ws = createTestWSv2Instance()
+
+ await ws.open()
+ await ws.auth()
+
+ ws._ws.send = (msgJSON) => {
+ const msg = JSON.parse(msgJSON)
+ assert.strictEqual(msg[1], 'flc')
+ assert.deepStrictEqual(msg[3], testCases[scenario].expectedResult)
+ sentPackets++
+ }
+
+ ws.closeFundingLoan(testCases[scenario].payload)
+ assert.strictEqual(sentPackets, 1)
+ })
+ })
+ })
+
+ // TODO: unskip when socket input is implemented
+ describe.skip('closeFundingCredit', () => {
+ const testCases = {
+ 'as class instance': {
+ payload: new FundingOffer({ id: 123 }),
+ expectedResult: { id: 123 }
+ },
+ 'as object literal': {
+ payload: { id: 124 },
+ expectedResult: { id: 124 }
+ },
+ 'as number': {
+ payload: 125,
+ expectedResult: { id: 125 }
+ },
+ 'as array': {
+ payload: [126],
+ expectedResult: { id: 126 }
+ }
+ }
+
+ Object.keys(testCases).forEach((scenario) => {
+ it(scenario, async () => {
+ let sentPackets = 0
+ wss = new MockWSv2Server()
+ ws = createTestWSv2Instance()
+
+ await ws.open()
+ await ws.auth()
+
+ ws._ws.send = (msgJSON) => {
+ const msg = JSON.parse(msgJSON)
+ assert.strictEqual(msg[1], 'fcc')
+ assert.deepStrictEqual(msg[3], testCases[scenario].expectedResult)
+ sentPackets++
+ }
+
+ ws.closeFundingCredit(testCases[scenario].payload)
+ assert.strictEqual(sentPackets, 1)
+ })
+ })
+ })
+
describe('listeners', () => {
it('manages listeners by cbGID', () => {
ws = createTestWSv2Instance()