@pear-protocol/exchanges-sdk 0.1.1 → 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.
- package/dist/client/hyperliquid/types.d.ts +76 -1
- package/dist/helper/index.d.ts +1 -1
- package/dist/helper/lighter/helper.d.ts +1 -1
- package/dist/helper/lighter/index.d.ts +2 -2
- package/dist/helper/lighter/index.js +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/sdk.d.ts +2 -2
- package/dist/sdk.js +4 -3
- package/dist/syncer/base.d.ts +13 -6
- package/dist/syncer/base.js +38 -2
- package/dist/syncer/binance/syncer.d.ts +24 -0
- package/dist/syncer/binance/syncer.js +9 -0
- package/dist/syncer/bybit/syncer.d.ts +24 -0
- package/dist/syncer/bybit/syncer.js +9 -0
- package/dist/syncer/factory.d.ts +22 -0
- package/dist/syncer/factory.js +26 -0
- package/dist/syncer/hyperliquid/syncer.d.ts +26 -0
- package/dist/syncer/hyperliquid/syncer.js +43 -0
- package/dist/syncer/index.d.ts +7 -1
- package/dist/syncer/index.js +6 -0
- package/dist/syncer/lighter/syncer.d.ts +24 -0
- package/dist/syncer/lighter/syncer.js +9 -0
- package/dist/syncer/okx/syncer.d.ts +24 -0
- package/dist/syncer/okx/syncer.js +9 -0
- package/package.json +7 -9
|
@@ -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 };
|
package/dist/helper/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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';
|
|
@@ -1,6 +1,6 @@
|
|
|
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';
|
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 {
|
|
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';
|
|
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';
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connector } from '@pear-protocol/types';
|
|
2
2
|
import { ExchangeHelperExchange, ExchangeHelperMap } from './helper/types.js';
|
|
3
|
-
import {
|
|
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';
|
|
@@ -36,7 +36,7 @@ declare class ExchangesSDK {
|
|
|
36
36
|
connect(tradeAccountId: string, exchange: Connector): Promise<ExchangeConnection>;
|
|
37
37
|
createTracker(connection: ExchangeConnection): AccountTracker;
|
|
38
38
|
createHelper<E extends ExchangeHelperExchange>(exchange: E): ExchangeHelperMap[E];
|
|
39
|
-
|
|
39
|
+
createSyncer(connection: ExchangeConnection): AccountSyncer;
|
|
40
40
|
private fetchCredentials;
|
|
41
41
|
}
|
|
42
42
|
|
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 {
|
|
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
|
-
|
|
30
|
-
return
|
|
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
|
package/dist/syncer/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import PearSDK from '@pear-protocol/core-sdk';
|
|
2
|
-
import { Connector } from '@pear-protocol/types';
|
|
2
|
+
import { Connector, InstrumentId, HttpTypes } from '@pear-protocol/types';
|
|
3
3
|
import { ExchangeWsByConnector } from '../client/index.js';
|
|
4
4
|
import { SupportedCredentials } from '../types.js';
|
|
5
5
|
import '../client/binance/exchange-ws.js';
|
|
@@ -16,18 +16,25 @@ import '../client/lighter/ws.js';
|
|
|
16
16
|
import '../client/okx/exchange-ws.js';
|
|
17
17
|
import '../client/okx/ws.js';
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
interface AccountSyncerConfig {
|
|
20
20
|
sdk: PearSDK;
|
|
21
|
+
connector: Connector;
|
|
21
22
|
credentials: SupportedCredentials;
|
|
22
23
|
ws: ExchangeWsByConnector[Connector];
|
|
23
24
|
demo: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
25
|
+
}
|
|
26
|
+
interface AccountSyncer {
|
|
27
|
+
synchronize(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
declare abstract class BaseAccountSyncer implements AccountSyncer {
|
|
26
30
|
protected sdk: PearSDK;
|
|
31
|
+
protected connector: Connector;
|
|
27
32
|
protected credentials: SupportedCredentials;
|
|
28
33
|
protected ws: ExchangeWsByConnector[Connector];
|
|
29
34
|
protected demo: boolean;
|
|
30
|
-
constructor(config:
|
|
35
|
+
constructor(config: AccountSyncerConfig);
|
|
36
|
+
protected abstract listExternalFills(since: Date, instrumentSymbolToIdMap: Record<string, InstrumentId>): Promise<HttpTypes.UnknownExternalFill[]>;
|
|
37
|
+
synchronize(): Promise<void>;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
export {
|
|
40
|
+
export { type AccountSyncer, type AccountSyncerConfig, BaseAccountSyncer };
|
package/dist/syncer/base.js
CHANGED
|
@@ -1,14 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import { computeSyncPayload } from '@pear-protocol/utils';
|
|
2
|
+
|
|
3
|
+
class BaseAccountSyncer {
|
|
2
4
|
sdk;
|
|
5
|
+
connector;
|
|
3
6
|
credentials;
|
|
4
7
|
ws;
|
|
5
8
|
demo;
|
|
6
9
|
constructor(config) {
|
|
7
10
|
this.sdk = config.sdk;
|
|
11
|
+
this.connector = config.connector;
|
|
8
12
|
this.credentials = config.credentials;
|
|
9
13
|
this.ws = config.ws;
|
|
10
14
|
this.demo = config.demo;
|
|
11
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
|
+
}
|
|
12
48
|
}
|
|
13
49
|
|
|
14
|
-
export {
|
|
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,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,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 };
|
package/dist/syncer/index.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export {
|
|
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';
|
|
2
8
|
import '@pear-protocol/core-sdk';
|
|
3
9
|
import '@pear-protocol/types';
|
|
4
10
|
import '../client/index.js';
|
package/dist/syncer/index.js
CHANGED
|
@@ -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,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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/exchanges-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pear Protocol Exchanges SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -25,14 +25,12 @@
|
|
|
25
25
|
"typecheck": "tsc --noEmit"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pear-protocol/core-sdk": "0.0.
|
|
29
|
-
"@pear-protocol/types": "0.0.
|
|
30
|
-
"@pear-protocol/utils": "0.0.
|
|
31
|
-
"bignumber.js": "
|
|
32
|
-
"partysocket": "^1.0.3"
|
|
33
|
-
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"viem": "^2.38.0"
|
|
28
|
+
"@pear-protocol/core-sdk": "^0.0.20",
|
|
29
|
+
"@pear-protocol/types": "^0.0.17",
|
|
30
|
+
"@pear-protocol/utils": "^0.0.17",
|
|
31
|
+
"bignumber.js": "^11.1.1",
|
|
32
|
+
"partysocket": "^1.0.3",
|
|
33
|
+
"viem": "^2.48.8"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@backend/typescript-config": "workspace:*",
|