@injectivelabs/sdk-ts 1.17.2-alpha.1 → 1.17.2-alpha.10
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/dist/cjs/{ChainGrpcExchangeApi-BtyGj9nz.cjs → ChainGrpcExchangeApi-DLpkgEyg.cjs} +2 -2
- package/dist/cjs/{ChainRestTendermintApi-QfW64O3w.cjs → ChainRestTendermintApi-BiZOeKcG.cjs} +1 -1
- package/dist/cjs/{DirectEthSecp256k1Wallet-DoKnf40T.cjs → DirectEthSecp256k1Wallet-CU18lti3.cjs} +2 -2
- package/dist/cjs/{ExecArgNeptuneWithdraw-Bq-vm03i.cjs → ExecArgNeptuneWithdraw-DOHeo3AJ.cjs} +6 -6
- package/dist/cjs/{IndexerGrpcWeb3GwApi-DqzAO5JM.cjs → IndexerGrpcWeb3GwApi-BgWT2tWK.cjs} +6 -6
- package/dist/cjs/{MsgBase-BJ1-Qh5c.cjs → MsgBase-DqOmzCyS.cjs} +1 -0
- package/dist/cjs/{MsgSetDenomMetadata-DRNtJ4-D.cjs → MsgSetDenomMetadata-CUoGqV8P.cjs} +9 -9
- package/dist/cjs/{QueryTradingStrategyContractTotalStrategies-C9cHGYOE.cjs → QueryTradingStrategyContractTotalStrategies-Bh8AXm4k.cjs} +3 -3
- package/dist/cjs/{IndexerGrpcAccountPortfolioStream-DeTA0ie2.cjs → StreamManager-ikNObdr-.cjs} +1257 -278
- package/dist/cjs/{accounts-D7eN2BGD.cjs → accounts-CXaUasU5.cjs} +9 -8
- package/dist/cjs/{any_pb-CP-3DVyl.d.cts → any_pb-CutLnOUR.d.cts} +2 -2
- package/dist/cjs/{chain--FmH8auB.cjs → chain-Cs9sNuT1.cjs} +2 -2
- package/dist/cjs/client/chain.cjs +4 -4
- package/dist/cjs/client/chain.d.cts +7 -7
- package/dist/cjs/client/indexer.cjs +72 -58
- package/dist/cjs/client/indexer.d.cts +8 -8
- package/dist/cjs/client/olp.d.cts +1 -1
- package/dist/cjs/client/wasm.cjs +7 -7
- package/dist/cjs/client/wasm.d.cts +2 -2
- package/dist/cjs/core/accounts.cjs +3 -3
- package/dist/cjs/core/accounts.d.cts +7 -7
- package/dist/cjs/core/modules.cjs +9 -9
- package/dist/cjs/core/modules.d.cts +7 -7
- package/dist/cjs/core/tx.cjs +6 -6
- package/dist/cjs/core/tx.d.cts +7 -7
- package/dist/cjs/cosmjs.cjs +7 -7
- package/dist/cjs/cosmjs.d.cts +3 -3
- package/dist/cjs/exports.cjs +7 -7
- package/dist/cjs/exports.d.cts +3 -3
- package/dist/cjs/{index-Cqfc1ppG.d.cts → index-B1AYbshM.d.cts} +223 -19
- package/dist/cjs/{index-D4uWOVE5.d.cts → index-B8XmWgDc.d.cts} +5 -5
- package/dist/cjs/{index-Cc4mqAsR.d.cts → index-D6ubyMlR.d.cts} +1 -1
- package/dist/cjs/{index-9KV6P3U_.d.cts → index-DDQzXOux.d.cts} +933 -154
- package/dist/cjs/{index-CKBod1ba.d.cts → index-D__cYp7U.d.cts} +3 -2
- package/dist/cjs/{index-Cc5Q73-y.d.cts → index-FEXnDdOc.d.cts} +1 -1
- package/dist/cjs/index.cjs +89 -68
- package/dist/cjs/index.d.cts +8 -8
- package/dist/cjs/{service-BsjIvzFh.cjs → service-yA6fSem8.cjs} +2 -2
- package/dist/cjs/service.cjs +3 -3
- package/dist/cjs/service.d.cts +4 -4
- package/dist/cjs/{tx-BXz2UdNK.cjs → tx-Cn0j2SRh.cjs} +4 -4
- package/dist/{esm/tx_pb-TiSRD5ay.d.ts → cjs/tx_pb-D-cNmrlO.d.cts} +4 -3
- package/dist/cjs/{types-NFV4P_J_.cjs → types-DvoTS2v1.cjs} +104 -7
- package/dist/cjs/types.cjs +6 -1
- package/dist/cjs/types.d.cts +4 -4
- package/dist/cjs/{utils-WpVZ-fdd.cjs → utils-V1uXtT51.cjs} +120 -88
- package/dist/cjs/utils.cjs +3 -1
- package/dist/cjs/utils.d.cts +8 -8
- package/dist/esm/{ChainGrpcExchangeApi-C2PzFFLo.js → ChainGrpcExchangeApi-C-2XsVVs.js} +2 -2
- package/dist/esm/{ChainRestTendermintApi-iWnboboL.js → ChainRestTendermintApi-CMrAg0Zm.js} +1 -1
- package/dist/esm/{DirectEthSecp256k1Wallet-3qFMEHzf.js → DirectEthSecp256k1Wallet-a9KiF9fA.js} +2 -2
- package/dist/esm/{ExecArgNeptuneWithdraw-D_zdRFlV.js → ExecArgNeptuneWithdraw-DEljIeLd.js} +6 -6
- package/dist/esm/{IndexerGrpcWeb3GwApi-C82holuJ.js → IndexerGrpcWeb3GwApi-CtUYowus.js} +6 -6
- package/dist/esm/{MsgBase-aKq3ln6R.js → MsgBase-BkRgVbdY.js} +1 -0
- package/dist/esm/{MsgSetDenomMetadata-WwlO0X1r.js → MsgSetDenomMetadata-BhJMebO9.js} +9 -9
- package/dist/esm/{QueryTradingStrategyContractTotalStrategies-Bov-bhFt.js → QueryTradingStrategyContractTotalStrategies-7IjWZLsc.js} +3 -3
- package/dist/esm/{IndexerGrpcAccountPortfolioStream-CxK8ZbH1.js → StreamManager-Bz2mGjMt.js} +926 -31
- package/dist/esm/{accounts-B8PWTc1V.js → accounts-DFC9RYDH.js} +9 -8
- package/dist/esm/{any_pb-B1YYUSUf.d.ts → any_pb-DBt7qvTr.d.ts} +2 -2
- package/dist/esm/{chain-B93GTjUS.js → chain-phKWVf8c.js} +2 -2
- package/dist/esm/client/chain.d.ts +7 -7
- package/dist/esm/client/chain.js +4 -4
- package/dist/esm/client/indexer.d.ts +8 -8
- package/dist/esm/client/indexer.js +5 -5
- package/dist/esm/client/olp.d.ts +1 -1
- package/dist/esm/client/wasm.d.ts +2 -2
- package/dist/esm/client/wasm.js +7 -7
- package/dist/esm/core/accounts.d.ts +7 -7
- package/dist/esm/core/accounts.js +3 -3
- package/dist/esm/core/modules.d.ts +7 -7
- package/dist/esm/core/modules.js +9 -9
- package/dist/esm/core/tx.d.ts +7 -7
- package/dist/esm/core/tx.js +6 -6
- package/dist/esm/cosmjs.d.ts +3 -3
- package/dist/esm/cosmjs.js +7 -7
- package/dist/esm/exports.d.ts +3 -3
- package/dist/esm/exports.js +7 -7
- package/dist/esm/{index-BOKuUpVZ.d.ts → index--sg5xbEP.d.ts} +1 -1
- package/dist/esm/{index-aNMYd-s0.d.ts → index-BoEe6weX.d.ts} +3 -2
- package/dist/esm/{index-CIU3qLo9.d.ts → index-DSY58vw-.d.ts} +949 -170
- package/dist/esm/{index-DS6aJrL5.d.ts → index-DgYt7OQg.d.ts} +1 -1
- package/dist/esm/{index-DdGVE3_u.d.ts → index-GcFVWcCn.d.ts} +5 -5
- package/dist/esm/{index-B1R417vW.d.ts → index-mAmKmwGY.d.ts} +223 -19
- package/dist/esm/index.d.ts +8 -8
- package/dist/esm/index.js +15 -15
- package/dist/esm/{service-DsZ0vnDP.js → service-B_k552b0.js} +2 -2
- package/dist/esm/service.d.ts +4 -4
- package/dist/esm/service.js +3 -3
- package/dist/esm/{tx-C1AZz6w-.js → tx-CcaVBSym.js} +4 -4
- package/dist/{cjs/tx_pb-tECSPcSB.d.cts → esm/tx_pb-zz4o4hHG.d.ts} +4 -3
- package/dist/esm/types-Bu8IAJ0R.js +137 -0
- package/dist/esm/types.d.ts +4 -4
- package/dist/esm/types.js +2 -2
- package/dist/esm/{utils-BaRG9oyg.js → utils-DwGoPRTL.js} +111 -90
- package/dist/esm/utils.d.ts +8 -8
- package/dist/esm/utils.js +2 -2
- package/package.json +17 -17
- package/dist/esm/types-Cq0sRR6y.js +0 -70
package/dist/esm/{IndexerGrpcAccountPortfolioStream-CxK8ZbH1.js → StreamManager-Bz2mGjMt.js}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Jt as uint8ArrayToString, a as grpcPagingToPagingV2, en as isJsonString } from "./utils-DwGoPRTL.js";
|
|
2
2
|
import { t as _defineProperty } from "./defineProperty-Bq6QU9Te.js";
|
|
3
3
|
import { n as GrpcWebRpcTransport } from "./BaseGrpcConsumer-DptVGP0n.js";
|
|
4
4
|
import { t as BaseIndexerGrpcConsumer } from "./BaseIndexerGrpcConsumer-CjpUoGXy.js";
|
|
5
5
|
import { t as BaseRestConsumer } from "./BaseRestConsumer-rK4eS4W8.js";
|
|
6
|
-
import { r as IndexerModule } from "./IndexerGrpcWeb3GwApi-
|
|
7
|
-
import { a as
|
|
6
|
+
import { r as IndexerModule } from "./IndexerGrpcWeb3GwApi-CtUYowus.js";
|
|
7
|
+
import { a as TradeDirection, c as StreamDisconnectReason, f as TokenType, i as OrderState, l as StreamEvent, p as TokenVerification, t as StreamOperation, u as StreamState } from "./types-Bu8IAJ0R.js";
|
|
8
8
|
import { BigNumber, toBigNumber, toHumanReadable } from "@injectivelabs/utils";
|
|
9
9
|
import { GeneralException, HttpRequestException, UnspecifiedErrorCode } from "@injectivelabs/exceptions";
|
|
10
|
-
import { OrderState, StreamOperation, TradeDirection } from "@injectivelabs/ts-types";
|
|
11
10
|
import { MitoAPIClient } from "@injectivelabs/mito-proto-ts-v2/generated/goadesign_goagen_mito_api_pb.client";
|
|
12
11
|
import * as GoadesignGoagenMitoApiPb from "@injectivelabs/mito-proto-ts-v2/generated/goadesign_goagen_mito_api_pb";
|
|
13
12
|
import * as InjectiveMetaRpcPb from "@injectivelabs/indexer-proto-ts-v2/generated/injective_meta_rpc_pb";
|
|
@@ -38,6 +37,7 @@ import * as InjectivePortfolioRpcPb from "@injectivelabs/indexer-proto-ts-v2/gen
|
|
|
38
37
|
import { InjectivePortfolioRPCClient } from "@injectivelabs/indexer-proto-ts-v2/generated/injective_portfolio_rpc_pb.client";
|
|
39
38
|
import * as InjectiveInsuranceRpcPb from "@injectivelabs/indexer-proto-ts-v2/generated/injective_insurance_rpc_pb";
|
|
40
39
|
import { InjectiveInsuranceRPCClient } from "@injectivelabs/indexer-proto-ts-v2/generated/injective_insurance_rpc_pb.client";
|
|
40
|
+
import { EventEmitter } from "eventemitter3";
|
|
41
41
|
|
|
42
42
|
//#region src/client/indexer/transformers/IndexerCommonTransformer.ts
|
|
43
43
|
var IndexerCommonTransformer = class {
|
|
@@ -1710,7 +1710,7 @@ var IndexerGrpcReferralTransformer = class {
|
|
|
1710
1710
|
var IndexerOracleStreamTransformer = class {};
|
|
1711
1711
|
_defineProperty(IndexerOracleStreamTransformer, "pricesStreamCallback", (response) => ({
|
|
1712
1712
|
price: response.price,
|
|
1713
|
-
operation: StreamOperation
|
|
1713
|
+
operation: StreamOperation.Update,
|
|
1714
1714
|
timestamp: typeof response.timestamp === "bigint" ? Number(response.timestamp) : parseInt(response.timestamp, 10)
|
|
1715
1715
|
}));
|
|
1716
1716
|
_defineProperty(IndexerOracleStreamTransformer, "pricesByMarketsCallback", (response) => ({ ...response }));
|
|
@@ -1949,7 +1949,7 @@ _defineProperty(IndexerAccountStreamTransformer, "balanceStreamCallback", (respo
|
|
|
1949
1949
|
const balance = response.balance;
|
|
1950
1950
|
return {
|
|
1951
1951
|
balance: balance ? IndexerGrpcAccountTransformer.grpcBalanceToBalance(balance) : void 0,
|
|
1952
|
-
operation: StreamOperation
|
|
1952
|
+
operation: StreamOperation.Update,
|
|
1953
1953
|
timestamp: response.timestamp
|
|
1954
1954
|
};
|
|
1955
1955
|
});
|
|
@@ -2185,7 +2185,7 @@ _defineProperty(IndexerArchiverStreamTransformer, "spotAverageEntriesStreamCallb
|
|
|
2185
2185
|
const averageEntry = response.averageEntry;
|
|
2186
2186
|
return {
|
|
2187
2187
|
averageEntry: averageEntry ? IndexerGrpcArchiverTransformer.grpcSpotAverageEntryToSpotAverageEntry(averageEntry) : void 0,
|
|
2188
|
-
operation: StreamOperation
|
|
2188
|
+
operation: StreamOperation.Update,
|
|
2189
2189
|
timestamp: typeof response.timestamp === "bigint" ? Number(response.timestamp) : response.timestamp
|
|
2190
2190
|
};
|
|
2191
2191
|
});
|
|
@@ -2198,15 +2198,15 @@ _defineProperty(IndexerArchiverStreamTransformer, "spotAverageEntriesStreamCallb
|
|
|
2198
2198
|
var ExplorerStreamTransformer = class {};
|
|
2199
2199
|
_defineProperty(ExplorerStreamTransformer, "blocksStreamCallback", (response) => ({
|
|
2200
2200
|
block: IndexerGrpcExplorerTransformer.grpcBlockToBlock(response),
|
|
2201
|
-
operation: StreamOperation
|
|
2201
|
+
operation: StreamOperation.Insert
|
|
2202
2202
|
}));
|
|
2203
2203
|
_defineProperty(ExplorerStreamTransformer, "blocksWithTxsStreamCallback", (response) => ({
|
|
2204
2204
|
block: IndexerGrpcExplorerTransformer.grpcBlockToBlockWithTxs(response),
|
|
2205
|
-
operation: StreamOperation
|
|
2205
|
+
operation: StreamOperation.Insert
|
|
2206
2206
|
}));
|
|
2207
2207
|
_defineProperty(ExplorerStreamTransformer, "transactionsStreamCallback", (response) => ({
|
|
2208
2208
|
block: IndexerGrpcExplorerTransformer.streamTxResponseToTxs(response),
|
|
2209
|
-
operation: StreamOperation
|
|
2209
|
+
operation: StreamOperation.Insert
|
|
2210
2210
|
}));
|
|
2211
2211
|
|
|
2212
2212
|
//#endregion
|
|
@@ -4616,7 +4616,7 @@ var IndexerRestLeaderboardChronosApi = class extends BaseRestConsumer {
|
|
|
4616
4616
|
};
|
|
4617
4617
|
|
|
4618
4618
|
//#endregion
|
|
4619
|
-
//#region src/client/indexer/grpc_stream/streamHelpers.ts
|
|
4619
|
+
//#region src/client/indexer/grpc_stream/stream/streamHelpers.ts
|
|
4620
4620
|
/**
|
|
4621
4621
|
* Creates a subscription wrapper for V2 streaming with proper cancellation support.
|
|
4622
4622
|
*
|
|
@@ -4650,7 +4650,7 @@ function createStreamSubscription(stream, handleResponse, onEndCallback, onStatu
|
|
|
4650
4650
|
}
|
|
4651
4651
|
|
|
4652
4652
|
//#endregion
|
|
4653
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcSpotStream.ts
|
|
4653
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcSpotStream.ts
|
|
4654
4654
|
/**
|
|
4655
4655
|
* @category Indexer Grpc Stream
|
|
4656
4656
|
* @description Provides streaming access to spot market data from Injective Indexer
|
|
@@ -4662,9 +4662,9 @@ var IndexerGrpcSpotStream = class {
|
|
|
4662
4662
|
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
4663
4663
|
this.client = new InjectiveSpotExchangeRPCClient(this.transport);
|
|
4664
4664
|
}
|
|
4665
|
-
/** @deprecated - use
|
|
4666
|
-
|
|
4667
|
-
throw new GeneralException(/* @__PURE__ */ new Error("deprecated - use
|
|
4665
|
+
/** @deprecated - use streamOrderbookV2 */
|
|
4666
|
+
streamOrderbook(_args) {
|
|
4667
|
+
throw new GeneralException(/* @__PURE__ */ new Error("deprecated - use streamOrderbookV2"));
|
|
4668
4668
|
}
|
|
4669
4669
|
/**
|
|
4670
4670
|
* Stream spot orders
|
|
@@ -4677,7 +4677,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4677
4677
|
* @param params.onStatusCallback - Called on stream errors
|
|
4678
4678
|
* @returns Subscription object with unsubscribe method
|
|
4679
4679
|
*/
|
|
4680
|
-
|
|
4680
|
+
streamOrders({ marketId, subaccountId, orderSide, callback, onEndCallback, onStatusCallback }) {
|
|
4681
4681
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4682
4682
|
const request = InjectiveSpotExchangeRpcPb.StreamOrdersRequest.create();
|
|
4683
4683
|
if (marketId) request.marketId = marketId;
|
|
@@ -4701,7 +4701,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4701
4701
|
* @param params.onStatusCallback - Called on stream errors
|
|
4702
4702
|
* @returns Subscription object with unsubscribe method
|
|
4703
4703
|
*/
|
|
4704
|
-
|
|
4704
|
+
streamOrderHistory({ marketId, subaccountId, orderTypes, executionTypes, direction, state, callback, onEndCallback, onStatusCallback }) {
|
|
4705
4705
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4706
4706
|
const request = InjectiveSpotExchangeRpcPb.StreamOrdersHistoryRequest.create();
|
|
4707
4707
|
if (subaccountId) request.subaccountId = subaccountId;
|
|
@@ -4729,7 +4729,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4729
4729
|
* @param params.onStatusCallback - Called on stream errors
|
|
4730
4730
|
* @returns Subscription object with unsubscribe method
|
|
4731
4731
|
*/
|
|
4732
|
-
|
|
4732
|
+
streamTrades({ marketIds, marketId, subaccountIds, subaccountId, pagination, direction, executionSide, callback, onEndCallback, onStatusCallback }) {
|
|
4733
4733
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4734
4734
|
const request = InjectiveSpotExchangeRpcPb.StreamTradesRequest.create();
|
|
4735
4735
|
if (marketIds) request.marketIds = marketIds;
|
|
@@ -4755,7 +4755,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4755
4755
|
* @param params.onStatusCallback - Called on stream errors
|
|
4756
4756
|
* @returns Subscription object with unsubscribe method
|
|
4757
4757
|
*/
|
|
4758
|
-
|
|
4758
|
+
streamMarkets({ marketIds, callback, onEndCallback, onStatusCallback }) {
|
|
4759
4759
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4760
4760
|
const request = InjectiveSpotExchangeRpcPb.StreamMarketsRequest.create();
|
|
4761
4761
|
if (marketIds) request.marketIds = marketIds;
|
|
@@ -4772,7 +4772,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4772
4772
|
* @param params.onStatusCallback - Called on stream errors
|
|
4773
4773
|
* @returns Subscription object with unsubscribe method
|
|
4774
4774
|
*/
|
|
4775
|
-
|
|
4775
|
+
streamOrderbooksV2({ marketIds, callback, onEndCallback, onStatusCallback }) {
|
|
4776
4776
|
if (!marketIds || marketIds.length === 0) throw new Error("marketIds is required and cannot be empty");
|
|
4777
4777
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4778
4778
|
const request = InjectiveSpotExchangeRpcPb.StreamOrderbookV2Request.create();
|
|
@@ -4790,7 +4790,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4790
4790
|
* @param params.onStatusCallback - Called on stream errors
|
|
4791
4791
|
* @returns Subscription object with unsubscribe method
|
|
4792
4792
|
*/
|
|
4793
|
-
|
|
4793
|
+
streamOrderbookUpdates({ marketIds, callback, onEndCallback, onStatusCallback }) {
|
|
4794
4794
|
if (!marketIds || marketIds.length === 0) throw new Error("marketIds is required and cannot be empty");
|
|
4795
4795
|
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
4796
4796
|
const request = InjectiveSpotExchangeRpcPb.StreamOrderbookUpdateRequest.create();
|
|
@@ -4802,7 +4802,7 @@ var IndexerGrpcSpotStream = class {
|
|
|
4802
4802
|
};
|
|
4803
4803
|
|
|
4804
4804
|
//#endregion
|
|
4805
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcMitoStream.ts
|
|
4805
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcMitoStream.ts
|
|
4806
4806
|
/**
|
|
4807
4807
|
* @category Indexer Grpc Stream
|
|
4808
4808
|
* @description Provides streaming access to Mito vault data from Injective Indexer
|
|
@@ -4917,7 +4917,7 @@ var IndexerGrpcMitoStream = class {
|
|
|
4917
4917
|
};
|
|
4918
4918
|
|
|
4919
4919
|
//#endregion
|
|
4920
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcOracleStream.ts
|
|
4920
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcOracleStream.ts
|
|
4921
4921
|
/**
|
|
4922
4922
|
* @category Indexer Grpc Stream
|
|
4923
4923
|
* @description Provides streaming access to oracle price data from Injective Indexer
|
|
@@ -4971,7 +4971,7 @@ var IndexerGrpcOracleStream = class {
|
|
|
4971
4971
|
};
|
|
4972
4972
|
|
|
4973
4973
|
//#endregion
|
|
4974
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcAccountStream.ts
|
|
4974
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcAccountStream.ts
|
|
4975
4975
|
/**
|
|
4976
4976
|
* @category Indexer Grpc Stream
|
|
4977
4977
|
* @description Provides streaming access to account data from the Injective Indexer
|
|
@@ -5004,7 +5004,7 @@ var IndexerGrpcAccountStream = class {
|
|
|
5004
5004
|
};
|
|
5005
5005
|
|
|
5006
5006
|
//#endregion
|
|
5007
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcAuctionStream.ts
|
|
5007
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcAuctionStream.ts
|
|
5008
5008
|
/**
|
|
5009
5009
|
* @category Indexer Grpc Stream
|
|
5010
5010
|
* @description Provides streaming access to auction data from Injective Indexer
|
|
@@ -5034,7 +5034,7 @@ var IndexerGrpcAuctionStream = class {
|
|
|
5034
5034
|
};
|
|
5035
5035
|
|
|
5036
5036
|
//#endregion
|
|
5037
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcTradingStream.ts
|
|
5037
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcTradingStream.ts
|
|
5038
5038
|
/**
|
|
5039
5039
|
* @category Indexer Grid Strategy Grpc Stream
|
|
5040
5040
|
* @description Provides streaming access to grid strategy data from Injective Indexer
|
|
@@ -5069,7 +5069,7 @@ var IndexerGrpcTradingStream = class {
|
|
|
5069
5069
|
};
|
|
5070
5070
|
|
|
5071
5071
|
//#endregion
|
|
5072
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcArchiverStream.ts
|
|
5072
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcArchiverStream.ts
|
|
5073
5073
|
/**
|
|
5074
5074
|
* @category Indexer Grpc Stream
|
|
5075
5075
|
* @description Provides streaming access to archiver data from Injective Indexer
|
|
@@ -5102,7 +5102,7 @@ var IndexerGrpcArchiverStream = class {
|
|
|
5102
5102
|
};
|
|
5103
5103
|
|
|
5104
5104
|
//#endregion
|
|
5105
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcExplorerStream.ts
|
|
5105
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcExplorerStream.ts
|
|
5106
5106
|
/**
|
|
5107
5107
|
* @category Indexer Grpc Stream
|
|
5108
5108
|
* @description Provides streaming access to blockchain explorer data from Injective Indexer
|
|
@@ -5162,7 +5162,7 @@ var IndexerGrpcExplorerStream = class {
|
|
|
5162
5162
|
};
|
|
5163
5163
|
|
|
5164
5164
|
//#endregion
|
|
5165
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcDerivativesStream.ts
|
|
5165
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcDerivativesStream.ts
|
|
5166
5166
|
/**
|
|
5167
5167
|
* @category Indexer Grpc Stream
|
|
5168
5168
|
* @description Provides streaming access to derivatives market data from Injective Indexer
|
|
@@ -5352,7 +5352,7 @@ var IndexerGrpcDerivativesStream = class {
|
|
|
5352
5352
|
};
|
|
5353
5353
|
|
|
5354
5354
|
//#endregion
|
|
5355
|
-
//#region src/client/indexer/grpc_stream/IndexerGrpcAccountPortfolioStream.ts
|
|
5355
|
+
//#region src/client/indexer/grpc_stream/stream/IndexerGrpcAccountPortfolioStream.ts
|
|
5356
5356
|
/**
|
|
5357
5357
|
* @category Indexer Grpc Stream
|
|
5358
5358
|
* @description Provides streaming access to account portfolio data from Injective Indexer
|
|
@@ -5389,4 +5389,899 @@ var IndexerGrpcAccountPortfolioStream = class {
|
|
|
5389
5389
|
};
|
|
5390
5390
|
|
|
5391
5391
|
//#endregion
|
|
5392
|
-
|
|
5392
|
+
//#region src/client/indexer/grpc_stream/stream/StreamManager.ts
|
|
5393
|
+
/**
|
|
5394
|
+
* StreamManager - Simple registry for managing multiple V1 stream subscriptions by key
|
|
5395
|
+
*
|
|
5396
|
+
* This is a lightweight utility for storing and canceling multiple V1 RxJS-based streams.
|
|
5397
|
+
* For V2 streams with advanced lifecycle management and retry logic, use StreamManagerV2.
|
|
5398
|
+
*/
|
|
5399
|
+
var StreamManager = class {
|
|
5400
|
+
constructor() {
|
|
5401
|
+
_defineProperty(this, "streams", /* @__PURE__ */ new Map());
|
|
5402
|
+
}
|
|
5403
|
+
set(stream, streamKey) {
|
|
5404
|
+
if (this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} already exists`);
|
|
5405
|
+
this.streams.set(streamKey, stream);
|
|
5406
|
+
}
|
|
5407
|
+
get(streamKey) {
|
|
5408
|
+
if (!this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} is not found`);
|
|
5409
|
+
return this.streams.get(streamKey);
|
|
5410
|
+
}
|
|
5411
|
+
exists(streamKey) {
|
|
5412
|
+
return this.streams.has(streamKey);
|
|
5413
|
+
}
|
|
5414
|
+
cancelAll() {
|
|
5415
|
+
this.streams.forEach((stream) => {
|
|
5416
|
+
stream.cancel();
|
|
5417
|
+
});
|
|
5418
|
+
this.streams = /* @__PURE__ */ new Map();
|
|
5419
|
+
}
|
|
5420
|
+
cancel(streamKey) {
|
|
5421
|
+
if (!this.streams.has(streamKey)) throw new Error(`Stream ${streamKey} is not found`);
|
|
5422
|
+
this.streams.get(streamKey).cancel();
|
|
5423
|
+
this.streams.delete(streamKey);
|
|
5424
|
+
}
|
|
5425
|
+
cancelIfExists(streamKey) {
|
|
5426
|
+
if (!this.streams.has(streamKey)) return;
|
|
5427
|
+
this.streams.get(streamKey).cancel();
|
|
5428
|
+
this.streams.delete(streamKey);
|
|
5429
|
+
}
|
|
5430
|
+
};
|
|
5431
|
+
|
|
5432
|
+
//#endregion
|
|
5433
|
+
//#region src/client/indexer/grpc_stream/streamV2/streamHelpersV2.ts
|
|
5434
|
+
/**
|
|
5435
|
+
* Creates an event-based subscription for StreamManager V2.
|
|
5436
|
+
* This emits 'error' and 'complete' events instead of using callbacks.
|
|
5437
|
+
*
|
|
5438
|
+
* @param stream - The ServerStreamingCall from the V2 client
|
|
5439
|
+
* @param handleResponse - Callback to process each stream response
|
|
5440
|
+
* @returns StreamSubscription with event emitters for error/complete
|
|
5441
|
+
*/
|
|
5442
|
+
function createStreamSubscriptionV2(stream, handleResponse) {
|
|
5443
|
+
const emitter = new EventEmitter();
|
|
5444
|
+
const abortController = new AbortController();
|
|
5445
|
+
const subscription = {
|
|
5446
|
+
unsubscribe: () => {
|
|
5447
|
+
abortController.abort();
|
|
5448
|
+
emitter.removeAllListeners();
|
|
5449
|
+
},
|
|
5450
|
+
on: (event, handler) => {
|
|
5451
|
+
emitter.on(event, handler);
|
|
5452
|
+
},
|
|
5453
|
+
off: (event, handler) => {
|
|
5454
|
+
emitter.off(event, handler);
|
|
5455
|
+
}
|
|
5456
|
+
};
|
|
5457
|
+
(async () => {
|
|
5458
|
+
try {
|
|
5459
|
+
for await (const response of stream.responses) {
|
|
5460
|
+
if (abortController.signal.aborted) break;
|
|
5461
|
+
if (abortController.signal.aborted) break;
|
|
5462
|
+
handleResponse(response);
|
|
5463
|
+
}
|
|
5464
|
+
if (!abortController.signal.aborted) emitter.emit("complete");
|
|
5465
|
+
} catch (error) {
|
|
5466
|
+
if (!abortController.signal.aborted) {
|
|
5467
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown stream error";
|
|
5468
|
+
let grpcCode = 2;
|
|
5469
|
+
if (error && typeof error === "object" && "code" in error) grpcCode = error.code;
|
|
5470
|
+
const streamError = {
|
|
5471
|
+
code: grpcCode,
|
|
5472
|
+
metadata: error,
|
|
5473
|
+
details: errorMessage
|
|
5474
|
+
};
|
|
5475
|
+
emitter.emit("error", streamError);
|
|
5476
|
+
}
|
|
5477
|
+
}
|
|
5478
|
+
})();
|
|
5479
|
+
return subscription;
|
|
5480
|
+
}
|
|
5481
|
+
|
|
5482
|
+
//#endregion
|
|
5483
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcSpotStreamV2.ts
|
|
5484
|
+
var IndexerGrpcSpotStreamV2 = class {
|
|
5485
|
+
constructor(endpoint, metadata) {
|
|
5486
|
+
_defineProperty(this, "client", void 0);
|
|
5487
|
+
_defineProperty(this, "transport", void 0);
|
|
5488
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5489
|
+
this.client = new InjectiveSpotExchangeRPCClient(this.transport);
|
|
5490
|
+
}
|
|
5491
|
+
/**
|
|
5492
|
+
* Stream spot orderbook updates
|
|
5493
|
+
* @param params.marketIds - Array of market IDs to stream
|
|
5494
|
+
* @param params.callback - Called for each orderbook update
|
|
5495
|
+
* @returns StreamSubscription
|
|
5496
|
+
*/
|
|
5497
|
+
streamOrderbookUpdates({ marketIds, callback }) {
|
|
5498
|
+
if (!marketIds || marketIds.length === 0) throw new Error("marketIds is required");
|
|
5499
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5500
|
+
const request = InjectiveSpotExchangeRpcPb.StreamOrderbookUpdateRequest.create();
|
|
5501
|
+
request.marketIds = marketIds;
|
|
5502
|
+
return createStreamSubscriptionV2(this.client.streamOrderbookUpdate(request), (response) => {
|
|
5503
|
+
callback(IndexerSpotStreamTransformer.orderbookUpdateStreamCallback(response));
|
|
5504
|
+
});
|
|
5505
|
+
}
|
|
5506
|
+
/**
|
|
5507
|
+
* Stream spot orders
|
|
5508
|
+
* @param params.marketId - Optional market ID to filter
|
|
5509
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5510
|
+
* @param params.orderSide - Optional order side to filter
|
|
5511
|
+
* @param params.callback - Called for each order update
|
|
5512
|
+
* @returns StreamSubscription
|
|
5513
|
+
*/
|
|
5514
|
+
streamOrders({ marketId, subaccountId, orderSide, callback }) {
|
|
5515
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5516
|
+
const request = InjectiveSpotExchangeRpcPb.StreamOrdersRequest.create();
|
|
5517
|
+
if (marketId) request.marketId = marketId;
|
|
5518
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5519
|
+
if (orderSide) request.orderSide = orderSide;
|
|
5520
|
+
return createStreamSubscriptionV2(this.client.streamOrders(request), (response) => {
|
|
5521
|
+
callback(IndexerSpotStreamTransformer.ordersStreamCallback(response));
|
|
5522
|
+
});
|
|
5523
|
+
}
|
|
5524
|
+
/**
|
|
5525
|
+
* Stream spot order history
|
|
5526
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5527
|
+
* @param params.marketId - Optional market ID to filter
|
|
5528
|
+
* @param params.orderTypes - Optional order types to filter
|
|
5529
|
+
* @param params.direction - Optional direction to filter
|
|
5530
|
+
* @param params.state - Optional state to filter
|
|
5531
|
+
* @param params.executionTypes - Optional execution types to filter
|
|
5532
|
+
* @param params.callback - Called for each order history update
|
|
5533
|
+
* @returns StreamSubscription
|
|
5534
|
+
*/
|
|
5535
|
+
streamOrderHistory({ subaccountId, marketId, orderTypes, direction, state, executionTypes, callback }) {
|
|
5536
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5537
|
+
const request = InjectiveSpotExchangeRpcPb.StreamOrdersHistoryRequest.create();
|
|
5538
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5539
|
+
if (marketId) request.marketId = marketId;
|
|
5540
|
+
if (orderTypes) request.orderTypes = orderTypes;
|
|
5541
|
+
if (direction) request.direction = direction;
|
|
5542
|
+
if (state) request.state = state;
|
|
5543
|
+
if (executionTypes) request.executionTypes = executionTypes;
|
|
5544
|
+
return createStreamSubscriptionV2(this.client.streamOrdersHistory(request), (response) => {
|
|
5545
|
+
callback(IndexerSpotStreamTransformer.orderHistoryStreamCallback(response));
|
|
5546
|
+
});
|
|
5547
|
+
}
|
|
5548
|
+
/**
|
|
5549
|
+
* Stream spot trades
|
|
5550
|
+
* @param params.marketId - Optional market ID to filter
|
|
5551
|
+
* @param params.marketIds - Optional array of market IDs to filter
|
|
5552
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5553
|
+
* @param params.subaccountIds - Optional array of subaccount IDs to filter
|
|
5554
|
+
* @param params.executionSide - Optional execution side to filter
|
|
5555
|
+
* @param params.direction - Optional direction to filter
|
|
5556
|
+
* @param params.executionTypes - Optional execution types to filter
|
|
5557
|
+
* @param params.callback - Called for each trade update
|
|
5558
|
+
* @returns StreamSubscription
|
|
5559
|
+
*/
|
|
5560
|
+
streamTrades({ marketId, marketIds, subaccountId, subaccountIds, executionSide, direction, executionTypes, callback }) {
|
|
5561
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5562
|
+
const request = InjectiveSpotExchangeRpcPb.StreamTradesRequest.create();
|
|
5563
|
+
if (marketId) request.marketId = marketId;
|
|
5564
|
+
if (marketIds) request.marketIds = marketIds;
|
|
5565
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5566
|
+
if (subaccountIds) request.subaccountIds = subaccountIds;
|
|
5567
|
+
if (executionSide) request.executionSide = executionSide;
|
|
5568
|
+
if (direction) request.direction = direction;
|
|
5569
|
+
if (executionTypes) request.executionTypes = executionTypes;
|
|
5570
|
+
return createStreamSubscriptionV2(this.client.streamTrades(request), (response) => {
|
|
5571
|
+
callback(IndexerSpotStreamTransformer.tradesStreamCallback(response));
|
|
5572
|
+
});
|
|
5573
|
+
}
|
|
5574
|
+
};
|
|
5575
|
+
|
|
5576
|
+
//#endregion
|
|
5577
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcMitoStreamV2.ts
|
|
5578
|
+
var IndexerGrpcMitoStreamV2 = class {
|
|
5579
|
+
constructor(endpoint, metadata) {
|
|
5580
|
+
_defineProperty(this, "client", void 0);
|
|
5581
|
+
_defineProperty(this, "transport", void 0);
|
|
5582
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5583
|
+
this.client = new MitoAPIClient(this.transport);
|
|
5584
|
+
}
|
|
5585
|
+
/**
|
|
5586
|
+
* Stream vault transfers
|
|
5587
|
+
* @param params.vault - Optional vault address to filter
|
|
5588
|
+
* @param params.account - Optional account address to filter
|
|
5589
|
+
* @param params.callback - Called for each transfer update
|
|
5590
|
+
* @returns StreamSubscription
|
|
5591
|
+
*/
|
|
5592
|
+
streamTransfers({ vault, account, callback }) {
|
|
5593
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5594
|
+
const request = GoadesignGoagenMitoApiPb.StreamTransfersRequest.create();
|
|
5595
|
+
if (vault) request.vault = vault;
|
|
5596
|
+
if (account) request.account = account;
|
|
5597
|
+
return createStreamSubscriptionV2(this.client.streamTransfers(request), (response) => {
|
|
5598
|
+
callback(IndexerGrpcMitoStreamTransformer.transfersStreamCallback(response));
|
|
5599
|
+
});
|
|
5600
|
+
}
|
|
5601
|
+
/**
|
|
5602
|
+
* Stream vault information
|
|
5603
|
+
* @param params.vault - Optional vault address to filter
|
|
5604
|
+
* @param params.callback - Called for each vault update
|
|
5605
|
+
* @returns StreamSubscription
|
|
5606
|
+
*/
|
|
5607
|
+
streamVault({ vault, callback }) {
|
|
5608
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5609
|
+
const request = GoadesignGoagenMitoApiPb.StreamVaultRequest.create();
|
|
5610
|
+
if (vault) request.vault = vault;
|
|
5611
|
+
return createStreamSubscriptionV2(this.client.streamVault(request), (response) => {
|
|
5612
|
+
callback(IndexerGrpcMitoStreamTransformer.vaultStreamCallback(response));
|
|
5613
|
+
});
|
|
5614
|
+
}
|
|
5615
|
+
/**
|
|
5616
|
+
* Stream vault holder subscriptions
|
|
5617
|
+
* @param params.holderAddress - The holder address to stream subscriptions for
|
|
5618
|
+
* @param params.vaultAddress - Optional vault address to filter
|
|
5619
|
+
* @param params.stakingContractAddress - Optional staking contract address to filter
|
|
5620
|
+
* @param params.callback - Called for each subscription update
|
|
5621
|
+
* @returns StreamSubscription
|
|
5622
|
+
*/
|
|
5623
|
+
streamVaultHolderSubscriptions({ holderAddress, vaultAddress, stakingContractAddress, callback }) {
|
|
5624
|
+
if (!holderAddress) throw new Error("holderAddress is required");
|
|
5625
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5626
|
+
const request = GoadesignGoagenMitoApiPb.StreamHolderSubscriptionRequest.create();
|
|
5627
|
+
request.holderAddress = holderAddress;
|
|
5628
|
+
if (vaultAddress) request.vaultAddress = vaultAddress;
|
|
5629
|
+
if (stakingContractAddress) request.stakingContractAddress = stakingContractAddress;
|
|
5630
|
+
return createStreamSubscriptionV2(this.client.streamHolderSubscription(request), (response) => {
|
|
5631
|
+
callback(IndexerGrpcMitoStreamTransformer.vaultHolderSubscriptionStreamCallback(response));
|
|
5632
|
+
});
|
|
5633
|
+
}
|
|
5634
|
+
/**
|
|
5635
|
+
* Stream staking rewards by account
|
|
5636
|
+
* @param params.staker - The staker address to stream rewards for
|
|
5637
|
+
* @param params.stakingContractAddress - The staking contract address
|
|
5638
|
+
* @param params.callback - Called for each reward update
|
|
5639
|
+
* @returns StreamSubscription
|
|
5640
|
+
*/
|
|
5641
|
+
streamStakingRewardsByAccount({ staker, stakingContractAddress, callback }) {
|
|
5642
|
+
if (!staker) throw new Error("staker is required");
|
|
5643
|
+
if (!stakingContractAddress) throw new Error("stakingContractAddress is required");
|
|
5644
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5645
|
+
const request = GoadesignGoagenMitoApiPb.StreamStakingRewardByAccountRequest.create();
|
|
5646
|
+
request.staker = staker;
|
|
5647
|
+
request.stakingContractAddress = stakingContractAddress;
|
|
5648
|
+
return createStreamSubscriptionV2(this.client.streamStakingRewardByAccount(request), (response) => {
|
|
5649
|
+
callback(IndexerGrpcMitoStreamTransformer.stakingRewardByAccountStreamCallback(response));
|
|
5650
|
+
});
|
|
5651
|
+
}
|
|
5652
|
+
/**
|
|
5653
|
+
* Stream historical staking data
|
|
5654
|
+
* @param params.staker - The staker address to stream data for
|
|
5655
|
+
* @param params.stakingContractAddress - The staking contract address
|
|
5656
|
+
* @param params.callback - Called for each historical staking update
|
|
5657
|
+
* @returns StreamSubscription
|
|
5658
|
+
*/
|
|
5659
|
+
streamHistoricalStaking({ staker, stakingContractAddress, callback }) {
|
|
5660
|
+
if (!staker) throw new Error("staker is required");
|
|
5661
|
+
if (!stakingContractAddress) throw new Error("stakingContractAddress is required");
|
|
5662
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5663
|
+
const request = GoadesignGoagenMitoApiPb.StreamHistoricalStakingRequest.create();
|
|
5664
|
+
request.staker = staker;
|
|
5665
|
+
request.stakingContractAddress = stakingContractAddress;
|
|
5666
|
+
return createStreamSubscriptionV2(this.client.streamHistoricalStaking(request), (response) => {
|
|
5667
|
+
callback(IndexerGrpcMitoStreamTransformer.historicalStakingStreamCallback(response));
|
|
5668
|
+
});
|
|
5669
|
+
}
|
|
5670
|
+
};
|
|
5671
|
+
|
|
5672
|
+
//#endregion
|
|
5673
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcOracleStreamV2.ts
|
|
5674
|
+
var IndexerGrpcOracleStreamV2 = class {
|
|
5675
|
+
constructor(endpoint, metadata) {
|
|
5676
|
+
_defineProperty(this, "client", void 0);
|
|
5677
|
+
_defineProperty(this, "transport", void 0);
|
|
5678
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5679
|
+
this.client = new InjectiveOracleRPCClient(this.transport);
|
|
5680
|
+
}
|
|
5681
|
+
/**
|
|
5682
|
+
* Stream oracle price updates
|
|
5683
|
+
* @param params.oracleType - The oracle type to stream prices for
|
|
5684
|
+
* @param params.baseSymbol - Optional base symbol filter
|
|
5685
|
+
* @param params.quoteSymbol - Optional quote symbol filter
|
|
5686
|
+
* @param params.callback - Called for each price update
|
|
5687
|
+
* @returns StreamSubscription
|
|
5688
|
+
*/
|
|
5689
|
+
streamOraclePrices({ oracleType, baseSymbol, quoteSymbol, callback }) {
|
|
5690
|
+
if (!oracleType) throw new Error("oracleType is required");
|
|
5691
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5692
|
+
const request = InjectiveOracleRpcPb.StreamPricesRequest.create();
|
|
5693
|
+
if (baseSymbol) request.baseSymbol = baseSymbol;
|
|
5694
|
+
if (quoteSymbol) request.quoteSymbol = quoteSymbol;
|
|
5695
|
+
request.oracleType = oracleType;
|
|
5696
|
+
return createStreamSubscriptionV2(this.client.streamPrices(request), (response) => {
|
|
5697
|
+
callback(IndexerOracleStreamTransformer.pricesStreamCallback(response));
|
|
5698
|
+
});
|
|
5699
|
+
}
|
|
5700
|
+
/**
|
|
5701
|
+
* Stream oracle prices by markets
|
|
5702
|
+
* @param params.marketIds - Optional array of market IDs to filter
|
|
5703
|
+
* @param params.callback - Called for each price update
|
|
5704
|
+
* @returns StreamSubscription
|
|
5705
|
+
*/
|
|
5706
|
+
streamOraclePricesByMarkets({ marketIds, callback }) {
|
|
5707
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5708
|
+
const request = InjectiveOracleRpcPb.StreamPricesByMarketsRequest.create();
|
|
5709
|
+
if (marketIds) request.marketIds = marketIds;
|
|
5710
|
+
return createStreamSubscriptionV2(this.client.streamPricesByMarkets(request), (response) => {
|
|
5711
|
+
callback(IndexerOracleStreamTransformer.pricesByMarketsCallback(response));
|
|
5712
|
+
});
|
|
5713
|
+
}
|
|
5714
|
+
};
|
|
5715
|
+
|
|
5716
|
+
//#endregion
|
|
5717
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcAccountStreamV2.ts
|
|
5718
|
+
var IndexerGrpcAccountStreamV2 = class {
|
|
5719
|
+
constructor(endpoint, metadata) {
|
|
5720
|
+
_defineProperty(this, "client", void 0);
|
|
5721
|
+
_defineProperty(this, "transport", void 0);
|
|
5722
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5723
|
+
this.client = new InjectiveAccountsRPCClient(this.transport);
|
|
5724
|
+
}
|
|
5725
|
+
/**
|
|
5726
|
+
* Stream subaccount balance updates
|
|
5727
|
+
* @param params.subaccountId - The subaccount ID to stream balance for
|
|
5728
|
+
* @param params.callback - Called for each balance update
|
|
5729
|
+
* @returns StreamSubscription
|
|
5730
|
+
*/
|
|
5731
|
+
streamSubaccountBalance({ subaccountId, callback }) {
|
|
5732
|
+
if (!subaccountId) throw new Error("subaccountId is required");
|
|
5733
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5734
|
+
const request = InjectiveAccountsRpcPb.StreamSubaccountBalanceRequest.create();
|
|
5735
|
+
request.subaccountId = subaccountId;
|
|
5736
|
+
return createStreamSubscriptionV2(this.client.streamSubaccountBalance(request), (response) => {
|
|
5737
|
+
callback(IndexerAccountStreamTransformer.balanceStreamCallback(response));
|
|
5738
|
+
});
|
|
5739
|
+
}
|
|
5740
|
+
};
|
|
5741
|
+
|
|
5742
|
+
//#endregion
|
|
5743
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcAuctionStreamV2.ts
|
|
5744
|
+
var IndexerGrpcAuctionStreamV2 = class {
|
|
5745
|
+
constructor(endpoint, metadata) {
|
|
5746
|
+
_defineProperty(this, "client", void 0);
|
|
5747
|
+
_defineProperty(this, "transport", void 0);
|
|
5748
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5749
|
+
this.client = new InjectiveAuctionRPCClient(this.transport);
|
|
5750
|
+
}
|
|
5751
|
+
/**
|
|
5752
|
+
* Stream auction bids
|
|
5753
|
+
* @param params.callback - Called for each bid update
|
|
5754
|
+
* @returns StreamSubscription
|
|
5755
|
+
*/
|
|
5756
|
+
streamBids({ callback }) {
|
|
5757
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5758
|
+
const request = InjectiveAuctionRpcPb.StreamBidsRequest.create();
|
|
5759
|
+
return createStreamSubscriptionV2(this.client.streamBids(request), (response) => {
|
|
5760
|
+
callback(IndexerAuctionStreamTransformer.bidsStreamCallback(response));
|
|
5761
|
+
});
|
|
5762
|
+
}
|
|
5763
|
+
};
|
|
5764
|
+
|
|
5765
|
+
//#endregion
|
|
5766
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcTradingStreamV2.ts
|
|
5767
|
+
var IndexerGrpcTradingStreamV2 = class {
|
|
5768
|
+
constructor(endpoint, metadata) {
|
|
5769
|
+
_defineProperty(this, "client", void 0);
|
|
5770
|
+
_defineProperty(this, "transport", void 0);
|
|
5771
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5772
|
+
this.client = new InjectiveTradingRPCClient(this.transport);
|
|
5773
|
+
}
|
|
5774
|
+
/**
|
|
5775
|
+
* Stream grid strategies
|
|
5776
|
+
* @param params.marketId - Optional market ID to filter strategies
|
|
5777
|
+
* @param params.accountAddresses - Optional array of account addresses to filter
|
|
5778
|
+
* @param params.callback - Called for each strategy update
|
|
5779
|
+
* @returns StreamSubscription
|
|
5780
|
+
*/
|
|
5781
|
+
streamGridStrategies({ marketId, accountAddresses, callback }) {
|
|
5782
|
+
if ((!accountAddresses || accountAddresses.length === 0) && !marketId) throw new Error("accountAddresses or marketId is required");
|
|
5783
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5784
|
+
const request = InjectiveTradingRpcPb.StreamStrategyRequest.create();
|
|
5785
|
+
if (accountAddresses) request.accountAddresses = accountAddresses;
|
|
5786
|
+
if (marketId) request.marketId = marketId;
|
|
5787
|
+
return createStreamSubscriptionV2(this.client.streamStrategy(request), (response) => {
|
|
5788
|
+
callback(response);
|
|
5789
|
+
});
|
|
5790
|
+
}
|
|
5791
|
+
};
|
|
5792
|
+
|
|
5793
|
+
//#endregion
|
|
5794
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcArchiverStreamV2.ts
|
|
5795
|
+
var IndexerGrpcArchiverStreamV2 = class {
|
|
5796
|
+
constructor(endpoint, metadata) {
|
|
5797
|
+
_defineProperty(this, "client", void 0);
|
|
5798
|
+
_defineProperty(this, "transport", void 0);
|
|
5799
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5800
|
+
this.client = new InjectiveArchiverRPCClient(this.transport);
|
|
5801
|
+
}
|
|
5802
|
+
/**
|
|
5803
|
+
* Stream spot average entries
|
|
5804
|
+
* @param params.account - The account address to stream entries for
|
|
5805
|
+
* @param params.callback - Called for each average entry update
|
|
5806
|
+
* @returns StreamSubscription
|
|
5807
|
+
*/
|
|
5808
|
+
streamSpotAverageEntries({ account, callback }) {
|
|
5809
|
+
if (!account) throw new Error("account is required");
|
|
5810
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5811
|
+
const request = InjectiveArchiverRpcPb.StreamSpotAverageEntriesRequest.create();
|
|
5812
|
+
request.account = account;
|
|
5813
|
+
return createStreamSubscriptionV2(this.client.streamSpotAverageEntries(request), (response) => {
|
|
5814
|
+
callback(IndexerArchiverStreamTransformer.spotAverageEntriesStreamCallback(response));
|
|
5815
|
+
});
|
|
5816
|
+
}
|
|
5817
|
+
};
|
|
5818
|
+
|
|
5819
|
+
//#endregion
|
|
5820
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcExplorerStreamV2.ts
|
|
5821
|
+
var IndexerGrpcExplorerStreamV2 = class {
|
|
5822
|
+
constructor(endpoint, metadata) {
|
|
5823
|
+
_defineProperty(this, "client", void 0);
|
|
5824
|
+
_defineProperty(this, "transport", void 0);
|
|
5825
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5826
|
+
this.client = new InjectiveExplorerRPCClient(this.transport);
|
|
5827
|
+
}
|
|
5828
|
+
/**
|
|
5829
|
+
* Stream block updates
|
|
5830
|
+
* @param params.callback - Called for each block update
|
|
5831
|
+
* @returns StreamSubscription
|
|
5832
|
+
*/
|
|
5833
|
+
streamBlocks({ callback }) {
|
|
5834
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5835
|
+
const request = InjectiveExplorerRpcPb.StreamBlocksRequest.create();
|
|
5836
|
+
return createStreamSubscriptionV2(this.client.streamBlocks(request), (response) => {
|
|
5837
|
+
callback(ExplorerStreamTransformer.blocksStreamCallback(response));
|
|
5838
|
+
});
|
|
5839
|
+
}
|
|
5840
|
+
/**
|
|
5841
|
+
* Stream blocks with transactions
|
|
5842
|
+
* @param params.callback - Called for each block with transactions update
|
|
5843
|
+
* @returns StreamSubscription
|
|
5844
|
+
*/
|
|
5845
|
+
streamBlocksWithTxs({ callback }) {
|
|
5846
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5847
|
+
const request = InjectiveExplorerRpcPb.StreamBlocksRequest.create();
|
|
5848
|
+
return createStreamSubscriptionV2(this.client.streamBlocks(request), (response) => {
|
|
5849
|
+
callback(ExplorerStreamTransformer.blocksWithTxsStreamCallback(response));
|
|
5850
|
+
});
|
|
5851
|
+
}
|
|
5852
|
+
/**
|
|
5853
|
+
* Stream transaction updates
|
|
5854
|
+
* @param params.callback - Called for each transaction update
|
|
5855
|
+
* @returns StreamSubscription
|
|
5856
|
+
*/
|
|
5857
|
+
streamTransactions({ callback }) {
|
|
5858
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5859
|
+
const request = InjectiveExplorerRpcPb.StreamTxsRequest.create();
|
|
5860
|
+
return createStreamSubscriptionV2(this.client.streamTxs(request), (response) => {
|
|
5861
|
+
callback(ExplorerStreamTransformer.transactionsStreamCallback(response));
|
|
5862
|
+
});
|
|
5863
|
+
}
|
|
5864
|
+
};
|
|
5865
|
+
|
|
5866
|
+
//#endregion
|
|
5867
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcDerivativesStreamV2.ts
|
|
5868
|
+
var IndexerGrpcDerivativesStreamV2 = class {
|
|
5869
|
+
constructor(endpoint, metadata) {
|
|
5870
|
+
_defineProperty(this, "client", void 0);
|
|
5871
|
+
_defineProperty(this, "transport", void 0);
|
|
5872
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
5873
|
+
this.client = new InjectiveDerivativeExchangeRPCClient(this.transport);
|
|
5874
|
+
}
|
|
5875
|
+
/**
|
|
5876
|
+
* Stream derivative orders
|
|
5877
|
+
* @param params.marketId - Optional market ID to filter
|
|
5878
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5879
|
+
* @param params.orderSide - Optional order side to filter
|
|
5880
|
+
* @param params.callback - Called for each order update
|
|
5881
|
+
* @returns StreamSubscription
|
|
5882
|
+
*/
|
|
5883
|
+
streamOrders({ marketId, subaccountId, orderSide, callback }) {
|
|
5884
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5885
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamOrdersRequest.create();
|
|
5886
|
+
if (marketId) request.marketId = marketId;
|
|
5887
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5888
|
+
if (orderSide) request.orderSide = orderSide;
|
|
5889
|
+
return createStreamSubscriptionV2(this.client.streamOrders(request), (response) => {
|
|
5890
|
+
callback(IndexerDerivativeStreamTransformer.ordersStreamCallback(response));
|
|
5891
|
+
});
|
|
5892
|
+
}
|
|
5893
|
+
/**
|
|
5894
|
+
* Stream derivative order history
|
|
5895
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5896
|
+
* @param params.marketId - Optional market ID to filter
|
|
5897
|
+
* @param params.orderTypes - Optional order types to filter
|
|
5898
|
+
* @param params.direction - Optional direction to filter
|
|
5899
|
+
* @param params.state - Optional state to filter
|
|
5900
|
+
* @param params.executionTypes - Optional execution types to filter
|
|
5901
|
+
* @param params.callback - Called for each order history update
|
|
5902
|
+
* @returns StreamSubscription
|
|
5903
|
+
*/
|
|
5904
|
+
streamOrdersHistory({ subaccountId, marketId, orderTypes, direction, state, executionTypes, callback }) {
|
|
5905
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5906
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamOrdersHistoryRequest.create();
|
|
5907
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5908
|
+
if (marketId) request.marketId = marketId;
|
|
5909
|
+
if (orderTypes) request.orderTypes = orderTypes;
|
|
5910
|
+
if (direction) request.direction = direction;
|
|
5911
|
+
if (state) request.state = state;
|
|
5912
|
+
if (executionTypes) request.executionTypes = executionTypes;
|
|
5913
|
+
return createStreamSubscriptionV2(this.client.streamOrdersHistory(request), (response) => {
|
|
5914
|
+
callback(IndexerDerivativeStreamTransformer.orderHistoryStreamCallback(response));
|
|
5915
|
+
});
|
|
5916
|
+
}
|
|
5917
|
+
/**
|
|
5918
|
+
* Stream derivative trades
|
|
5919
|
+
* @param params.marketId - Optional market ID to filter
|
|
5920
|
+
* @param params.marketIds - Optional array of market IDs to filter
|
|
5921
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5922
|
+
* @param params.subaccountIds - Optional array of subaccount IDs to filter
|
|
5923
|
+
* @param params.executionSide - Optional execution side to filter
|
|
5924
|
+
* @param params.direction - Optional direction to filter
|
|
5925
|
+
* @param params.pagination - Optional pagination options
|
|
5926
|
+
* @param params.callback - Called for each trade update
|
|
5927
|
+
* @returns StreamSubscription
|
|
5928
|
+
*/
|
|
5929
|
+
streamTrades({ marketIds, marketId, subaccountIds, subaccountId, executionSide, direction, pagination, callback }) {
|
|
5930
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5931
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamTradesRequest.create();
|
|
5932
|
+
if (marketIds) request.marketIds = marketIds;
|
|
5933
|
+
if (marketId) request.marketId = marketId;
|
|
5934
|
+
if (subaccountIds) request.subaccountIds = subaccountIds;
|
|
5935
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5936
|
+
if (executionSide) request.executionSide = executionSide;
|
|
5937
|
+
if (direction) request.direction = direction;
|
|
5938
|
+
if (pagination) {
|
|
5939
|
+
if (pagination.skip !== void 0) request.skip = BigInt(pagination.skip);
|
|
5940
|
+
if (pagination.limit !== void 0) request.limit = pagination.limit;
|
|
5941
|
+
}
|
|
5942
|
+
return createStreamSubscriptionV2(this.client.streamTrades(request), (response) => {
|
|
5943
|
+
callback(IndexerDerivativeStreamTransformer.tradesStreamCallback(response));
|
|
5944
|
+
});
|
|
5945
|
+
}
|
|
5946
|
+
/**
|
|
5947
|
+
* Stream derivative positions
|
|
5948
|
+
* @param params.marketId - Optional market ID to filter
|
|
5949
|
+
* @param params.address - Optional address to filter
|
|
5950
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
5951
|
+
* @param params.callback - Called for each position update
|
|
5952
|
+
* @returns StreamSubscription
|
|
5953
|
+
*/
|
|
5954
|
+
streamPositions({ marketId, address, subaccountId, callback }) {
|
|
5955
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5956
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamPositionsRequest.create();
|
|
5957
|
+
if (marketId) request.marketId = marketId;
|
|
5958
|
+
if (address) request.accountAddress = address;
|
|
5959
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
5960
|
+
return createStreamSubscriptionV2(this.client.streamPositions(request), (response) => {
|
|
5961
|
+
callback(IndexerDerivativeStreamTransformer.positionStreamCallback(response));
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5964
|
+
/**
|
|
5965
|
+
* Stream derivative markets
|
|
5966
|
+
* @param params.marketIds - Optional array of market IDs to filter
|
|
5967
|
+
* @param params.callback - Called for each market update
|
|
5968
|
+
* @returns StreamSubscription
|
|
5969
|
+
*/
|
|
5970
|
+
streamMarkets({ marketIds, callback }) {
|
|
5971
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5972
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamMarketRequest.create();
|
|
5973
|
+
if (marketIds && marketIds.length) request.marketIds = marketIds;
|
|
5974
|
+
return createStreamSubscriptionV2(this.client.streamMarket(request), (response) => {
|
|
5975
|
+
callback(response);
|
|
5976
|
+
});
|
|
5977
|
+
}
|
|
5978
|
+
/**
|
|
5979
|
+
* Stream derivative orderbooks V2
|
|
5980
|
+
* @param params.marketIds - Array of market IDs to stream
|
|
5981
|
+
* @param params.callback - Called for each orderbook update
|
|
5982
|
+
* @returns StreamSubscription
|
|
5983
|
+
*/
|
|
5984
|
+
streamOrderbooksV2({ marketIds, callback }) {
|
|
5985
|
+
if (!marketIds || marketIds.length === 0) throw new Error("marketIds is required and cannot be empty");
|
|
5986
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
5987
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamOrderbookV2Request.create();
|
|
5988
|
+
request.marketIds = marketIds;
|
|
5989
|
+
return createStreamSubscriptionV2(this.client.streamOrderbookV2(request), (response) => {
|
|
5990
|
+
callback(IndexerDerivativeStreamTransformer.orderbookV2StreamCallback(response));
|
|
5991
|
+
});
|
|
5992
|
+
}
|
|
5993
|
+
/**
|
|
5994
|
+
* Stream derivative orderbook updates
|
|
5995
|
+
* @param params.marketIds - Array of market IDs to stream
|
|
5996
|
+
* @param params.callback - Called for each orderbook update
|
|
5997
|
+
* @returns StreamSubscription
|
|
5998
|
+
*/
|
|
5999
|
+
streamOrderbookUpdates({ marketIds, callback }) {
|
|
6000
|
+
if (!marketIds || marketIds.length === 0) throw new Error("marketIds is required and cannot be empty");
|
|
6001
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
6002
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamOrderbookUpdateRequest.create();
|
|
6003
|
+
request.marketIds = marketIds;
|
|
6004
|
+
return createStreamSubscriptionV2(this.client.streamOrderbookUpdate(request), (response) => {
|
|
6005
|
+
callback(IndexerDerivativeStreamTransformer.orderbookUpdateStreamCallback(response));
|
|
6006
|
+
});
|
|
6007
|
+
}
|
|
6008
|
+
/**
|
|
6009
|
+
* Stream derivative positions V2
|
|
6010
|
+
* @param params.marketId - Optional market ID to filter
|
|
6011
|
+
* @param params.address - Optional address to filter
|
|
6012
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
6013
|
+
* @param params.callback - Called for each position update
|
|
6014
|
+
* @returns StreamSubscription
|
|
6015
|
+
*/
|
|
6016
|
+
streamPositionsV2({ marketId, address, subaccountId, callback }) {
|
|
6017
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
6018
|
+
const request = InjectiveDerivativeExchangeRpcPb.StreamPositionsV2Request.create();
|
|
6019
|
+
if (marketId) request.marketId = marketId;
|
|
6020
|
+
if (address) request.accountAddress = address;
|
|
6021
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
6022
|
+
return createStreamSubscriptionV2(this.client.streamPositionsV2(request), (response) => {
|
|
6023
|
+
callback(IndexerDerivativeStreamTransformer.positionV2StreamCallback(response));
|
|
6024
|
+
});
|
|
6025
|
+
}
|
|
6026
|
+
};
|
|
6027
|
+
|
|
6028
|
+
//#endregion
|
|
6029
|
+
//#region src/client/indexer/grpc_stream/streamV2/IndexerGrpcAccountPortfolioStreamV2.ts
|
|
6030
|
+
var IndexerGrpcAccountPortfolioStreamV2 = class {
|
|
6031
|
+
constructor(endpoint, metadata) {
|
|
6032
|
+
_defineProperty(this, "client", void 0);
|
|
6033
|
+
_defineProperty(this, "transport", void 0);
|
|
6034
|
+
this.transport = new GrpcWebRpcTransport(endpoint, metadata);
|
|
6035
|
+
this.client = new InjectivePortfolioRPCClient(this.transport);
|
|
6036
|
+
}
|
|
6037
|
+
/**
|
|
6038
|
+
* Stream account portfolio updates
|
|
6039
|
+
* @param params.accountAddress - The account address to stream portfolio for
|
|
6040
|
+
* @param params.subaccountId - Optional subaccount ID to filter
|
|
6041
|
+
* @param params.type - Optional portfolio type to filter
|
|
6042
|
+
* @param params.callback - Called for each portfolio update
|
|
6043
|
+
* @returns StreamSubscription
|
|
6044
|
+
*/
|
|
6045
|
+
streamAccountPortfolio({ accountAddress, subaccountId, type, callback }) {
|
|
6046
|
+
if (!accountAddress) throw new Error("accountAddress is required");
|
|
6047
|
+
if (typeof callback !== "function") throw new Error("callback must be a function");
|
|
6048
|
+
const request = InjectivePortfolioRpcPb.StreamAccountPortfolioRequest.create();
|
|
6049
|
+
request.accountAddress = accountAddress;
|
|
6050
|
+
if (subaccountId) request.subaccountId = subaccountId;
|
|
6051
|
+
if (type) request.type = type;
|
|
6052
|
+
return createStreamSubscriptionV2(this.client.streamAccountPortfolio(request), (response) => {
|
|
6053
|
+
callback(IndexerAccountPortfolioStreamTransformer.accountPortfolioStreamCallback(response));
|
|
6054
|
+
});
|
|
6055
|
+
}
|
|
6056
|
+
};
|
|
6057
|
+
|
|
6058
|
+
//#endregion
|
|
6059
|
+
//#region src/client/indexer/grpc_stream/streamV2/StreamManager.ts
|
|
6060
|
+
/**
|
|
6061
|
+
* Default retry configuration
|
|
6062
|
+
*/
|
|
6063
|
+
const DEFAULT_RETRY_CONFIG = {
|
|
6064
|
+
enabled: true,
|
|
6065
|
+
maxAttempts: 5,
|
|
6066
|
+
initialDelayMs: 1e3,
|
|
6067
|
+
maxDelayMs: 3e4,
|
|
6068
|
+
backoffMultiplier: 2,
|
|
6069
|
+
persistent: true
|
|
6070
|
+
};
|
|
6071
|
+
/**
|
|
6072
|
+
* StreamManagerV2 - Manages gRPC stream connections with automatic retry
|
|
6073
|
+
*
|
|
6074
|
+
* V2 Features:
|
|
6075
|
+
* - Event-based lifecycle (on/off methods)
|
|
6076
|
+
* - Automatic retry with exponential backoff
|
|
6077
|
+
* - Persistent retry mode
|
|
6078
|
+
* - Comprehensive statistics tracking
|
|
6079
|
+
* - gRPC error code mapping
|
|
6080
|
+
*
|
|
6081
|
+
*/
|
|
6082
|
+
var StreamManagerV2 = class extends EventEmitter {
|
|
6083
|
+
constructor(config) {
|
|
6084
|
+
super();
|
|
6085
|
+
_defineProperty(this, "config", void 0);
|
|
6086
|
+
_defineProperty(this, "state", StreamState.Idle);
|
|
6087
|
+
_defineProperty(this, "subscription", null);
|
|
6088
|
+
_defineProperty(this, "retryTimeoutId", null);
|
|
6089
|
+
_defineProperty(this, "stats", void 0);
|
|
6090
|
+
_defineProperty(this, "retryAttempt", 0);
|
|
6091
|
+
this.config = {
|
|
6092
|
+
id: config.id,
|
|
6093
|
+
streamFactory: config.streamFactory,
|
|
6094
|
+
onData: config.onData,
|
|
6095
|
+
retryConfig: {
|
|
6096
|
+
...DEFAULT_RETRY_CONFIG,
|
|
6097
|
+
...config.retryConfig
|
|
6098
|
+
}
|
|
6099
|
+
};
|
|
6100
|
+
this.stats = {
|
|
6101
|
+
state: StreamState.Idle,
|
|
6102
|
+
connectCount: 0,
|
|
6103
|
+
disconnectCount: 0,
|
|
6104
|
+
retryCount: 0,
|
|
6105
|
+
dataReceivedCount: 0,
|
|
6106
|
+
errorCount: 0,
|
|
6107
|
+
lastDataAt: null,
|
|
6108
|
+
createdAt: Date.now(),
|
|
6109
|
+
connectedAt: null,
|
|
6110
|
+
disconnectedAt: null
|
|
6111
|
+
};
|
|
6112
|
+
const originalEmit = this.emit.bind(this);
|
|
6113
|
+
this.emit = ((event, ...args) => {
|
|
6114
|
+
if (event === StreamEvent.Data && args.length > 0) this.handleData(args[0]);
|
|
6115
|
+
return originalEmit(event, ...args);
|
|
6116
|
+
});
|
|
6117
|
+
}
|
|
6118
|
+
start() {
|
|
6119
|
+
if (this.state !== StreamState.Idle && this.state !== StreamState.Stopped) {
|
|
6120
|
+
this.emit(StreamEvent.Warn, { message: `Stream already started (state: ${this.state})` });
|
|
6121
|
+
return;
|
|
6122
|
+
}
|
|
6123
|
+
this.connect();
|
|
6124
|
+
}
|
|
6125
|
+
stop() {
|
|
6126
|
+
this.handleDisconnect(StreamDisconnectReason.UserStopped);
|
|
6127
|
+
}
|
|
6128
|
+
getId() {
|
|
6129
|
+
return this.config.id;
|
|
6130
|
+
}
|
|
6131
|
+
getState() {
|
|
6132
|
+
return this.state;
|
|
6133
|
+
}
|
|
6134
|
+
getStats() {
|
|
6135
|
+
return {
|
|
6136
|
+
...this.stats,
|
|
6137
|
+
state: this.state
|
|
6138
|
+
};
|
|
6139
|
+
}
|
|
6140
|
+
/**
|
|
6141
|
+
* Destroy the stream manager and clean up all resources
|
|
6142
|
+
* Call this when the stream manager is no longer needed
|
|
6143
|
+
*/
|
|
6144
|
+
destroy() {
|
|
6145
|
+
this.stop();
|
|
6146
|
+
this.removeAllListeners();
|
|
6147
|
+
}
|
|
6148
|
+
updateState(newState) {
|
|
6149
|
+
const oldState = this.state;
|
|
6150
|
+
this.state = newState;
|
|
6151
|
+
this.stats.state = newState;
|
|
6152
|
+
this.emit(StreamEvent.StateChange, {
|
|
6153
|
+
from: oldState,
|
|
6154
|
+
to: newState
|
|
6155
|
+
});
|
|
6156
|
+
}
|
|
6157
|
+
clearSubscription() {
|
|
6158
|
+
if (!this.subscription) return;
|
|
6159
|
+
this.subscription.unsubscribe();
|
|
6160
|
+
this.subscription = null;
|
|
6161
|
+
}
|
|
6162
|
+
clearRetryTimeout() {
|
|
6163
|
+
if (!this.retryTimeoutId) return;
|
|
6164
|
+
clearTimeout(this.retryTimeoutId);
|
|
6165
|
+
this.retryTimeoutId = null;
|
|
6166
|
+
}
|
|
6167
|
+
calculateNextBackoff() {
|
|
6168
|
+
if (this.config.retryConfig.maxAttempts > 0 && this.retryAttempt >= this.config.retryConfig.maxAttempts) return this.config.retryConfig.persistent ? this.config.retryConfig.maxDelayMs : null;
|
|
6169
|
+
const nextBackoffDelay = this.config.retryConfig.initialDelayMs * Math.pow(this.config.retryConfig.backoffMultiplier, this.retryAttempt);
|
|
6170
|
+
return Math.min(nextBackoffDelay, this.config.retryConfig.maxDelayMs);
|
|
6171
|
+
}
|
|
6172
|
+
scheduleRetry() {
|
|
6173
|
+
if (!this.config.retryConfig.enabled) return;
|
|
6174
|
+
const nextBackoff = this.calculateNextBackoff();
|
|
6175
|
+
if (nextBackoff === null) {
|
|
6176
|
+
this.handleMaxRetriesReached();
|
|
6177
|
+
return;
|
|
6178
|
+
}
|
|
6179
|
+
this.retryTimeoutId = setTimeout(() => {
|
|
6180
|
+
this.retryAttempt++;
|
|
6181
|
+
this.stats.retryCount++;
|
|
6182
|
+
this.emit(StreamEvent.Retry, {
|
|
6183
|
+
attempt: this.retryAttempt,
|
|
6184
|
+
delayMs: nextBackoff,
|
|
6185
|
+
nextBackoff: this.calculateNextBackoff()
|
|
6186
|
+
});
|
|
6187
|
+
this.connect();
|
|
6188
|
+
}, nextBackoff);
|
|
6189
|
+
}
|
|
6190
|
+
handleMaxRetriesReached() {
|
|
6191
|
+
this.emit(StreamEvent.Error, { message: `Max retries (${this.config.retryConfig.maxAttempts}) reached` });
|
|
6192
|
+
this.handleDisconnect(StreamDisconnectReason.MaxRetries);
|
|
6193
|
+
}
|
|
6194
|
+
handleError(error) {
|
|
6195
|
+
const errorInfo = this.extractErrorInfo(error);
|
|
6196
|
+
this.stats.errorCount++;
|
|
6197
|
+
this.emit(StreamEvent.Error, errorInfo);
|
|
6198
|
+
let reason = StreamDisconnectReason.StreamError;
|
|
6199
|
+
if (error && typeof error === "object" && "code" in error) switch (error.code) {
|
|
6200
|
+
case 14:
|
|
6201
|
+
reason = StreamDisconnectReason.NetworkError;
|
|
6202
|
+
break;
|
|
6203
|
+
case 4:
|
|
6204
|
+
reason = StreamDisconnectReason.Timeout;
|
|
6205
|
+
break;
|
|
6206
|
+
case 16:
|
|
6207
|
+
reason = StreamDisconnectReason.AuthenticationError;
|
|
6208
|
+
break;
|
|
6209
|
+
case 1:
|
|
6210
|
+
reason = StreamDisconnectReason.UserStopped;
|
|
6211
|
+
break;
|
|
6212
|
+
}
|
|
6213
|
+
this.handleDisconnect(reason);
|
|
6214
|
+
}
|
|
6215
|
+
/**
|
|
6216
|
+
* Handles incoming data - tracks stats and calls user callback
|
|
6217
|
+
* Called automatically when user emits 'data' event from streamFactory callback
|
|
6218
|
+
*/
|
|
6219
|
+
handleData(response) {
|
|
6220
|
+
this.stats.dataReceivedCount++;
|
|
6221
|
+
this.stats.lastDataAt = Date.now();
|
|
6222
|
+
try {
|
|
6223
|
+
this.config.onData(response);
|
|
6224
|
+
} catch (error) {
|
|
6225
|
+
this.handleError(error);
|
|
6226
|
+
}
|
|
6227
|
+
}
|
|
6228
|
+
handleConnected(isReconnect) {
|
|
6229
|
+
this.updateState(StreamState.Connected);
|
|
6230
|
+
this.retryAttempt = 0;
|
|
6231
|
+
this.stats.connectCount++;
|
|
6232
|
+
this.stats.connectedAt = Date.now();
|
|
6233
|
+
this.emit(StreamEvent.Connect, {
|
|
6234
|
+
isReconnect,
|
|
6235
|
+
attempt: this.stats.connectCount
|
|
6236
|
+
});
|
|
6237
|
+
}
|
|
6238
|
+
handleDisconnect(reason) {
|
|
6239
|
+
this.clearSubscription();
|
|
6240
|
+
this.clearRetryTimeout();
|
|
6241
|
+
this.stats.disconnectCount++;
|
|
6242
|
+
this.stats.disconnectedAt = Date.now();
|
|
6243
|
+
const willRetry = reason !== StreamDisconnectReason.UserStopped && reason !== StreamDisconnectReason.MaxRetries && this.config.retryConfig.enabled;
|
|
6244
|
+
this.emit(StreamEvent.Disconnect, {
|
|
6245
|
+
reason,
|
|
6246
|
+
willRetry,
|
|
6247
|
+
attempt: this.retryAttempt
|
|
6248
|
+
});
|
|
6249
|
+
if (willRetry) {
|
|
6250
|
+
this.updateState(StreamState.Reconnecting);
|
|
6251
|
+
this.scheduleRetry();
|
|
6252
|
+
} else this.updateState(StreamState.Stopped);
|
|
6253
|
+
}
|
|
6254
|
+
connect() {
|
|
6255
|
+
this.clearSubscription();
|
|
6256
|
+
const isReconnect = this.state === StreamState.Reconnecting;
|
|
6257
|
+
this.updateState(isReconnect ? StreamState.Reconnecting : StreamState.Connecting);
|
|
6258
|
+
try {
|
|
6259
|
+
this.subscription = this.config.streamFactory();
|
|
6260
|
+
this.subscription.on("error", (error) => {
|
|
6261
|
+
this.handleError(error);
|
|
6262
|
+
});
|
|
6263
|
+
this.subscription.on("complete", () => {
|
|
6264
|
+
this.handleDisconnect(StreamDisconnectReason.StreamEnded);
|
|
6265
|
+
});
|
|
6266
|
+
this.handleConnected(isReconnect);
|
|
6267
|
+
} catch (error) {
|
|
6268
|
+
this.handleError(error);
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
/**
|
|
6272
|
+
* Extracts error message and details from an error object
|
|
6273
|
+
*/
|
|
6274
|
+
extractErrorInfo(error) {
|
|
6275
|
+
if (error && typeof error === "object" && "details" in error) return {
|
|
6276
|
+
message: error.details,
|
|
6277
|
+
details: error
|
|
6278
|
+
};
|
|
6279
|
+
return {
|
|
6280
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
6281
|
+
details: error instanceof Error ? error.stack : error
|
|
6282
|
+
};
|
|
6283
|
+
}
|
|
6284
|
+
};
|
|
6285
|
+
|
|
6286
|
+
//#endregion
|
|
6287
|
+
export { IndexerGrpcMegaVaultTransformer as $, IndexerGrpcInsuranceFundApi as A, IndexerGrpcAccountApi as B, IndexerGrpcSpotStream as C, IndexerRestMarketChronosApi as D, IndexerRestDerivativesChronosApi as E, IndexerGrpcArchiverApi as F, IndexerAccountPortfolioStreamTransformer as G, IndexerGrpcSpotApi as H, IndexerGrpcCampaignApi as I, IndexerGrpcAccountPortfolioTransformer as J, IndexerGrpcInsuranceFundTransformer as K, IndexerGrpcExplorerApi as L, IndexerGrpcDerivativesApi as M, IndexerGrpcMegaVaultApi as N, IndexerRestSpotChronosApi as O, IndexerGrpcReferralApi as P, IndexerArchiverStreamTransformer as Q, IndexerGrpcTradingApi as R, IndexerGrpcMitoStream as S, IndexerRestLeaderboardChronosApi as T, IndexerGrpcMetaApi as U, IndexerGrpcOracleApi as V, IndexerGrpcMitoApi as W, IndexerGrpcDerivativeTransformer as X, IndexerGrpcMitoStreamTransformer as Y, ExplorerStreamTransformer as Z, IndexerGrpcArchiverStream as _, IndexerGrpcArchiverStreamV2 as a, IndexerGrpcExplorerTransformer as at, IndexerGrpcAccountStream as b, IndexerGrpcAccountStreamV2 as c, IndexerGrpcAccountTransformer as ct, IndexerGrpcSpotStreamV2 as d, IndexerCampaignTransformer as dt, IndexerAuctionStreamTransformer as et, createStreamSubscriptionV2 as f, IndexerGrpcSpotTransformer as ft, IndexerGrpcExplorerStream as g, IndexerGrpcDerivativesStream as h, IndexerGrpcExplorerStreamV2 as i, IndexerGrpcReferralTransformer as it, IndexerGrpcAccountPortfolioApi as j, IndexerRestExplorerApi as k, IndexerGrpcOracleStreamV2 as l, IndexerSpotStreamTransformer as lt, IndexerGrpcAccountPortfolioStream as m, IndexerGrpcAccountPortfolioStreamV2 as n, IndexerRestExplorerTransformer as nt, IndexerGrpcTradingStreamV2 as o, IndexerGrpcArchiverTransformer as ot, StreamManager as p, IndexerGrpcMitoTransformer as pt, IndexerDerivativeStreamTransformer as q, IndexerGrpcDerivativesStreamV2 as r, IndexerOracleStreamTransformer as rt, IndexerGrpcAuctionStreamV2 as s, IndexerGrpcAuctionTransformer as st, StreamManagerV2 as t, IndexerAccountStreamTransformer as tt, IndexerGrpcMitoStreamV2 as u, IndexerGrpcOracleTransformer as ut, IndexerGrpcTradingStream as v, createStreamSubscription as w, IndexerGrpcOracleStream as x, IndexerGrpcAuctionStream as y, IndexerGrpcAuctionApi as z };
|