@axis-markets/client 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/lib/axis-client.cjs +1 -1
- package/lib/axis-client.cjs.map +1 -1
- package/package.json +1 -1
- package/src/axis-market.js +23 -3
- package/src/index.d.ts +6 -3
package/package.json
CHANGED
package/src/axis-market.js
CHANGED
|
@@ -117,13 +117,16 @@ export class AxisMarket {
|
|
|
117
117
|
* Returns a snapshot, then updates on book changes
|
|
118
118
|
* @param {{base?: string, depth?: number, step?: string, limit?: number}} params
|
|
119
119
|
* @param {function(OrderbookDepth): void} callback
|
|
120
|
+
* @param {function(Error): void} [onError] - Called if the API refuses the subscription (see {@link refused})
|
|
120
121
|
* @return {function(): void} - Unsubscribe function
|
|
121
122
|
*/
|
|
122
|
-
subscribeDepth({base = this.base, depth, step, limit} = {}, callback) {
|
|
123
|
+
subscribeDepth({base = this.base, depth, step, limit} = {}, callback, onError) {
|
|
123
124
|
const market = base + '/' + this.counter(base)
|
|
124
125
|
return this.axis.stream.subscribe('depth', {market, depth, step, limit}, message => {
|
|
125
126
|
if (message.type === 'depth') {
|
|
126
127
|
callback(message.data)
|
|
128
|
+
} else {
|
|
129
|
+
refused(message, onError)
|
|
127
130
|
}
|
|
128
131
|
})
|
|
129
132
|
}
|
|
@@ -132,14 +135,17 @@ export class AxisMarket {
|
|
|
132
135
|
* Stream the market trades
|
|
133
136
|
* Returns a snapshot, then updates on trades
|
|
134
137
|
* @param {function(ApiTrade[], boolean): void} callback - Trades and whether they are the snapshot
|
|
138
|
+
* @param {function(Error): void} [onError] - Called if the API refuses the subscription (see {@link refused})
|
|
135
139
|
* @return {function(): void} - Unsubscribe function
|
|
136
140
|
*/
|
|
137
|
-
subscribeTrades(callback) {
|
|
141
|
+
subscribeTrades(callback, onError) {
|
|
138
142
|
return this.axis.stream.subscribe('trades', {market: this.key}, message => {
|
|
139
143
|
if (message.type === 'trades') {
|
|
140
144
|
callback(message.trades, true)
|
|
141
145
|
} else if (message.type === 'trade') {
|
|
142
146
|
callback([message.trade], false)
|
|
147
|
+
} else {
|
|
148
|
+
refused(message, onError)
|
|
143
149
|
}
|
|
144
150
|
})
|
|
145
151
|
}
|
|
@@ -149,15 +155,18 @@ export class AxisMarket {
|
|
|
149
155
|
* Returns a snapshot, then updates on trades
|
|
150
156
|
* @param {{base?: string, resolution: number|string, limit?: number}} params - `base` is the base asset of the view, `resolution` in seconds or an alias (`5m`, `1h`, …), `limit` the candles in the snapshot (200 by default, at most 200)
|
|
151
157
|
* @param {function(Candle[], boolean): void} callback - Candles
|
|
158
|
+
* @param {function(Error): void} [onError] - Called if the API refuses the subscription (see {@link refused})
|
|
152
159
|
* @return {function(): void} - Unsubscribe function
|
|
153
160
|
*/
|
|
154
|
-
subscribeCandles({base = this.base, resolution, limit}, callback) {
|
|
161
|
+
subscribeCandles({base = this.base, resolution, limit}, callback, onError) {
|
|
155
162
|
const market = base + '/' + this.counter(base)
|
|
156
163
|
return this.axis.stream.subscribe('candles', {market, resolution, limit}, message => {
|
|
157
164
|
if (message.type === 'candles') {
|
|
158
165
|
callback(message.candles, true)
|
|
159
166
|
} else if (message.type === 'candle') {
|
|
160
167
|
callback([message.candle], false)
|
|
168
|
+
} else {
|
|
169
|
+
refused(message, onError)
|
|
161
170
|
}
|
|
162
171
|
})
|
|
163
172
|
}
|
|
@@ -175,6 +184,17 @@ export class AxisMarket {
|
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Report a subscription the API refused. The stream drops a refused subscription, the caller subscribes again to retry.
|
|
189
|
+
* @param {StreamMessage} message
|
|
190
|
+
* @param {function(Error): void} [onError]
|
|
191
|
+
*/
|
|
192
|
+
function refused(message, onError) {
|
|
193
|
+
if (message.type === 'error') {
|
|
194
|
+
onError?.(new Error(message.error))
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
178
198
|
/**
|
|
179
199
|
* @typedef {{}} Signer - Account signing contract calls
|
|
180
200
|
* @property {string} publicKey - Transaction source account
|
package/src/index.d.ts
CHANGED
|
@@ -1405,24 +1405,27 @@ export declare class AxisMarket {
|
|
|
1405
1405
|
/**
|
|
1406
1406
|
* Stream the orderbook depth
|
|
1407
1407
|
* Returns a snapshot, then updates on book changes
|
|
1408
|
+
* @param onError - Called if the API refuses the subscription, which is then dropped (subscribe again to retry)
|
|
1408
1409
|
* @returns Unsubscribe function
|
|
1409
1410
|
*/
|
|
1410
|
-
subscribeDepth(params: {base?: string, depth?: number, step?: string, limit?: number}, callback: (depth: OrderbookDepth) => void): () => void;
|
|
1411
|
+
subscribeDepth(params: {base?: string, depth?: number, step?: string, limit?: number}, callback: (depth: OrderbookDepth) => void, onError?: (error: Error) => void): () => void;
|
|
1411
1412
|
/**
|
|
1412
1413
|
* Stream the market trades
|
|
1413
1414
|
* Returns a snapshot, then updates on trades
|
|
1414
1415
|
* @param callback - Trades and whether they are the snapshot
|
|
1416
|
+
* @param onError - Called if the API refuses the subscription, which is then dropped (subscribe again to retry)
|
|
1415
1417
|
* @returns Unsubscribe function
|
|
1416
1418
|
*/
|
|
1417
|
-
subscribeTrades(callback: (trades: ApiTrade[], snapshot: boolean) => void): () => void;
|
|
1419
|
+
subscribeTrades(callback: (trades: ApiTrade[], snapshot: boolean) => void, onError?: (error: Error) => void): () => void;
|
|
1418
1420
|
/**
|
|
1419
1421
|
* Stream the market candles
|
|
1420
1422
|
* Returns a snapshot, then updates on trades
|
|
1421
1423
|
* @param params - `base` is the base asset of the view, `resolution` in seconds or an alias (`5m`, `1h`, …), `limit` the candles in the snapshot (200 by default, at most 200)
|
|
1422
1424
|
* @param callback - Candles
|
|
1425
|
+
* @param onError - Called if the API refuses the subscription, which is then dropped (subscribe again to retry)
|
|
1423
1426
|
* @returns Unsubscribe function
|
|
1424
1427
|
*/
|
|
1425
|
-
subscribeCandles(params: {base?: string, resolution: number | string, limit?: number}, callback: (candles: Candle[], snapshot: boolean) => void): () => void;
|
|
1428
|
+
subscribeCandles(params: {base?: string, resolution: number | string, limit?: number}, callback: (candles: Candle[], snapshot: boolean) => void, onError?: (error: Error) => void): () => void;
|
|
1426
1429
|
}
|
|
1427
1430
|
|
|
1428
1431
|
/** Open order of a tracked account */
|