@axis-markets/client 0.9.2 → 0.9.4
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/api-client.js +506 -506
- package/src/axis-account.js +6 -2
- package/src/axis-market.js +23 -3
- package/src/index.d.ts +9 -6
package/src/axis-account.js
CHANGED
|
@@ -811,6 +811,10 @@ export class AxisAccount extends Emitter {
|
|
|
811
811
|
this.removed.set(key, until)
|
|
812
812
|
}
|
|
813
813
|
} else if (current) {
|
|
814
|
+
//a new price or amount is a new version of the order that nothing has filled yet
|
|
815
|
+
if (update.price !== current.price || update.amount !== current.amount) {
|
|
816
|
+
Object.assign(current, {quote: update.amount, filledPct: 0})
|
|
817
|
+
}
|
|
814
818
|
Object.assign(current, {amount: update.amount, price: update.price, expires: Number(update.expires)})
|
|
815
819
|
}
|
|
816
820
|
}
|
|
@@ -1279,7 +1283,7 @@ function newestFirst(x, y) {
|
|
|
1279
1283
|
* @property {'ACTIVE'|'FILLED'|'CANCELED'|'EXPIRED'} status - Current status
|
|
1280
1284
|
* @property {bigint} price - `buying` per 1 `selling`, contract scale (18 decimals)
|
|
1281
1285
|
* @property {bigint} amount - Amount of `selling` left
|
|
1282
|
-
* @property {bigint} quote -
|
|
1286
|
+
* @property {bigint} quote - Original `selling` amount
|
|
1283
1287
|
* @property {number} expires - Expiration UNIX timestamp in seconds, 0 = none
|
|
1284
1288
|
* @property {number} created - Creation time, UNIX milliseconds
|
|
1285
1289
|
* @property {number} updated - Last change, UNIX milliseconds
|
|
@@ -1287,7 +1291,7 @@ function newestFirst(x, y) {
|
|
|
1287
1291
|
* @property {bigint|null} backed - Share of the account budget in `selling` that backs the order
|
|
1288
1292
|
* @property {number|null} backedPct - `backed / amount` (0..1), null when unknown
|
|
1289
1293
|
* @property {boolean} backingPending - The backing is not confirmed yet
|
|
1290
|
-
* @property {number} filledPct - Filled share of
|
|
1294
|
+
* @property {number} filledPct - Filled share of `quote` (0..1)
|
|
1291
1295
|
* @property {boolean} pending - Created by this client, not reported by the indexer yet
|
|
1292
1296
|
*/
|
|
1293
1297
|
|
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
|
@@ -825,7 +825,7 @@ export interface ApiOrder {
|
|
|
825
825
|
price: string;
|
|
826
826
|
/** Rational price representation */
|
|
827
827
|
rprice: string;
|
|
828
|
-
/**
|
|
828
|
+
/** Original selling amount */
|
|
829
829
|
quote: string;
|
|
830
830
|
/** Amount left to sell */
|
|
831
831
|
amount: string;
|
|
@@ -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 */
|
|
@@ -1443,7 +1446,7 @@ export interface AccountOrder {
|
|
|
1443
1446
|
price: bigint;
|
|
1444
1447
|
/** Amount of `selling` left */
|
|
1445
1448
|
amount: bigint;
|
|
1446
|
-
/**
|
|
1449
|
+
/** Original selling amount */
|
|
1447
1450
|
quote: bigint;
|
|
1448
1451
|
/** Expiration UNIX timestamp in seconds, 0 = none */
|
|
1449
1452
|
expires: number;
|
|
@@ -1459,7 +1462,7 @@ export interface AccountOrder {
|
|
|
1459
1462
|
backedPct: number | null;
|
|
1460
1463
|
/** The backing is not confirmed yet */
|
|
1461
1464
|
backingPending: boolean;
|
|
1462
|
-
/** Filled share of
|
|
1465
|
+
/** Filled share of `quote` (0..1) */
|
|
1463
1466
|
filledPct: number;
|
|
1464
1467
|
/** Created by this client, not reported by the indexer yet */
|
|
1465
1468
|
pending: boolean;
|