@pear-protocol/exchanges-sdk 0.0.18 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +73 -137
  2. package/dist/client/base-ws.d.ts +30 -0
  3. package/dist/client/base-ws.js +113 -0
  4. package/dist/client/binance/exchange-ws.d.ts +19 -0
  5. package/dist/client/binance/exchange-ws.js +26 -0
  6. package/dist/{account/exchanges → client}/binance/rest.d.ts +2 -6
  7. package/dist/{account/exchanges → client}/binance/rest.js +4 -11
  8. package/dist/client/binance/types.d.ts +68 -0
  9. package/dist/client/binance/types.js +1 -0
  10. package/dist/client/binance/ws.d.ts +30 -0
  11. package/dist/client/binance/ws.js +54 -0
  12. package/dist/client/bybit/exchange-ws.d.ts +20 -0
  13. package/dist/client/bybit/exchange-ws.js +28 -0
  14. package/dist/{account/exchanges → client}/bybit/rest.js +3 -2
  15. package/dist/{account/exchanges → client}/bybit/types.d.ts +1 -9
  16. package/dist/client/bybit/types.js +1 -0
  17. package/dist/client/bybit/ws.d.ts +17 -0
  18. package/dist/client/bybit/ws.js +50 -0
  19. package/dist/client/exchange-ws.d.ts +12 -0
  20. package/dist/client/exchange-ws.js +10 -0
  21. package/dist/client/hyperliquid/exchange-ws.d.ts +15 -0
  22. package/dist/client/hyperliquid/exchange-ws.js +21 -0
  23. package/dist/client/hyperliquid/rest.d.ts +3 -0
  24. package/dist/client/hyperliquid/rest.js +12 -0
  25. package/dist/{account/exchanges → client}/hyperliquid/types.d.ts +93 -39
  26. package/dist/client/hyperliquid/types.js +1 -0
  27. package/dist/client/hyperliquid/ws.d.ts +10 -0
  28. package/dist/client/hyperliquid/ws.js +16 -0
  29. package/dist/client/index.d.ts +31 -0
  30. package/dist/client/index.js +47 -0
  31. package/dist/client/lighter/constants.d.ts +4 -0
  32. package/dist/client/lighter/constants.js +4 -0
  33. package/dist/client/lighter/exchange-ws.d.ts +15 -0
  34. package/dist/client/lighter/exchange-ws.js +21 -0
  35. package/dist/client/lighter/rest.d.ts +56 -0
  36. package/dist/client/lighter/rest.js +27 -0
  37. package/dist/client/lighter/types.d.ts +32 -0
  38. package/dist/client/lighter/types.js +1 -0
  39. package/dist/client/lighter/ws.d.ts +10 -0
  40. package/dist/client/lighter/ws.js +17 -0
  41. package/dist/client/okx/exchange-ws.d.ts +20 -0
  42. package/dist/client/okx/exchange-ws.js +28 -0
  43. package/dist/{account/exchanges → client}/okx/rest.js +2 -2
  44. package/dist/{account/exchanges → client}/okx/types.d.ts +1 -10
  45. package/dist/client/okx/types.js +1 -0
  46. package/dist/client/okx/ws.d.ts +17 -0
  47. package/dist/client/okx/ws.js +61 -0
  48. package/dist/helper/factory.d.ts +10 -0
  49. package/dist/helper/factory.js +12 -0
  50. package/dist/helper/index.d.ts +7 -0
  51. package/dist/helper/index.js +2 -0
  52. package/dist/helper/lighter/ethereum/abi.d.ts +66 -0
  53. package/dist/helper/lighter/ethereum/abi.js +40 -0
  54. package/dist/helper/lighter/ethereum/index.d.ts +8 -0
  55. package/dist/helper/lighter/ethereum/index.js +34 -0
  56. package/dist/helper/lighter/ethereum/types.d.ts +23 -0
  57. package/dist/helper/lighter/ethereum/types.js +1 -0
  58. package/dist/helper/lighter/helper.d.ts +9 -0
  59. package/dist/helper/lighter/helper.js +67 -0
  60. package/dist/helper/lighter/index.d.ts +6 -0
  61. package/dist/helper/lighter/index.js +2 -0
  62. package/dist/helper/lighter/types.d.ts +63 -0
  63. package/dist/helper/lighter/types.js +35 -0
  64. package/dist/helper/types.d.ts +11 -0
  65. package/dist/helper/types.js +1 -0
  66. package/dist/index.d.ts +43 -24
  67. package/dist/index.js +6 -21
  68. package/dist/sdk.d.ts +43 -0
  69. package/dist/sdk.js +53 -0
  70. package/dist/syncer/base.d.ts +40 -0
  71. package/dist/syncer/base.js +50 -0
  72. package/dist/syncer/binance/syncer.d.ts +24 -0
  73. package/dist/syncer/binance/syncer.js +9 -0
  74. package/dist/syncer/bybit/syncer.d.ts +24 -0
  75. package/dist/syncer/bybit/syncer.js +9 -0
  76. package/dist/syncer/factory.d.ts +22 -0
  77. package/dist/syncer/factory.js +26 -0
  78. package/dist/syncer/hyperliquid/syncer.d.ts +26 -0
  79. package/dist/syncer/hyperliquid/syncer.js +43 -0
  80. package/dist/syncer/index.d.ts +24 -0
  81. package/dist/syncer/index.js +7 -0
  82. package/dist/syncer/lighter/syncer.d.ts +24 -0
  83. package/dist/syncer/lighter/syncer.js +9 -0
  84. package/dist/syncer/okx/syncer.d.ts +24 -0
  85. package/dist/syncer/okx/syncer.js +9 -0
  86. package/dist/tracker/base.d.ts +79 -0
  87. package/dist/tracker/base.js +120 -0
  88. package/dist/tracker/binance/const.d.ts +4 -0
  89. package/dist/tracker/binance/const.js +4 -0
  90. package/dist/{account/exchanges → tracker}/binance/mapper.d.ts +4 -1
  91. package/dist/{account/exchanges → tracker}/binance/mapper.js +7 -6
  92. package/dist/tracker/binance/tracker.d.ts +60 -0
  93. package/dist/tracker/binance/tracker.js +181 -0
  94. package/dist/tracker/binance/types.d.ts +6 -0
  95. package/dist/{account/exchanges → tracker}/bybit/mapper.d.ts +5 -3
  96. package/dist/{account/exchanges → tracker}/bybit/mapper.js +11 -10
  97. package/dist/tracker/bybit/tracker.d.ts +51 -0
  98. package/dist/tracker/bybit/tracker.js +138 -0
  99. package/dist/tracker/bybit/types.d.ts +7 -0
  100. package/dist/{account/exchanges → tracker}/hyperliquid/mapper.d.ts +6 -4
  101. package/dist/{account/exchanges → tracker}/hyperliquid/mapper.js +18 -16
  102. package/dist/tracker/hyperliquid/tracker.d.ts +62 -0
  103. package/dist/tracker/hyperliquid/tracker.js +219 -0
  104. package/dist/tracker/hyperliquid/types.d.ts +23 -0
  105. package/dist/tracker/index.d.ts +38 -0
  106. package/dist/tracker/index.js +81 -0
  107. package/dist/tracker/lighter/const.d.ts +3 -0
  108. package/dist/tracker/lighter/const.js +3 -0
  109. package/dist/tracker/lighter/mapper.d.ts +16 -0
  110. package/dist/tracker/lighter/mapper.js +77 -0
  111. package/dist/tracker/lighter/tracker.d.ts +53 -0
  112. package/dist/tracker/lighter/tracker.js +150 -0
  113. package/dist/tracker/lighter/types.d.ts +16 -0
  114. package/dist/tracker/lighter/types.js +6 -0
  115. package/dist/{account/exchanges → tracker}/okx/mapper.d.ts +5 -3
  116. package/dist/{account/exchanges → tracker}/okx/mapper.js +11 -10
  117. package/dist/tracker/okx/tracker.d.ts +51 -0
  118. package/dist/tracker/okx/tracker.js +134 -0
  119. package/dist/tracker/okx/types.d.ts +8 -0
  120. package/dist/tracker/types.d.ts +63 -0
  121. package/dist/{account → tracker}/types.js +6 -4
  122. package/dist/tracker/utils.d.ts +11 -0
  123. package/dist/{account → tracker}/utils.js +0 -2
  124. package/dist/types.d.ts +50 -0
  125. package/dist/types.js +1 -0
  126. package/package.json +7 -5
  127. package/dist/account/account-manager.d.ts +0 -31
  128. package/dist/account/account-manager.js +0 -119
  129. package/dist/account/exchange-account.d.ts +0 -35
  130. package/dist/account/exchange-account.js +0 -158
  131. package/dist/account/exchanges/base.d.ts +0 -48
  132. package/dist/account/exchanges/base.js +0 -41
  133. package/dist/account/exchanges/binance/asset-tracker.d.ts +0 -26
  134. package/dist/account/exchanges/binance/asset-tracker.js +0 -38
  135. package/dist/account/exchanges/binance/const.d.ts +0 -10
  136. package/dist/account/exchanges/binance/const.js +0 -10
  137. package/dist/account/exchanges/binance/orchestrator.d.ts +0 -31
  138. package/dist/account/exchanges/binance/orchestrator.js +0 -91
  139. package/dist/account/exchanges/binance/state-handler.d.ts +0 -33
  140. package/dist/account/exchanges/binance/state-handler.js +0 -113
  141. package/dist/account/exchanges/binance/types.d.ts +0 -5
  142. package/dist/account/exchanges/binance/ws.d.ts +0 -23
  143. package/dist/account/exchanges/binance/ws.js +0 -69
  144. package/dist/account/exchanges/bybit/asset-tracker.d.ts +0 -26
  145. package/dist/account/exchanges/bybit/asset-tracker.js +0 -37
  146. package/dist/account/exchanges/bybit/const.d.ts +0 -7
  147. package/dist/account/exchanges/bybit/const.js +0 -7
  148. package/dist/account/exchanges/bybit/orchestrator.d.ts +0 -22
  149. package/dist/account/exchanges/bybit/orchestrator.js +0 -66
  150. package/dist/account/exchanges/bybit/state-handler.d.ts +0 -23
  151. package/dist/account/exchanges/bybit/state-handler.js +0 -70
  152. package/dist/account/exchanges/bybit/ws.d.ts +0 -19
  153. package/dist/account/exchanges/bybit/ws.js +0 -83
  154. package/dist/account/exchanges/hyperliquid/asset-tracker.d.ts +0 -35
  155. package/dist/account/exchanges/hyperliquid/asset-tracker.js +0 -83
  156. package/dist/account/exchanges/hyperliquid/orchestrator.d.ts +0 -26
  157. package/dist/account/exchanges/hyperliquid/orchestrator.js +0 -102
  158. package/dist/account/exchanges/hyperliquid/state-handler.d.ts +0 -25
  159. package/dist/account/exchanges/hyperliquid/state-handler.js +0 -104
  160. package/dist/account/exchanges/index.d.ts +0 -11
  161. package/dist/account/exchanges/index.js +0 -32
  162. package/dist/account/exchanges/okx/asset-tracker.d.ts +0 -26
  163. package/dist/account/exchanges/okx/asset-tracker.js +0 -34
  164. package/dist/account/exchanges/okx/const.d.ts +0 -7
  165. package/dist/account/exchanges/okx/const.js +0 -7
  166. package/dist/account/exchanges/okx/orchestrator.d.ts +0 -22
  167. package/dist/account/exchanges/okx/orchestrator.js +0 -57
  168. package/dist/account/exchanges/okx/state-handler.d.ts +0 -24
  169. package/dist/account/exchanges/okx/state-handler.js +0 -78
  170. package/dist/account/exchanges/okx/ws.d.ts +0 -20
  171. package/dist/account/exchanges/okx/ws.js +0 -103
  172. package/dist/account/index.d.ts +0 -11
  173. package/dist/account/index.js +0 -4
  174. package/dist/account/types.d.ts +0 -5
  175. package/dist/account/utils.d.ts +0 -10
  176. package/dist/credentials.d.ts +0 -28
  177. package/dist/credentials.js +0 -46
  178. package/dist/types-Caz2X4h0.d.ts +0 -151
  179. package/dist/utils/ws.d.ts +0 -10
  180. package/dist/utils/ws.js +0 -42
  181. /package/dist/{account/exchanges → client}/bybit/rest.d.ts +0 -0
  182. /package/dist/{utils → client}/hmac.d.ts +0 -0
  183. /package/dist/{utils → client}/hmac.js +0 -0
  184. /package/dist/{account/exchanges → client}/okx/rest.d.ts +0 -0
  185. /package/dist/{account/exchanges → tracker}/binance/types.js +0 -0
  186. /package/dist/{account/exchanges → tracker}/bybit/types.js +0 -0
  187. /package/dist/{account/exchanges → tracker}/hyperliquid/const.d.ts +0 -0
  188. /package/dist/{account/exchanges → tracker}/hyperliquid/const.js +0 -0
  189. /package/dist/{account/exchanges → tracker}/hyperliquid/types.js +0 -0
  190. /package/dist/{account/exchanges → tracker}/okx/types.js +0 -0
package/dist/index.d.ts CHANGED
@@ -1,25 +1,44 @@
1
- import PearSDK from '@pear-protocol/core-sdk';
2
- import { AccountManager } from './account/account-manager.js';
3
- export { ExchangeAccount } from './account/exchange-account.js';
4
- export { createOrchestrator } from './account/exchanges/index.js';
5
- export { A as ACCOUNT_TYPE_LABELS, a as AccountBalance, b as AccountConfig, c as AccountPosition, d as AccountType, e as AssetBalance, B as BalanceCallback, f as BinanceAccountType, E as ExchangeState, H as HyperliquidAccountCredentials, M as MarginMode, P as PositionsCallback, S as StateUpdate, g as SupportedCredentials, T as TrackedAssetCallback, h as TrackedAssetInfo, i as Tracker } from './types-Caz2X4h0.js';
6
- import { Credentials } from './credentials.js';
7
- export { BybitAccountType } from './account/exchanges/bybit/types.js';
8
- export { HyperliquidAccountType } from './account/exchanges/hyperliquid/types.js';
9
- export { OkxAccountType } from './account/exchanges/okx/types.js';
10
- export { Orchestrator, OrchestratorConfig } from './account/exchanges/base.js';
1
+ export { CreateExchangeWsConfig, ExchangeWsByConnector, createExchangeWs } from './client/index.js';
2
+ export { createLighterHelper } from './helper/lighter/helper.js';
3
+ export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './helper/lighter/types.js';
4
+ export { ExchangeHelperExchange, ExchangeHelperMap } from './helper/types.js';
5
+ export { ExchangesSDK } from './sdk.js';
6
+ export { AccountSyncer, AccountSyncerConfig, BaseAccountSyncer } from './syncer/base.js';
7
+ export { BinanceAccountSyncer } from './syncer/binance/syncer.js';
8
+ export { BybitAccountSyncer } from './syncer/bybit/syncer.js';
9
+ export { createAccountSyncer } from './syncer/factory.js';
10
+ export { HyperliquidAccountSyncer } from './syncer/hyperliquid/syncer.js';
11
+ export { LighterAccountSyncer } from './syncer/lighter/syncer.js';
12
+ export { OkxAccountSyncer } from './syncer/okx/syncer.js';
13
+ export { CreateAccountTrackerConfig, createAccountTracker } from './tracker/index.js';
14
+ export { ExchangeConnection, ExchangesSDKConfig, HyperliquidAccountCredentials, LighterAccountCredentials, SupportedCredentials } from './types.js';
15
+ export { ACCOUNT_TYPE_LABELS, AccountBalance, AccountPosition, AccountType, AssetBalance, BalanceCallback, ExchangeState, MarginMode, PositionsCallback, StateUpdate, TrackedAssetCallback, TrackedAssetInfo } from './tracker/types.js';
16
+ export { AccountTracker, AccountTrackerConfig, BaseAccountTracker } from './tracker/base.js';
17
+ export { ApiKey } from './client/lighter/rest.js';
18
+ export { BaseWs, MessageListener, OpenListener, WsMessage } from './client/base-ws.js';
19
+ export { BinanceAccountTracker, BinanceAccountTrackerConfig } from './tracker/binance/tracker.js';
20
+ export { BinanceAccountType } from './tracker/binance/types.js';
21
+ export { BinanceExchangeWs } from './client/binance/exchange-ws.js';
22
+ export { BinanceUserDataWs, BinanceUserDataWsConfig, BinanceWsApi, BinanceWsApiConfig } from './client/binance/ws.js';
23
+ export { BybitAccountTracker, BybitAccountTrackerConfig } from './tracker/bybit/tracker.js';
24
+ export { BybitAccountType } from './tracker/bybit/types.js';
25
+ export { BybitExchangeWs } from './client/bybit/exchange-ws.js';
26
+ export { BybitWs, BybitWsConfig } from './client/bybit/ws.js';
27
+ export { ExchangeWs } from './client/exchange-ws.js';
28
+ export { HyperliquidAccountTracker, HyperliquidAccountTrackerConfig } from './tracker/hyperliquid/tracker.js';
29
+ export { HyperliquidAccountType } from './tracker/hyperliquid/types.js';
30
+ export { HyperliquidExchangeWs } from './client/hyperliquid/exchange-ws.js';
31
+ export { HyperliquidWs } from './client/hyperliquid/ws.js';
32
+ export { LighterAccountTracker, LighterAccountTrackerConfig } from './tracker/lighter/tracker.js';
33
+ export { LighterAccountType } from './tracker/lighter/types.js';
34
+ export { LighterExchangeWs } from './client/lighter/exchange-ws.js';
35
+ export { LighterWs } from './client/lighter/ws.js';
36
+ export { OkxAccountTracker, OkxAccountTrackerConfig } from './tracker/okx/tracker.js';
37
+ export { OkxAccountType } from './tracker/okx/types.js';
38
+ export { OkxExchangeWs } from './client/okx/exchange-ws.js';
39
+ export { OkxWs, OkxWsConfig } from './client/okx/ws.js';
40
+ export { WalletClientWithAccount } from './helper/lighter/ethereum/types.js';
11
41
  import '@pear-protocol/types';
12
-
13
- type ExchangesSDKConfig = {
14
- sdk: PearSDK;
15
- demo?: boolean;
16
- };
17
- declare class ExchangesSDK {
18
- credentials: Credentials;
19
- account: AccountManager;
20
- sdk: PearSDK;
21
- constructor(config: ExchangesSDKConfig);
22
- destroy(): void;
23
- }
24
-
25
- export { AccountManager, Credentials, ExchangesSDK, type ExchangesSDKConfig };
42
+ import '@pear-protocol/core-sdk';
43
+ import 'partysocket';
44
+ import 'viem';
package/dist/index.js CHANGED
@@ -1,21 +1,6 @@
1
- import { AccountManager } from './account';
2
- export * from './account';
3
- import { Credentials } from './credentials';
4
- export * from './credentials';
5
-
6
- class ExchangesSDK {
7
- credentials;
8
- account;
9
- sdk;
10
- constructor(config) {
11
- this.sdk = config.sdk;
12
- this.credentials = new Credentials(config.sdk);
13
- this.account = new AccountManager(this.credentials, config.sdk, config.demo);
14
- }
15
- destroy() {
16
- this.account.destroy();
17
- this.credentials.clear();
18
- }
19
- }
20
-
21
- export { ExchangesSDK };
1
+ export * from './client';
2
+ export * from './helper';
3
+ export * from './sdk';
4
+ export * from './syncer';
5
+ export * from './tracker';
6
+ export * from './types';
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,43 @@
1
+ import { Connector } from '@pear-protocol/types';
2
+ import { ExchangeHelperExchange, ExchangeHelperMap } from './helper/types.js';
3
+ import { AccountSyncer } from './syncer/base.js';
4
+ import { ExchangesSDKConfig, ExchangeConnection } from './types.js';
5
+ import { AccountTracker } from './tracker/base.js';
6
+ import './helper/lighter/types.js';
7
+ import './helper/lighter/ethereum/types.js';
8
+ import 'viem';
9
+ import './client/lighter/rest.js';
10
+ import '@pear-protocol/core-sdk';
11
+ import './client/index.js';
12
+ import './client/binance/exchange-ws.js';
13
+ import './client/base-ws.js';
14
+ import 'partysocket';
15
+ import './client/exchange-ws.js';
16
+ import './client/binance/ws.js';
17
+ import './client/bybit/exchange-ws.js';
18
+ import './client/bybit/ws.js';
19
+ import './client/hyperliquid/exchange-ws.js';
20
+ import './client/hyperliquid/ws.js';
21
+ import './client/lighter/exchange-ws.js';
22
+ import './client/lighter/ws.js';
23
+ import './client/okx/exchange-ws.js';
24
+ import './client/okx/ws.js';
25
+ import './tracker/types.js';
26
+ import './tracker/binance/types.js';
27
+ import './tracker/bybit/types.js';
28
+ import './tracker/hyperliquid/types.js';
29
+ import './tracker/lighter/types.js';
30
+ import './tracker/okx/types.js';
31
+
32
+ declare class ExchangesSDK {
33
+ private sdk;
34
+ private demo;
35
+ constructor(config: ExchangesSDKConfig);
36
+ connect(tradeAccountId: string, exchange: Connector): Promise<ExchangeConnection>;
37
+ createTracker(connection: ExchangeConnection): AccountTracker;
38
+ createHelper<E extends ExchangeHelperExchange>(exchange: E): ExchangeHelperMap[E];
39
+ createSyncer(connection: ExchangeConnection): AccountSyncer;
40
+ private fetchCredentials;
41
+ }
42
+
43
+ export { ExchangesSDK };
package/dist/sdk.js ADDED
@@ -0,0 +1,53 @@
1
+ import { createExchangeWs } from './client';
2
+ import './helper';
3
+ import { createExchangeHelper } from './helper/factory';
4
+ import { createAccountSyncer } from './syncer';
5
+ import { createAccountTracker } from './tracker';
6
+
7
+ class ExchangesSDK {
8
+ sdk;
9
+ demo;
10
+ constructor(config) {
11
+ this.sdk = config.sdk;
12
+ this.demo = config.demo ?? false;
13
+ }
14
+ async connect(tradeAccountId, exchange) {
15
+ const credentials = await this.fetchCredentials(tradeAccountId, exchange);
16
+ const ws = await createExchangeWs(exchange, { demo: this.demo, credentials });
17
+ return { exchange, credentials, ws };
18
+ }
19
+ createTracker(connection) {
20
+ return createAccountTracker(connection.exchange, {
21
+ demo: this.demo,
22
+ credentials: connection.credentials,
23
+ ws: connection.ws
24
+ });
25
+ }
26
+ createHelper(exchange) {
27
+ return createExchangeHelper(exchange, this.sdk);
28
+ }
29
+ createSyncer(connection) {
30
+ return createAccountSyncer(connection.exchange, {
31
+ sdk: this.sdk,
32
+ connector: connection.exchange,
33
+ credentials: connection.credentials,
34
+ ws: connection.ws,
35
+ demo: this.demo
36
+ });
37
+ }
38
+ async fetchCredentials(tradeAccountId, exchange) {
39
+ const response = await this.sdk.core.accounts.credentials(tradeAccountId);
40
+ const baseCreds = response.credentials;
41
+ if (exchange === "hyperliquid" || exchange === "lighter") {
42
+ const { accounts } = await this.sdk.core.accounts.list();
43
+ const account = accounts.find((a) => a.id === tradeAccountId);
44
+ if (!account) {
45
+ throw new Error(`Trade account ${tradeAccountId} not found`);
46
+ }
47
+ return { ...baseCreds, accountIdentifier: account.exchangeIdentifier };
48
+ }
49
+ return baseCreds;
50
+ }
51
+ }
52
+
53
+ export { ExchangesSDK };
@@ -0,0 +1,40 @@
1
+ import PearSDK from '@pear-protocol/core-sdk';
2
+ import { Connector, InstrumentId, HttpTypes } from '@pear-protocol/types';
3
+ import { ExchangeWsByConnector } from '../client/index.js';
4
+ import { SupportedCredentials } from '../types.js';
5
+ import '../client/binance/exchange-ws.js';
6
+ import '../client/base-ws.js';
7
+ import 'partysocket';
8
+ import '../client/exchange-ws.js';
9
+ import '../client/binance/ws.js';
10
+ import '../client/bybit/exchange-ws.js';
11
+ import '../client/bybit/ws.js';
12
+ import '../client/hyperliquid/exchange-ws.js';
13
+ import '../client/hyperliquid/ws.js';
14
+ import '../client/lighter/exchange-ws.js';
15
+ import '../client/lighter/ws.js';
16
+ import '../client/okx/exchange-ws.js';
17
+ import '../client/okx/ws.js';
18
+
19
+ interface AccountSyncerConfig {
20
+ sdk: PearSDK;
21
+ connector: Connector;
22
+ credentials: SupportedCredentials;
23
+ ws: ExchangeWsByConnector[Connector];
24
+ demo: boolean;
25
+ }
26
+ interface AccountSyncer {
27
+ synchronize(): Promise<void>;
28
+ }
29
+ declare abstract class BaseAccountSyncer implements AccountSyncer {
30
+ protected sdk: PearSDK;
31
+ protected connector: Connector;
32
+ protected credentials: SupportedCredentials;
33
+ protected ws: ExchangeWsByConnector[Connector];
34
+ protected demo: boolean;
35
+ constructor(config: AccountSyncerConfig);
36
+ protected abstract listExternalFills(since: Date, instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
37
+ synchronize(): Promise<void>;
38
+ }
39
+
40
+ export { type AccountSyncer, type AccountSyncerConfig, BaseAccountSyncer };
@@ -0,0 +1,50 @@
1
+ import { computeSyncPayload } from '@pear-protocol/utils';
2
+
3
+ class BaseAccountSyncer {
4
+ sdk;
5
+ connector;
6
+ credentials;
7
+ ws;
8
+ demo;
9
+ constructor(config) {
10
+ this.sdk = config.sdk;
11
+ this.connector = config.connector;
12
+ this.credentials = config.credentials;
13
+ this.ws = config.ws;
14
+ this.demo = config.demo;
15
+ }
16
+ async synchronize() {
17
+ const [{ positions }, { fills: provisionalFills }] = await Promise.all([
18
+ this.sdk.core.positions.openLite(),
19
+ this.sdk.core.fills.provisionals()
20
+ ]);
21
+ if (!positions.length && !provisionalFills.length) return;
22
+ const [{ data: instruments }, since] = await Promise.all([
23
+ this.sdk.core.instruments.symbolToIdMap({ connector: this.connector }),
24
+ this.sdk.core.sync.since({
25
+ overlapMs: 6e4,
26
+ nowMs: Date.now(),
27
+ bootstrapLookbackMs: 30 * 24 * 60 * 60 * 1e3
28
+ })
29
+ ]);
30
+ const externalFills = await this.listExternalFills(new Date(since.since), instruments);
31
+ const payload = await computeSyncPayload({
32
+ openPositions: positions,
33
+ provisionalFills,
34
+ confirmedExchangeFillIds: since.confirmedExchangeFillIds ?? [],
35
+ externalFills
36
+ });
37
+ if (!payload) return;
38
+ if (payload.reconcilables) {
39
+ await this.sdk.core.sync.reconcile(payload.reconcilables);
40
+ }
41
+ if (payload.confirmables) {
42
+ await this.sdk.core.sync.confirm(payload.confirmables);
43
+ }
44
+ if (payload.creatables) {
45
+ await this.sdk.core.sync.create(payload.creatables);
46
+ }
47
+ }
48
+ }
49
+
50
+ export { BaseAccountSyncer };
@@ -0,0 +1,24 @@
1
+ import { InstrumentId, HttpTypes } from '@pear-protocol/types';
2
+ import { BaseAccountSyncer } from '../base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../../client/index.js';
5
+ import '../../types.js';
6
+ import '../../client/binance/exchange-ws.js';
7
+ import '../../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../../client/exchange-ws.js';
10
+ import '../../client/binance/ws.js';
11
+ import '../../client/bybit/exchange-ws.js';
12
+ import '../../client/bybit/ws.js';
13
+ import '../../client/hyperliquid/exchange-ws.js';
14
+ import '../../client/hyperliquid/ws.js';
15
+ import '../../client/lighter/exchange-ws.js';
16
+ import '../../client/lighter/ws.js';
17
+ import '../../client/okx/exchange-ws.js';
18
+ import '../../client/okx/ws.js';
19
+
20
+ declare class BinanceAccountSyncer extends BaseAccountSyncer {
21
+ protected listExternalFills(_since: Date, _instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
22
+ }
23
+
24
+ export { BinanceAccountSyncer };
@@ -0,0 +1,9 @@
1
+ import { BaseAccountSyncer } from '../base';
2
+
3
+ class BinanceAccountSyncer extends BaseAccountSyncer {
4
+ async listExternalFills(_since, _instrumentSymbolToIdMap) {
5
+ return [];
6
+ }
7
+ }
8
+
9
+ export { BinanceAccountSyncer };
@@ -0,0 +1,24 @@
1
+ import { InstrumentId, HttpTypes } from '@pear-protocol/types';
2
+ import { BaseAccountSyncer } from '../base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../../client/index.js';
5
+ import '../../types.js';
6
+ import '../../client/binance/exchange-ws.js';
7
+ import '../../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../../client/exchange-ws.js';
10
+ import '../../client/binance/ws.js';
11
+ import '../../client/bybit/exchange-ws.js';
12
+ import '../../client/bybit/ws.js';
13
+ import '../../client/hyperliquid/exchange-ws.js';
14
+ import '../../client/hyperliquid/ws.js';
15
+ import '../../client/lighter/exchange-ws.js';
16
+ import '../../client/lighter/ws.js';
17
+ import '../../client/okx/exchange-ws.js';
18
+ import '../../client/okx/ws.js';
19
+
20
+ declare class BybitAccountSyncer extends BaseAccountSyncer {
21
+ protected listExternalFills(_since: Date, _instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
22
+ }
23
+
24
+ export { BybitAccountSyncer };
@@ -0,0 +1,9 @@
1
+ import { BaseAccountSyncer } from '../base';
2
+
3
+ class BybitAccountSyncer extends BaseAccountSyncer {
4
+ async listExternalFills(_since, _instrumentSymbolToIdMap) {
5
+ return [];
6
+ }
7
+ }
8
+
9
+ export { BybitAccountSyncer };
@@ -0,0 +1,22 @@
1
+ import { Connector } from '@pear-protocol/types';
2
+ import { AccountSyncerConfig, AccountSyncer } from './base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../client/index.js';
5
+ import '../types.js';
6
+ import '../client/binance/exchange-ws.js';
7
+ import '../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../client/exchange-ws.js';
10
+ import '../client/binance/ws.js';
11
+ import '../client/bybit/exchange-ws.js';
12
+ import '../client/bybit/ws.js';
13
+ import '../client/hyperliquid/exchange-ws.js';
14
+ import '../client/hyperliquid/ws.js';
15
+ import '../client/lighter/exchange-ws.js';
16
+ import '../client/lighter/ws.js';
17
+ import '../client/okx/exchange-ws.js';
18
+ import '../client/okx/ws.js';
19
+
20
+ declare function createAccountSyncer(exchange: Connector, config: AccountSyncerConfig): AccountSyncer;
21
+
22
+ export { createAccountSyncer };
@@ -0,0 +1,26 @@
1
+ import { BinanceAccountSyncer } from './binance/syncer';
2
+ import { BybitAccountSyncer } from './bybit/syncer';
3
+ import { HyperliquidAccountSyncer } from './hyperliquid/syncer';
4
+ import { LighterAccountSyncer } from './lighter/syncer';
5
+ import { OkxAccountSyncer } from './okx/syncer';
6
+
7
+ function createAccountSyncer(exchange, config) {
8
+ switch (exchange) {
9
+ case "binance":
10
+ return new BinanceAccountSyncer(config);
11
+ case "bybit":
12
+ return new BybitAccountSyncer(config);
13
+ case "okx":
14
+ return new OkxAccountSyncer(config);
15
+ case "hyperliquid":
16
+ return new HyperliquidAccountSyncer(config);
17
+ case "lighter":
18
+ return new LighterAccountSyncer(config);
19
+ default: {
20
+ const _exhaustive = exchange;
21
+ throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
22
+ }
23
+ }
24
+ }
25
+
26
+ export { createAccountSyncer };
@@ -0,0 +1,26 @@
1
+ import { InstrumentId, HttpTypes } from '@pear-protocol/types';
2
+ import { BaseAccountSyncer, AccountSyncerConfig } from '../base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../../client/index.js';
5
+ import '../../types.js';
6
+ import '../../client/binance/exchange-ws.js';
7
+ import '../../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../../client/exchange-ws.js';
10
+ import '../../client/binance/ws.js';
11
+ import '../../client/bybit/exchange-ws.js';
12
+ import '../../client/bybit/ws.js';
13
+ import '../../client/hyperliquid/exchange-ws.js';
14
+ import '../../client/hyperliquid/ws.js';
15
+ import '../../client/lighter/exchange-ws.js';
16
+ import '../../client/lighter/ws.js';
17
+ import '../../client/okx/exchange-ws.js';
18
+ import '../../client/okx/ws.js';
19
+
20
+ declare class HyperliquidAccountSyncer extends BaseAccountSyncer {
21
+ private readonly address;
22
+ constructor(config: AccountSyncerConfig);
23
+ protected listExternalFills(since: Date, instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
24
+ }
25
+
26
+ export { HyperliquidAccountSyncer };
@@ -0,0 +1,43 @@
1
+ import { fetchInfo } from '../../client/hyperliquid/rest';
2
+ import { BaseAccountSyncer } from '../base';
3
+
4
+ class HyperliquidAccountSyncer extends BaseAccountSyncer {
5
+ address;
6
+ constructor(config) {
7
+ super(config);
8
+ const creds = config.credentials;
9
+ this.address = creds.accountIdentifier;
10
+ }
11
+ async listExternalFills(since, instrumentSymbolToIdMap) {
12
+ const result = await fetchInfo({
13
+ type: "userFillsByTime",
14
+ user: this.address,
15
+ startTime: since.getTime(),
16
+ aggregateByTime: true
17
+ });
18
+ return result.reduce((acc, fill) => {
19
+ const instrumentId = instrumentSymbolToIdMap[fill.coin];
20
+ if (!instrumentId) {
21
+ console.warn(`Instrument symbol ${fill.coin} not found in instrument symbol to id map.`);
22
+ return acc;
23
+ }
24
+ acc.push({
25
+ connector: "hyperliquid",
26
+ exchangeFillId: fill.tid.toFixed(),
27
+ cloid: fill.cloid ?? null,
28
+ symbol: instrumentId,
29
+ price: fill.px,
30
+ quantity: fill.sz,
31
+ side: fill.side === "B" ? "BUY" : "SELL",
32
+ reduceOnly: fill.dir.includes("Close"),
33
+ timestamp: fill.time,
34
+ tradeFee: fill.fee,
35
+ builderFee: fill.builderFee ?? "0",
36
+ liquidation: fill.liquidation ? { mark: fill.liquidation.markPx } : null
37
+ });
38
+ return acc;
39
+ }, []);
40
+ }
41
+ }
42
+
43
+ export { HyperliquidAccountSyncer };
@@ -0,0 +1,24 @@
1
+ export { AccountSyncer, AccountSyncerConfig, BaseAccountSyncer } from './base.js';
2
+ export { BinanceAccountSyncer } from './binance/syncer.js';
3
+ export { BybitAccountSyncer } from './bybit/syncer.js';
4
+ export { createAccountSyncer } from './factory.js';
5
+ export { HyperliquidAccountSyncer } from './hyperliquid/syncer.js';
6
+ export { LighterAccountSyncer } from './lighter/syncer.js';
7
+ export { OkxAccountSyncer } from './okx/syncer.js';
8
+ import '@pear-protocol/core-sdk';
9
+ import '@pear-protocol/types';
10
+ import '../client/index.js';
11
+ import '../types.js';
12
+ import '../client/binance/exchange-ws.js';
13
+ import '../client/base-ws.js';
14
+ import 'partysocket';
15
+ import '../client/exchange-ws.js';
16
+ import '../client/binance/ws.js';
17
+ import '../client/bybit/exchange-ws.js';
18
+ import '../client/bybit/ws.js';
19
+ import '../client/hyperliquid/exchange-ws.js';
20
+ import '../client/hyperliquid/ws.js';
21
+ import '../client/lighter/exchange-ws.js';
22
+ import '../client/lighter/ws.js';
23
+ import '../client/okx/exchange-ws.js';
24
+ import '../client/okx/ws.js';
@@ -0,0 +1,7 @@
1
+ export * from './base';
2
+ export * from './binance/syncer';
3
+ export * from './bybit/syncer';
4
+ export * from './factory';
5
+ export * from './hyperliquid/syncer';
6
+ export * from './lighter/syncer';
7
+ export * from './okx/syncer';
@@ -0,0 +1,24 @@
1
+ import { InstrumentId, HttpTypes } from '@pear-protocol/types';
2
+ import { BaseAccountSyncer } from '../base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../../client/index.js';
5
+ import '../../types.js';
6
+ import '../../client/binance/exchange-ws.js';
7
+ import '../../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../../client/exchange-ws.js';
10
+ import '../../client/binance/ws.js';
11
+ import '../../client/bybit/exchange-ws.js';
12
+ import '../../client/bybit/ws.js';
13
+ import '../../client/hyperliquid/exchange-ws.js';
14
+ import '../../client/hyperliquid/ws.js';
15
+ import '../../client/lighter/exchange-ws.js';
16
+ import '../../client/lighter/ws.js';
17
+ import '../../client/okx/exchange-ws.js';
18
+ import '../../client/okx/ws.js';
19
+
20
+ declare class LighterAccountSyncer extends BaseAccountSyncer {
21
+ protected listExternalFills(_since: Date, _instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
22
+ }
23
+
24
+ export { LighterAccountSyncer };
@@ -0,0 +1,9 @@
1
+ import { BaseAccountSyncer } from '../base';
2
+
3
+ class LighterAccountSyncer extends BaseAccountSyncer {
4
+ async listExternalFills(_since, _instrumentSymbolToIdMap) {
5
+ return [];
6
+ }
7
+ }
8
+
9
+ export { LighterAccountSyncer };
@@ -0,0 +1,24 @@
1
+ import { InstrumentId, HttpTypes } from '@pear-protocol/types';
2
+ import { BaseAccountSyncer } from '../base.js';
3
+ import '@pear-protocol/core-sdk';
4
+ import '../../client/index.js';
5
+ import '../../types.js';
6
+ import '../../client/binance/exchange-ws.js';
7
+ import '../../client/base-ws.js';
8
+ import 'partysocket';
9
+ import '../../client/exchange-ws.js';
10
+ import '../../client/binance/ws.js';
11
+ import '../../client/bybit/exchange-ws.js';
12
+ import '../../client/bybit/ws.js';
13
+ import '../../client/hyperliquid/exchange-ws.js';
14
+ import '../../client/hyperliquid/ws.js';
15
+ import '../../client/lighter/exchange-ws.js';
16
+ import '../../client/lighter/ws.js';
17
+ import '../../client/okx/exchange-ws.js';
18
+ import '../../client/okx/ws.js';
19
+
20
+ declare class OkxAccountSyncer extends BaseAccountSyncer {
21
+ protected listExternalFills(_since: Date, _instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
22
+ }
23
+
24
+ export { OkxAccountSyncer };
@@ -0,0 +1,9 @@
1
+ import { BaseAccountSyncer } from '../base';
2
+
3
+ class OkxAccountSyncer extends BaseAccountSyncer {
4
+ async listExternalFills(_since, _instrumentSymbolToIdMap) {
5
+ return [];
6
+ }
7
+ }
8
+
9
+ export { OkxAccountSyncer };