@grvt/sdk 0.0.1-beta.1

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024 GRVT
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # GRVT TypeScript SDK
2
+
3
+ This SDK provides a TypeScript interface to interact with the GRVT API. It supports both REST API and WebSocket connections.
4
+
5
+ ## Installation
6
+
7
+ The GRVT TypeScript SDK consists of two packages:
8
+
9
+ - `@grvt/sdk`: TypeScript implementation of the GRVT API
10
+
11
+ Install both packages to get started:
12
+
13
+ ```bash
14
+ npm install @grvt/sdk
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### REST API Client
20
+
21
+ ```typescript
22
+ import { GrvtClient, GrvtEnvironment } from '@grvt/sdk';
23
+ import { ECurrency, ETransferType } from '@grvt/sdk';
24
+
25
+ const client = new GrvtClient({
26
+ apiKey: 'your-api-key',
27
+ apiSecret: 'your-api-secret',
28
+ env: GrvtEnvironment.DEV,
29
+ });
30
+
31
+ // Get funding account summary
32
+ const accountSummary = await client.getFundingAccountSummary();
33
+
34
+ // Get sub account summary
35
+ const subAccountSummary = await client.getSubAccountSummary({
36
+ sub_account_id: 'your-sub-account-id',
37
+ });
38
+
39
+ // Transfer funds
40
+ // Note: The signature field is optional. The SDK will automatically sign the transfer using the apiSecret.
41
+
42
+ const transfer = await client.transfer({
43
+ from_account_id: 'from-account-id',
44
+ from_sub_account_id: 'from-sub-account-id',
45
+ to_account_id: 'to-account-id',
46
+ to_sub_account_id: 'to-sub-account-id',
47
+ currency: ECurrency.USDT,
48
+ num_tokens: '100',
49
+ transfer_type: ETransferType.STANDARD,
50
+ transfer_metadata: ''
51
+ });
52
+ ```
53
+
54
+ ### WebSocket Client
55
+
56
+ The WebSocket client supports real-time data streaming and follows the same authentication mechanism as the REST API client.
57
+
58
+ ```typescript
59
+ import { GrvtWsClient, GrvtEnvironment } from '@grvt/sdk';
60
+
61
+ const client = new GrvtWsClient({
62
+ apiKey: 'your-api-key',
63
+ env: GrvtEnvironment.DEV,
64
+ });
65
+
66
+ // Connect to WebSocket
67
+ await client.connect();
68
+
69
+ // Subscribe to transfer history
70
+ client.subscribeTransferHistory(
71
+ 'main-account-id',
72
+ (data) => {
73
+ console.log('Received transfer:', data);
74
+ },
75
+ 'sub-account-id' // optional
76
+ );
77
+
78
+ // Disconnect when done
79
+ client.disconnect();
80
+ ```
81
+
82
+ #### WebSocket Features
83
+
84
+ 1. **Authentication**:
85
+ - Uses the same cookie-based authentication as the REST API
86
+ - Automatically refreshes cookies when needed
87
+
88
+ 2. **Connection Management**:
89
+ - Automatic reconnection with exponential backoff
90
+ - Connection monitoring with 5-second timeout
91
+ - Reconnects if no messages are received within the timeout period
92
+
93
+ 3. **Subscription Handling**:
94
+ - Unique subscription IDs for each subscription
95
+ - Subscriptions are not automatically restored after reconnection
96
+ - Users need to manually resubscribe after reconnection
97
+
98
+ 4. **Error Handling**:
99
+ - Automatic error logging
100
+ - Graceful disconnection handling
101
+ - Reconnection attempts with configurable maximum retries
102
+
103
+ ## Development
104
+
105
+ ### Building
106
+
107
+ ```bash
108
+ npm run build
109
+ ```
110
+
111
+ ### Formatting
112
+
113
+ ```bash
114
+ npm run format
115
+ ```
116
+
117
+ ### Testing
118
+
119
+ ```bash
120
+ # Run all tests
121
+ npm test
122
+
123
+ # Run SDK tests
124
+ npm run test:sdk
125
+
126
+ # Run WebSocket tests
127
+ npm run test:ws
128
+ ```
129
+
130
+ ### Linting and Formating
131
+
132
+ ```bash
133
+ npm run lint
134
+ ```
135
+
136
+ ```bash
137
+ npm run format
138
+ ```
139
+
140
+ ## License
141
+
142
+ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,17 @@
1
+ import { GrvtConfig } from '../config/config';
2
+ interface GrvtCookie {
3
+ gravity: string;
4
+ expires: number;
5
+ XGrvtAccountId?: string;
6
+ }
7
+ export declare class GrvtBaseClient {
8
+ protected config: GrvtConfig;
9
+ protected cookie: GrvtCookie | null;
10
+ protected domain: string;
11
+ protected edgeBaseUrl: string;
12
+ constructor(config: GrvtConfig);
13
+ protected shouldRefreshCookie(): boolean;
14
+ protected refreshCookie(): Promise<GrvtCookie | null>;
15
+ private getDomain;
16
+ }
17
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GrvtBaseClient = void 0;
4
+ const config_1 = require("../config/config");
5
+ const cookie_1 = require("../utils/cookie");
6
+ class GrvtBaseClient {
7
+ constructor(config) {
8
+ this.cookie = null;
9
+ this.config = config;
10
+ this.domain = this.getDomain();
11
+ this.edgeBaseUrl = `https://edge.${this.domain}`;
12
+ }
13
+ shouldRefreshCookie() {
14
+ if (!this.config.apiKey) {
15
+ return false;
16
+ }
17
+ const timeTillExpiration = this.cookie ? this.cookie.expires - Date.now() / 1000 : null;
18
+ const isCookieFresh = timeTillExpiration !== null && timeTillExpiration > 5;
19
+ if (!isCookieFresh) {
20
+ console.info(`Cookie should be refreshed, time till expiration: ${timeTillExpiration} seconds`);
21
+ }
22
+ return !isCookieFresh;
23
+ }
24
+ async refreshCookie() {
25
+ if (!this.shouldRefreshCookie()) {
26
+ return this.cookie;
27
+ }
28
+ const path = this.edgeBaseUrl + '/auth/api_key/login';
29
+ this.cookie = await (0, cookie_1.getCookieWithExpiration)(path, this.config.apiKey || null);
30
+ if (this.cookie) {
31
+ console.info('Cookie refreshed');
32
+ }
33
+ return this.cookie;
34
+ }
35
+ getDomain() {
36
+ switch (this.config.env) {
37
+ case config_1.GrvtEnvironment.PRODUCTION:
38
+ return 'grvt.io';
39
+ case config_1.GrvtEnvironment.TESTNET:
40
+ return 'testnet.grvt.io';
41
+ case config_1.GrvtEnvironment.STAGING:
42
+ return 'staging.gravitymarkets.io';
43
+ case config_1.GrvtEnvironment.DEV:
44
+ return 'dev.gravitymarkets.io';
45
+ default:
46
+ throw new Error(`Unknown environment: ${this.config.env}`);
47
+ }
48
+ }
49
+ }
50
+ exports.GrvtBaseClient = GrvtBaseClient;
51
+ //# sourceMappingURL=GrvtBaseClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GrvtBaseClient.js","sourceRoot":"","sources":["../../src/client/GrvtBaseClient.ts"],"names":[],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IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAEO,SAAS;QACf,QAAQ,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YACxB,KAAK,wBAAe,CAAC,UAAU;gBAC7B,OAAO,SAAS,CAAC;YACnB,KAAK,wBAAe,CAAC,OAAO;gBAC1B,OAAO,iBAAiB,CAAC;YAC3B,KAAK,wBAAe,CAAC,OAAO;gBAC1B,OAAO,2BAA2B,CAAC;YACrC,KAAK,wBAAe,CAAC,GAAG;gBACtB,OAAO,uBAAuB,CAAC;YACjC;gBACE,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF;AA1DD,wCA0DC"}
@@ -0,0 +1,38 @@
1
+ import { GrvtConfig } from '../config/config';
2
+ import { GrvtBaseClient } from './GrvtBaseClient';
3
+ import { TDG, MDG } from 'grvt';
4
+ import { Wallet } from 'ethers';
5
+ import { IApiSubAccountSummaryResponse, IApiFundingAccountSummaryResponse, IApiTransferHistoryRequest, IApiTransferHistoryResponse, IApiSubAccountSummaryRequest, IApiTransferRequest } from 'grvt';
6
+ export declare class GrvtClient extends GrvtBaseClient {
7
+ protected tdgClient: TDG;
8
+ protected mdgClient: MDG;
9
+ protected wallet?: Wallet;
10
+ protected tradesBaseUrl: string;
11
+ protected marketDataBaseUrl: string;
12
+ constructor(config: GrvtConfig);
13
+ /**
14
+ * Get funding account summary
15
+ * @returns Promise with funding account summary data
16
+ */
17
+ getFundingAccountSummary(): Promise<IApiFundingAccountSummaryResponse>;
18
+ /**
19
+ * Get sub account summary
20
+ * @returns Promise with sub account summary data
21
+ */
22
+ getSubAccountSummary(request: IApiSubAccountSummaryRequest): Promise<IApiSubAccountSummaryResponse>;
23
+ /**
24
+ * Transfer funds between accounts
25
+ * @param request - Transfer request
26
+ * @returns Promise with transfer response
27
+ */
28
+ transfer(request: IApiTransferRequest): Promise<{
29
+ acknowledgement: boolean;
30
+ }>;
31
+ /**
32
+ * Get transfer history
33
+ * @returns Promise with transfer history response
34
+ */
35
+ getTransferHistory(request: IApiTransferHistoryRequest): Promise<IApiTransferHistoryResponse>;
36
+ private authenticatedEndpoint;
37
+ private getAxiosConfig;
38
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GrvtClient = void 0;
4
+ const transfer_1 = require("../signing/transfer");
5
+ const GrvtBaseClient_1 = require("./GrvtBaseClient");
6
+ const axios_1 = require("axios");
7
+ const grvt_1 = require("grvt");
8
+ const ethers_1 = require("ethers");
9
+ class GrvtClient extends GrvtBaseClient_1.GrvtBaseClient {
10
+ constructor(config) {
11
+ super(config);
12
+ this.tradesBaseUrl = `https://trades.${this.domain}`;
13
+ this.marketDataBaseUrl = `https://market-data.${this.domain}`;
14
+ this.tdgClient = new grvt_1.TDG({
15
+ host: this.tradesBaseUrl,
16
+ });
17
+ this.mdgClient = new grvt_1.MDG({
18
+ host: this.marketDataBaseUrl,
19
+ });
20
+ if (config.apiSecret) {
21
+ this.wallet = new ethers_1.Wallet(config.apiSecret);
22
+ }
23
+ }
24
+ /**
25
+ * Get funding account summary
26
+ * @returns Promise with funding account summary data
27
+ */
28
+ async getFundingAccountSummary() {
29
+ const config = await this.authenticatedEndpoint();
30
+ return this.tdgClient.fundingAccountSummary(config);
31
+ }
32
+ /**
33
+ * Get sub account summary
34
+ * @returns Promise with sub account summary data
35
+ */
36
+ async getSubAccountSummary(request) {
37
+ const config = await this.authenticatedEndpoint();
38
+ return this.tdgClient.subAccountSummary(request, config);
39
+ }
40
+ /**
41
+ * Transfer funds between accounts
42
+ * @param request - Transfer request
43
+ * @returns Promise with transfer response
44
+ */
45
+ async transfer(request) {
46
+ if (!this.wallet) {
47
+ throw new Error('API secret is required for transfer');
48
+ }
49
+ const signedTransfer = await (0, transfer_1.signTransfer)(request, this.wallet, this.config.env);
50
+ const config = await this.authenticatedEndpoint();
51
+ return this.tdgClient.transfer(signedTransfer, config);
52
+ }
53
+ /**
54
+ * Get transfer history
55
+ * @returns Promise with transfer history response
56
+ */
57
+ async getTransferHistory(request) {
58
+ const config = await this.authenticatedEndpoint();
59
+ return this.tdgClient.transferHistory(request, config);
60
+ }
61
+ async authenticatedEndpoint() {
62
+ await this.refreshCookie();
63
+ return this.getAxiosConfig();
64
+ }
65
+ getAxiosConfig() {
66
+ let headers = new axios_1.AxiosHeaders();
67
+ headers = headers.set('Content-Type', 'application/json');
68
+ if (this.cookie?.gravity) {
69
+ headers = headers.set('Cookie', `gravity=${this.cookie.gravity}`);
70
+ }
71
+ if (this.cookie?.XGrvtAccountId) {
72
+ headers = headers.set('X-Grvt-Account-Id', this.cookie.XGrvtAccountId);
73
+ }
74
+ return {
75
+ headers,
76
+ };
77
+ }
78
+ }
79
+ exports.GrvtClient = GrvtClient;
80
+ //# sourceMappingURL=GrvtClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GrvtClient.js","sourceRoot":"","sources":["../../src/client/GrvtClient.ts"],"names":[],"mappings":";;;AAAA,kDAAmD;AAEnD,qDAAkD;AAClD,iCAAyD;AACzD,+BAAgC;AAChC,mCAAgC;AAUhC,MAAa,UAAW,SAAQ,+BAAc;IAO5C,YAAY,MAAkB;QAC5B,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,aAAa,GAAG,kBAAkB,IAAI,CAAC,MAAM,EAAE,CAAC;QACrD,IAAI,CAAC,iBAAiB,GAAG,uBAAuB,IAAI,CAAC,MAAM,EAAE,CAAC;QAC9D,IAAI,CAAC,SAAS,GAAG,IAAI,UAAG,CAAC;YACvB,IAAI,EAAE,IAAI,CAAC,aAAa;SACzB,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,UAAG,CAAC;YACvB,IAAI,EAAE,IAAI,CAAC,iBAAiB;SAC7B,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,IA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,EAAE,CAAC;IAC/B,CAAC;IAEO,cAAc;QACpB,IAAI,OAAO,GAAG,IAAI,oBAAY,EAAE,CAAC;QACjC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YACzB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YAChC,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;QACzE,CAAC;QAED,OAAO;YACL,OAAO;SACR,CAAC;IACJ,CAAC;CACF;AAxFD,gCAwFC"}
@@ -0,0 +1,27 @@
1
+ import { GrvtEnvironment } from '../config/config';
2
+ import { GrvtBaseClient } from './GrvtBaseClient';
3
+ import { TMessageHandler } from 'grvt/ws';
4
+ import { IWSTransferFeedDataV1 } from 'grvt';
5
+ export declare class GrvtWsClient extends GrvtBaseClient {
6
+ private ws;
7
+ private readonly url;
8
+ private messageHandlers;
9
+ private reconnectAttempts;
10
+ private readonly maxReconnectAttempts;
11
+ private reconnectTimeout;
12
+ private subscriptionId;
13
+ private readonly wsReadTimeout;
14
+ private lastMessageTime;
15
+ private messageCheckInterval;
16
+ constructor(config: {
17
+ apiKey: string;
18
+ env: GrvtEnvironment;
19
+ });
20
+ private getWebSocketUrl;
21
+ connect(): Promise<void>;
22
+ private startMessageCheck;
23
+ private stopMessageCheck;
24
+ private handleReconnect;
25
+ subscribeTransferHistory(main_account_id: string, handler: TMessageHandler<Required<IWSTransferFeedDataV1>['feed']>, sub_account_id?: string): void;
26
+ disconnect(): void;
27
+ }