@pear-protocol/exchanges-sdk 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/client/binance/rest.d.ts +4 -2
  2. package/dist/client/binance/rest.js +75 -1
  3. package/dist/client/binance/types.d.ts +36 -1
  4. package/dist/client/bybit/rest.d.ts +3 -2
  5. package/dist/client/bybit/rest.js +34 -1
  6. package/dist/client/bybit/types.d.ts +14 -1
  7. package/dist/client/hyperliquid/types.d.ts +76 -1
  8. package/dist/client/lighter/rest.d.ts +4 -1
  9. package/dist/client/lighter/rest.js +36 -1
  10. package/dist/client/lighter/types.d.ts +22 -1
  11. package/dist/client/okx/rest.d.ts +3 -2
  12. package/dist/client/okx/rest.js +28 -1
  13. package/dist/client/okx/types.d.ts +18 -1
  14. package/dist/helper/factory.d.ts +1 -0
  15. package/dist/helper/index.d.ts +2 -1
  16. package/dist/helper/lighter/helper.d.ts +2 -1
  17. package/dist/helper/lighter/index.d.ts +3 -2
  18. package/dist/helper/lighter/index.js +1 -1
  19. package/dist/helper/lighter/types.d.ts +1 -0
  20. package/dist/helper/types.d.ts +1 -0
  21. package/dist/index.d.ts +13 -2
  22. package/dist/sdk.d.ts +3 -2
  23. package/dist/sdk.js +4 -3
  24. package/dist/syncer/base.d.ts +20 -6
  25. package/dist/syncer/base.js +47 -2
  26. package/dist/syncer/binance/syncer.d.ts +31 -0
  27. package/dist/syncer/binance/syncer.js +82 -0
  28. package/dist/syncer/bybit/syncer.d.ts +28 -0
  29. package/dist/syncer/bybit/syncer.js +36 -0
  30. package/dist/syncer/factory.d.ts +22 -0
  31. package/dist/syncer/factory.js +26 -0
  32. package/dist/syncer/hyperliquid/syncer.d.ts +28 -0
  33. package/dist/syncer/hyperliquid/syncer.js +53 -0
  34. package/dist/syncer/index.d.ts +12 -1
  35. package/dist/syncer/index.js +6 -0
  36. package/dist/syncer/lighter/syncer.d.ts +37 -0
  37. package/dist/syncer/lighter/syncer.js +94 -0
  38. package/dist/syncer/okx/syncer.d.ts +29 -0
  39. package/dist/syncer/okx/syncer.js +48 -0
  40. package/package.json +7 -9
@@ -1,5 +1,5 @@
1
1
  import { BinanceCredentialsDTO } from '@pear-protocol/types';
2
- import { BinanceRawAccountStatus, BinanceRawPositionRisk } from './types.js';
2
+ import { BinanceRawAccountStatus, BinanceRawOrder, BinanceRawPositionRisk, BinanceRawUserTrade } from './types.js';
3
3
 
4
4
  declare function createListenKey(apiKey: string, demo?: boolean): Promise<string>;
5
5
  declare function keepAliveListenKey(apiKey: string, demo?: boolean): Promise<void>;
@@ -7,5 +7,7 @@ declare function fetchAccountStatus(creds: BinanceCredentialsDTO, demo: boolean)
7
7
  declare function fetchPositionRisk(creds: BinanceCredentialsDTO, symbol: string, demo: boolean): Promise<BinanceRawPositionRisk | undefined>;
8
8
  declare function fetchAllPositionRisk(creds: BinanceCredentialsDTO, demo: boolean): Promise<BinanceRawPositionRisk[]>;
9
9
  declare function fetchMultiAssetsMargin(creds: BinanceCredentialsDTO, demo: boolean): Promise<boolean>;
10
+ declare function fetchUserTradesSince(creds: BinanceCredentialsDTO, symbols: string[], since: Date, demo: boolean): Promise<BinanceRawUserTrade[]>;
11
+ declare function fetchAllOrdersSince(creds: BinanceCredentialsDTO, symbols: string[], since: Date, demo: boolean): Promise<BinanceRawOrder[]>;
10
12
 
11
- export { createListenKey, fetchAccountStatus, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, keepAliveListenKey };
13
+ export { createListenKey, fetchAccountStatus, fetchAllOrdersSince, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, fetchUserTradesSince, keepAliveListenKey };
@@ -54,5 +54,79 @@ async function fetchMultiAssetsMargin(creds, demo) {
54
54
  const res = await signedGet(creds, "/fapi/v1/multiAssetsMargin", {}, demo);
55
55
  return res.multiAssetsMargin;
56
56
  }
57
+ const USER_TRADES_LIMIT = 1e3;
58
+ const ALL_ORDERS_LIMIT = 1e3;
59
+ const BINANCE_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
60
+ async function fetchUserTradesSince(creds, symbols, since, demo) {
61
+ const now = Date.now();
62
+ const results = [];
63
+ for (const symbol of symbols) {
64
+ let windowStart = since.getTime();
65
+ while (windowStart <= now) {
66
+ const windowEnd = Math.min(windowStart + BINANCE_MAX_WINDOW_MS - 1, now);
67
+ let pageStart = windowStart;
68
+ while (pageStart <= windowEnd) {
69
+ const page = await signedGet(
70
+ creds,
71
+ "/fapi/v1/userTrades",
72
+ {
73
+ symbol,
74
+ startTime: pageStart.toString(),
75
+ endTime: windowEnd.toString(),
76
+ limit: USER_TRADES_LIMIT.toString()
77
+ },
78
+ demo
79
+ );
80
+ results.push(...page);
81
+ if (page.length < USER_TRADES_LIMIT) break;
82
+ const last = page[page.length - 1];
83
+ if (!last || last.time <= pageStart) break;
84
+ pageStart = last.time + 1;
85
+ }
86
+ windowStart = windowEnd + 1;
87
+ }
88
+ }
89
+ const byId = /* @__PURE__ */ new Map();
90
+ for (const trade of results) {
91
+ byId.set(`${trade.symbol}:${trade.id}`, trade);
92
+ }
93
+ return Array.from(byId.values());
94
+ }
95
+ async function fetchAllOrdersSince(creds, symbols, since, demo) {
96
+ const now = Date.now();
97
+ const results = [];
98
+ for (const symbol of symbols) {
99
+ let windowStart = since.getTime();
100
+ while (windowStart <= now) {
101
+ const windowEnd = Math.min(windowStart + BINANCE_MAX_WINDOW_MS - 1, now);
102
+ let pageStart = windowStart;
103
+ while (pageStart <= windowEnd) {
104
+ const page = await signedGet(
105
+ creds,
106
+ "/fapi/v1/allOrders",
107
+ {
108
+ symbol,
109
+ startTime: pageStart.toString(),
110
+ endTime: windowEnd.toString(),
111
+ limit: ALL_ORDERS_LIMIT.toString()
112
+ },
113
+ demo
114
+ );
115
+ results.push(...page);
116
+ if (page.length < ALL_ORDERS_LIMIT) break;
117
+ const last = page[page.length - 1];
118
+ const lastTs = last ? Math.max(last.updateTime, last.time) : pageStart;
119
+ if (lastTs <= pageStart) break;
120
+ pageStart = lastTs + 1;
121
+ }
122
+ windowStart = windowEnd + 1;
123
+ }
124
+ }
125
+ const byId = /* @__PURE__ */ new Map();
126
+ for (const order of results) {
127
+ byId.set(`${order.symbol}:${order.orderId}`, order);
128
+ }
129
+ return Array.from(byId.values());
130
+ }
57
131
 
58
- export { createListenKey, fetchAccountStatus, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, keepAliveListenKey };
132
+ export { createListenKey, fetchAccountStatus, fetchAllOrdersSince, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, fetchUserTradesSince, keepAliveListenKey };
@@ -40,6 +40,41 @@ interface BinanceRawAccountStatus {
40
40
  interface BinanceMultiAssetsMarginResponse {
41
41
  multiAssetsMargin: boolean;
42
42
  }
43
+ interface BinanceRawUserTrade {
44
+ buyer: boolean;
45
+ commission: string;
46
+ commissionAsset: string;
47
+ id: number;
48
+ maker: boolean;
49
+ orderId: number;
50
+ price: string;
51
+ qty: string;
52
+ quoteQty: string;
53
+ realizedPnl: string;
54
+ side: 'BUY' | 'SELL';
55
+ positionSide: string;
56
+ symbol: string;
57
+ time: number;
58
+ }
59
+ interface BinanceRawOrder {
60
+ avgPrice: string;
61
+ clientOrderId: string;
62
+ cumQuote: string;
63
+ executedQty: string;
64
+ orderId: number;
65
+ origQty: string;
66
+ origType: string;
67
+ price: string;
68
+ reduceOnly: boolean;
69
+ side: 'BUY' | 'SELL';
70
+ positionSide: string;
71
+ status: string;
72
+ symbol: string;
73
+ time: number;
74
+ timeInForce: string;
75
+ type: string;
76
+ updateTime: number;
77
+ }
43
78
  interface BinanceAssetIndex {
44
79
  symbol: string;
45
80
  time: number;
@@ -65,4 +100,4 @@ interface BinanceRawUserDataEvent {
65
100
  };
66
101
  }
67
102
 
68
- export type { BinanceAssetIndex, BinanceMultiAssetsMarginResponse, BinanceRawAccountStatus, BinanceRawAsset, BinanceRawPositionRisk, BinanceRawUserDataEvent };
103
+ export type { BinanceAssetIndex, BinanceMultiAssetsMarginResponse, BinanceRawAccountStatus, BinanceRawAsset, BinanceRawOrder, BinanceRawPositionRisk, BinanceRawUserDataEvent, BinanceRawUserTrade };
@@ -1,10 +1,11 @@
1
1
  import { BybitCredentialsDTO } from '@pear-protocol/types';
2
- import { BybitRawAccountInfo, BybitRawPosition, BybitRawWallet } from './types.js';
2
+ import { BybitRawAccountInfo, BybitRawExecution, BybitRawPosition, BybitRawWallet } from './types.js';
3
3
 
4
4
  declare function fetchWalletBalance(creds: BybitCredentialsDTO, demo: boolean): Promise<BybitRawWallet | undefined>;
5
5
  declare function fetchPositions(creds: BybitCredentialsDTO, settleCoin: string, demo: boolean): Promise<BybitRawPosition[]>;
6
6
  declare function fetchPositionLeverage(creds: BybitCredentialsDTO, symbol: string, demo: boolean): Promise<BybitRawPosition | undefined>;
7
7
  declare function fetchAccountInfo(creds: BybitCredentialsDTO, demo: boolean): Promise<BybitRawAccountInfo>;
8
8
  declare function fetchCollateralRatios(creds: BybitCredentialsDTO, demo: boolean): Promise<Map<string, string>>;
9
+ declare function fetchExecutionsSince(creds: BybitCredentialsDTO, since: Date, demo: boolean): Promise<BybitRawExecution[]>;
9
10
 
10
- export { fetchAccountInfo, fetchCollateralRatios, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
11
+ export { fetchAccountInfo, fetchCollateralRatios, fetchExecutionsSince, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
@@ -72,5 +72,38 @@ async function fetchCollateralRatios(creds, demo) {
72
72
  }
73
73
  return ratios;
74
74
  }
75
+ const EXECUTIONS_LIMIT = 100;
76
+ const BYBIT_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
77
+ async function fetchExecutionsSince(creds, since, demo) {
78
+ const results = [];
79
+ const now = Date.now();
80
+ let windowStart = since.getTime();
81
+ while (windowStart <= now) {
82
+ const windowEnd = Math.min(windowStart + BYBIT_MAX_WINDOW_MS - 1, now);
83
+ let cursor;
84
+ do {
85
+ const result = await signedGet(
86
+ creds,
87
+ "/v5/execution/list",
88
+ {
89
+ category: "linear",
90
+ startTime: windowStart.toString(),
91
+ endTime: windowEnd.toString(),
92
+ limit: EXECUTIONS_LIMIT.toString(),
93
+ ...cursor ? { cursor } : {}
94
+ },
95
+ demo
96
+ );
97
+ results.push(...result.list ?? []);
98
+ cursor = result.nextPageCursor || void 0;
99
+ } while (cursor);
100
+ windowStart = windowEnd + 1;
101
+ }
102
+ const byId = /* @__PURE__ */ new Map();
103
+ for (const execution of results) {
104
+ byId.set(execution.execId, execution);
105
+ }
106
+ return Array.from(byId.values());
107
+ }
75
108
 
76
- export { fetchAccountInfo, fetchCollateralRatios, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
109
+ export { fetchAccountInfo, fetchCollateralRatios, fetchExecutionsSince, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
@@ -46,6 +46,19 @@ interface BybitRawPosition {
46
46
  tradeMode: string;
47
47
  liqPrice: string;
48
48
  }
49
+ interface BybitRawExecution {
50
+ symbol: string;
51
+ orderId: string;
52
+ orderLinkId: string;
53
+ side: 'Buy' | 'Sell';
54
+ execFee: string;
55
+ execId: string;
56
+ execPrice: string;
57
+ execQty: string;
58
+ execTime: string;
59
+ execType: string;
60
+ closedSize: string;
61
+ }
49
62
  interface BybitResponse<T> {
50
63
  retCode: number;
51
64
  retMsg: string;
@@ -59,4 +72,4 @@ type BybitWsMessage = {
59
72
  data: BybitRawPosition[];
60
73
  };
61
74
 
62
- export type { BybitRawAccountInfo, BybitRawCoin, BybitRawCollateralRatioEntry, BybitRawCollateralTier, BybitRawPosition, BybitRawWallet, BybitResponse, BybitWsMessage };
75
+ export type { BybitRawAccountInfo, BybitRawCoin, BybitRawCollateralRatioEntry, BybitRawCollateralTier, BybitRawExecution, BybitRawPosition, BybitRawWallet, BybitResponse, BybitWsMessage };
@@ -109,5 +109,80 @@ type WebData3Event = {
109
109
  leadingVaults?: unknown;
110
110
  }[];
111
111
  };
112
+ type UserFillsByTimeResponse = {
113
+ /** Asset symbol. */
114
+ coin: string;
115
+ /**
116
+ * Price.
117
+ * @pattern ^[0-9]+(\.[0-9]+)?$
118
+ */
119
+ px: string;
120
+ /**
121
+ * Size.
122
+ * @pattern ^[0-9]+(\.[0-9]+)?$
123
+ */
124
+ sz: string;
125
+ /** Order side ("B" = Bid/Buy, "A" = Ask/Sell). */
126
+ side: 'B' | 'A';
127
+ /** Timestamp when the trade occurred (in ms since epoch). */
128
+ time: number;
129
+ /**
130
+ * Start position size.
131
+ * @pattern ^-?[0-9]+(\.[0-9]+)?$
132
+ */
133
+ startPosition: string;
134
+ /** Direction indicator for frontend display. */
135
+ dir: string;
136
+ /**
137
+ * Realized PnL.
138
+ * @pattern ^-?[0-9]+(\.[0-9]+)?$
139
+ */
140
+ closedPnl: string;
141
+ /**
142
+ * L1 transaction hash.
143
+ * @pattern ^0x[a-fA-F0-9]{64}$
144
+ */
145
+ hash: `0x${string}`;
146
+ /** Order ID. */
147
+ oid: number;
148
+ /** Indicates if the fill was a taker order. */
149
+ crossed: boolean;
150
+ /**
151
+ * Fee charged or rebate received (negative indicates rebate).
152
+ * @pattern ^-?[0-9]+(\.[0-9]+)?$
153
+ */
154
+ fee: string;
155
+ /**
156
+ * Optional fee charged by the UI builder.
157
+ * @pattern ^-?[0-9]+(\.[0-9]+)?$
158
+ */
159
+ builderFee?: string;
160
+ /** Unique transaction identifier for a partial fill of an order. */
161
+ tid: number;
162
+ /** Token in which the fee is denominated (e.g., "USDC"). */
163
+ feeToken: string;
164
+ /** ID of the TWAP. */
165
+ twapId: number | null;
166
+ /**
167
+ * Client Order ID.
168
+ * @pattern ^0x[a-fA-F0-9]{32}$
169
+ */
170
+ cloid?: `0x${string}`;
171
+ /** Liquidation details. */
172
+ liquidation?: {
173
+ /**
174
+ * Address of the liquidated user.
175
+ * @pattern ^0x[a-fA-F0-9]{40}$
176
+ */
177
+ liquidatedUser: `0x${string}`;
178
+ /**
179
+ * Mark price at the time of liquidation.
180
+ * @pattern ^[0-9]+(\.[0-9]+)?$
181
+ */
182
+ markPx: string;
183
+ /** Liquidation method. */
184
+ method: 'market' | 'backstop';
185
+ };
186
+ };
112
187
 
113
- export type { ActiveAssetDataEvent, AllDexsClearinghouseStateEvent, AllPerpMetasResponse, AssetPosition, ClearinghouseStateResponse, LeverageInfo, MetaResponse, SpotClearinghouseStateResponse, SpotStateEvent, WebData3Event };
188
+ export type { ActiveAssetDataEvent, AllDexsClearinghouseStateEvent, AllPerpMetasResponse, AssetPosition, ClearinghouseStateResponse, LeverageInfo, MetaResponse, SpotClearinghouseStateResponse, SpotStateEvent, UserFillsByTimeResponse, WebData3Event };
@@ -1,3 +1,5 @@
1
+ import { LighterRawTrade } from './types.js';
2
+
1
3
  type ApiKey = {
2
4
  account_index: number;
3
5
  api_key_index: number;
@@ -52,5 +54,6 @@ declare function fetchApiKeys(accountIndex: number): Promise<ApiKey[]>;
52
54
  declare function fetchAccountsByL1Address(l1Address: string): Promise<LighterAccountResponse>;
53
55
  declare function fetchAccount(accountIndex: number): Promise<DetailedAccountResponse>;
54
56
  declare function fetchOrderBookDetails(): Promise<OrderBookDetail[]>;
57
+ declare function fetchTradesSince(accountIndex: number, authToken: string, since: Date): Promise<LighterRawTrade[]>;
55
58
 
56
- export { type ApiKey, type ApprovedIntegrator, type DetailedAccountResponse, type LighterAccountResponse, type LighterSubAccount, type OrderBookDetail, type RestPosition, fetchAccount, fetchAccountsByL1Address, fetchApiKeys, fetchOrderBookDetails };
59
+ export { type ApiKey, type ApprovedIntegrator, type DetailedAccountResponse, type LighterAccountResponse, type LighterSubAccount, type OrderBookDetail, type RestPosition, fetchAccount, fetchAccountsByL1Address, fetchApiKeys, fetchOrderBookDetails, fetchTradesSince };
@@ -23,5 +23,40 @@ async function fetchOrderBookDetails() {
23
23
  const data = await res.json();
24
24
  return data.order_book_details;
25
25
  }
26
+ async function fetchTradesSince(accountIndex, authToken, since) {
27
+ const results = [];
28
+ let cursor;
29
+ do {
30
+ const params = new URLSearchParams({
31
+ market_type: "all",
32
+ account_index: accountIndex.toString(),
33
+ sort_by: "timestamp",
34
+ sort_dir: "desc",
35
+ ask_filter: "-1",
36
+ role: "all",
37
+ type: "all",
38
+ limit: "100",
39
+ aggregate: "false",
40
+ ...cursor ? { cursor } : {}
41
+ });
42
+ const res = await fetch(`${LIGHTER_BASE_URL}/api/v1/trades?${params.toString()}`, {
43
+ headers: { authorization: authToken }
44
+ });
45
+ if (!res.ok) throw new Error(`Lighter /trades returned ${res.status}`);
46
+ const data = await res.json();
47
+ if (data.code !== 200) {
48
+ throw new Error(`Lighter /trades returned ${data.code}: ${data.message ?? "unknown error"}`);
49
+ }
50
+ const page = data.trades ?? [];
51
+ results.push(...page.filter((trade) => trade.timestamp >= since.getTime()));
52
+ const reachedSince = page.some((trade) => trade.timestamp < since.getTime());
53
+ cursor = reachedSince ? void 0 : data.next_cursor || void 0;
54
+ } while (cursor);
55
+ const byId = /* @__PURE__ */ new Map();
56
+ for (const trade of results) {
57
+ byId.set(trade.trade_id_str ?? trade.trade_id.toString(), trade);
58
+ }
59
+ return Array.from(byId.values());
60
+ }
26
61
 
27
- export { fetchAccount, fetchAccountsByL1Address, fetchApiKeys, fetchOrderBookDetails };
62
+ export { fetchAccount, fetchAccountsByL1Address, fetchApiKeys, fetchOrderBookDetails, fetchTradesSince };
@@ -28,5 +28,26 @@ type UserStatsEvent = {
28
28
  margin_usage: string;
29
29
  };
30
30
  };
31
+ type LighterRawTrade = {
32
+ trade_id: number;
33
+ trade_id_str?: string;
34
+ type: 'trade' | 'liquidation' | 'deleverage' | 'market-settlement' | string;
35
+ market_id: number;
36
+ size: string;
37
+ price: string;
38
+ usd_amount: string;
39
+ ask_client_id_str?: string;
40
+ bid_client_id_str?: string;
41
+ ask_account_id: number;
42
+ bid_account_id: number;
43
+ is_maker_ask: boolean;
44
+ timestamp: number;
45
+ taker_fee?: number;
46
+ taker_position_size_before?: string;
47
+ maker_fee?: number;
48
+ maker_position_size_before?: string;
49
+ integrator_taker_fee?: number;
50
+ integrator_maker_fee?: number;
51
+ };
31
52
 
32
- export type { AccountAllEvent, RawAsset, RawPosition, UserStatsEvent };
53
+ export type { AccountAllEvent, LighterRawTrade, RawAsset, RawPosition, UserStatsEvent };
@@ -1,9 +1,10 @@
1
1
  import { OkxCredentialsDTO } from '@pear-protocol/types';
2
- import { OkxRawAccountConfig, OkxRawBalance, OkxRawLeverageInfo, OkxRawPosition } from './types.js';
2
+ import { OkxRawAccountConfig, OkxRawBalance, OkxRawFill, OkxRawLeverageInfo, OkxRawPosition } from './types.js';
3
3
 
4
4
  declare function fetchAccountConfig(creds: OkxCredentialsDTO, demo: boolean): Promise<OkxRawAccountConfig>;
5
5
  declare function fetchBalance(creds: OkxCredentialsDTO, demo: boolean): Promise<OkxRawBalance>;
6
6
  declare function fetchPositions(creds: OkxCredentialsDTO, demo: boolean): Promise<OkxRawPosition[]>;
7
7
  declare function fetchLeverageInfo(creds: OkxCredentialsDTO, instId: string, demo: boolean): Promise<OkxRawLeverageInfo | undefined>;
8
+ declare function fetchFillsHistorySince(creds: OkxCredentialsDTO, since: Date, demo: boolean): Promise<OkxRawFill[]>;
8
9
 
9
- export { fetchAccountConfig, fetchBalance, fetchLeverageInfo, fetchPositions };
10
+ export { fetchAccountConfig, fetchBalance, fetchFillsHistorySince, fetchLeverageInfo, fetchPositions };
@@ -53,5 +53,32 @@ async function fetchLeverageInfo(creds, instId, demo) {
53
53
  ).catch(() => []);
54
54
  return result[0];
55
55
  }
56
+ const FILLS_HISTORY_LIMIT = 100;
57
+ async function fetchFillsHistorySince(creds, since, demo) {
58
+ const results = [];
59
+ let after;
60
+ do {
61
+ const page = await signedGet(
62
+ creds,
63
+ "/api/v5/trade/fills-history",
64
+ {
65
+ instType: "SWAP",
66
+ begin: since.getTime().toString(),
67
+ end: Date.now().toString(),
68
+ limit: FILLS_HISTORY_LIMIT.toString(),
69
+ ...after ? { after } : {}
70
+ },
71
+ demo
72
+ );
73
+ results.push(...page);
74
+ const last = page[page.length - 1];
75
+ after = page.length === FILLS_HISTORY_LIMIT && last?.billId ? last.billId : void 0;
76
+ } while (after);
77
+ const byId = /* @__PURE__ */ new Map();
78
+ for (const fill of results) {
79
+ byId.set(fill.billId || fill.tradeId, fill);
80
+ }
81
+ return Array.from(byId.values());
82
+ }
56
83
 
57
- export { fetchAccountConfig, fetchBalance, fetchLeverageInfo, fetchPositions };
84
+ export { fetchAccountConfig, fetchBalance, fetchFillsHistorySince, fetchLeverageInfo, fetchPositions };
@@ -42,6 +42,23 @@ interface OkxRawLeverageInfo {
42
42
  lever: string;
43
43
  mgnMode: string;
44
44
  }
45
+ interface OkxRawFill {
46
+ instType: string;
47
+ instId: string;
48
+ tradeId: string;
49
+ ordId: string;
50
+ clOrdId: string;
51
+ billId: string;
52
+ fillPx: string;
53
+ fillSz: string;
54
+ side: 'buy' | 'sell';
55
+ posSide: string;
56
+ execType: string;
57
+ fee: string;
58
+ feeCcy: string;
59
+ fillTime: string;
60
+ ts: string;
61
+ }
45
62
  interface OkxWsAccountMessage {
46
63
  arg: {
47
64
  channel: 'account';
@@ -57,4 +74,4 @@ interface OkxWsPositionsMessage {
57
74
  }
58
75
  type OkxWsMessage = OkxWsAccountMessage | OkxWsPositionsMessage;
59
76
 
60
- export type { OkxRawAccountConfig, OkxRawBalance, OkxRawBalanceDetail, OkxRawLeverageInfo, OkxRawPosition, OkxWsAccountMessage, OkxWsMessage, OkxWsPositionsMessage };
77
+ export type { OkxRawAccountConfig, OkxRawBalance, OkxRawBalanceDetail, OkxRawFill, OkxRawLeverageInfo, OkxRawPosition, OkxWsAccountMessage, OkxWsMessage, OkxWsPositionsMessage };
@@ -4,6 +4,7 @@ import './lighter/types.js';
4
4
  import './lighter/ethereum/types.js';
5
5
  import 'viem';
6
6
  import '../client/lighter/rest.js';
7
+ import '../client/lighter/types.js';
7
8
 
8
9
  declare function createExchangeHelper<E extends ExchangeHelperExchange>(exchange: E, sdk: PearSDK): ExchangeHelperMap[E];
9
10
 
@@ -1,7 +1,8 @@
1
- export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './lighter/types.js';
2
1
  export { createLighterHelper } from './lighter/helper.js';
2
+ export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './lighter/types.js';
3
3
  export { ExchangeHelperExchange, ExchangeHelperMap } from './types.js';
4
4
  export { ApiKey } from '../client/lighter/rest.js';
5
5
  export { WalletClientWithAccount } from './lighter/ethereum/types.js';
6
6
  import '@pear-protocol/core-sdk';
7
+ import '../client/lighter/types.js';
7
8
  import 'viem';
@@ -1,8 +1,9 @@
1
- import { LighterHelper } from './types.js';
2
1
  import PearSDK from '@pear-protocol/core-sdk';
2
+ import { LighterHelper } from './types.js';
3
3
  import '../../client/lighter/rest.js';
4
4
  import './ethereum/types.js';
5
5
  import 'viem';
6
+ import '../../client/lighter/types.js';
6
7
 
7
8
  declare function createLighterHelper(sdk: PearSDK): LighterHelper;
8
9
 
@@ -1,6 +1,7 @@
1
- export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './types.js';
2
1
  export { createLighterHelper } from './helper.js';
2
+ export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './types.js';
3
3
  export { ApiKey } from '../../client/lighter/rest.js';
4
4
  export { WalletClientWithAccount } from './ethereum/types.js';
5
- import 'viem';
6
5
  import '@pear-protocol/core-sdk';
6
+ import 'viem';
7
+ import '../../client/lighter/types.js';
@@ -1,2 +1,2 @@
1
- export * from './types';
2
1
  export * from './helper';
2
+ export * from './types';
@@ -1,6 +1,7 @@
1
1
  import { WalletClientWithAccount } from './ethereum/types.js';
2
2
  export { ApiKey } from '../../client/lighter/rest.js';
3
3
  import 'viem';
4
+ import '../../client/lighter/types.js';
4
5
 
5
6
  declare const AssetId: {
6
7
  readonly ETH: 1;
@@ -2,6 +2,7 @@ import { LighterHelper } from './lighter/types.js';
2
2
  import './lighter/ethereum/types.js';
3
3
  import 'viem';
4
4
  import '../client/lighter/rest.js';
5
+ import '../client/lighter/types.js';
5
6
 
6
7
  type ExchangeHelperMap = {
7
8
  lighter: LighterHelper;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  export { CreateExchangeWsConfig, ExchangeWsByConnector, createExchangeWs } from './client/index.js';
2
- export { ASSET_DECIMALS, ApproveIntegratorParams, ApproveIntegratorResult, AssetId, ConnectWalletParams, ConnectWalletResult, DepositParams, LighterHelper, LighterLookupResult, RouteType, WithdrawParams, getAssetDecimals } from './helper/lighter/types.js';
3
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
4
  export { ExchangeHelperExchange, ExchangeHelperMap } from './helper/types.js';
5
5
  export { ExchangesSDK } from './sdk.js';
6
- export { AccountPositionSyncer, AccountPositionSyncerConfig } from './syncer/base.js';
6
+ export { AccountSyncer, AccountSyncerConfig, BaseAccountSyncer, ListExternalFillsParams } 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';
7
13
  export { CreateAccountTrackerConfig, createAccountTracker } from './tracker/index.js';
8
14
  export { ExchangeConnection, ExchangesSDKConfig, HyperliquidAccountCredentials, LighterAccountCredentials, SupportedCredentials } from './types.js';
9
15
  export { ACCOUNT_TYPE_LABELS, AccountBalance, AccountPosition, AccountType, AssetBalance, BalanceCallback, ExchangeState, MarginMode, PositionsCallback, StateUpdate, TrackedAssetCallback, TrackedAssetInfo } from './tracker/types.js';
@@ -34,5 +40,10 @@ export { OkxWs, OkxWsConfig } from './client/okx/ws.js';
34
40
  export { WalletClientWithAccount } from './helper/lighter/ethereum/types.js';
35
41
  import '@pear-protocol/types';
36
42
  import '@pear-protocol/core-sdk';
43
+ import './client/binance/types.js';
44
+ import './client/bybit/types.js';
45
+ import './client/hyperliquid/types.js';
46
+ import './client/lighter/types.js';
47
+ import './client/okx/types.js';
37
48
  import 'partysocket';
38
49
  import 'viem';
package/dist/sdk.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { Connector } from '@pear-protocol/types';
2
2
  import { ExchangeHelperExchange, ExchangeHelperMap } from './helper/types.js';
3
- import { AccountPositionSyncer } from './syncer/base.js';
3
+ import { AccountSyncer } from './syncer/base.js';
4
4
  import { ExchangesSDKConfig, ExchangeConnection } from './types.js';
5
5
  import { AccountTracker } from './tracker/base.js';
6
6
  import './helper/lighter/types.js';
7
7
  import './helper/lighter/ethereum/types.js';
8
8
  import 'viem';
9
9
  import './client/lighter/rest.js';
10
+ import './client/lighter/types.js';
10
11
  import '@pear-protocol/core-sdk';
11
12
  import './client/index.js';
12
13
  import './client/binance/exchange-ws.js';
@@ -36,7 +37,7 @@ declare class ExchangesSDK {
36
37
  connect(tradeAccountId: string, exchange: Connector): Promise<ExchangeConnection>;
37
38
  createTracker(connection: ExchangeConnection): AccountTracker;
38
39
  createHelper<E extends ExchangeHelperExchange>(exchange: E): ExchangeHelperMap[E];
39
- createPositionSyncer(connection: ExchangeConnection): AccountPositionSyncer;
40
+ createSyncer(connection: ExchangeConnection): AccountSyncer;
40
41
  private fetchCredentials;
41
42
  }
42
43
 
package/dist/sdk.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createExchangeWs } from './client';
2
2
  import './helper';
3
3
  import { createExchangeHelper } from './helper/factory';
4
- import { AccountPositionSyncer } from './syncer';
4
+ import { createAccountSyncer } from './syncer';
5
5
  import { createAccountTracker } from './tracker';
6
6
 
7
7
  class ExchangesSDK {
@@ -26,9 +26,10 @@ class ExchangesSDK {
26
26
  createHelper(exchange) {
27
27
  return createExchangeHelper(exchange, this.sdk);
28
28
  }
29
- createPositionSyncer(connection) {
30
- return new AccountPositionSyncer({
29
+ createSyncer(connection) {
30
+ return createAccountSyncer(connection.exchange, {
31
31
  sdk: this.sdk,
32
+ connector: connection.exchange,
32
33
  credentials: connection.credentials,
33
34
  ws: connection.ws,
34
35
  demo: this.demo