@pear-protocol/exchanges-sdk 0.1.6 → 0.1.8
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/README.md +63 -2
- package/dist/client/lighter/rest.js +18 -1
- package/dist/helper/factory.js +6 -5
- package/dist/helper/hyperliquid/helper.js +23 -0
- package/dist/helper/hyperliquid/index.js +1 -0
- package/dist/helper/hyperliquid/types.js +1 -0
- package/dist/helper/index.js +1 -0
- package/dist/index.d.ts +817 -49
- package/dist/sdk.js +33 -20
- package/dist/status/base.js +10 -0
- package/dist/status/binance/status.js +14 -0
- package/dist/status/bybit/status.js +14 -0
- package/dist/status/factory.js +26 -0
- package/dist/status/hyperliquid/status.js +37 -0
- package/dist/status/index.js +7 -0
- package/dist/status/lighter/status.js +33 -0
- package/dist/status/okx/status.js +14 -0
- package/dist/syncer/base.js +2 -0
- package/dist/syncer/hyperliquid/syncer.js +1 -2
- package/dist/syncer/lighter/syncer.js +1 -1
- package/dist/tracker/hyperliquid/tracker.js +1 -2
- package/dist/tracker/index.js +2 -0
- package/dist/tracker/lighter/tracker.js +1 -2
- package/package.json +4 -4
- package/dist/client/base-ws.d.ts +0 -30
- package/dist/client/binance/exchange-ws.d.ts +0 -19
- package/dist/client/binance/rest.d.ts +0 -13
- package/dist/client/binance/types.d.ts +0 -103
- package/dist/client/binance/ws.d.ts +0 -30
- package/dist/client/bybit/exchange-ws.d.ts +0 -20
- package/dist/client/bybit/rest.d.ts +0 -11
- package/dist/client/bybit/types.d.ts +0 -75
- package/dist/client/bybit/ws.d.ts +0 -17
- package/dist/client/exchange-ws.d.ts +0 -12
- package/dist/client/hmac.d.ts +0 -4
- package/dist/client/hyperliquid/exchange-ws.d.ts +0 -15
- package/dist/client/hyperliquid/rest.d.ts +0 -3
- package/dist/client/hyperliquid/types.d.ts +0 -188
- package/dist/client/hyperliquid/ws.d.ts +0 -10
- package/dist/client/index.d.ts +0 -31
- package/dist/client/lighter/constants.d.ts +0 -4
- package/dist/client/lighter/exchange-ws.d.ts +0 -15
- package/dist/client/lighter/rest.d.ts +0 -59
- package/dist/client/lighter/types.d.ts +0 -53
- package/dist/client/lighter/ws.d.ts +0 -10
- package/dist/client/okx/exchange-ws.d.ts +0 -20
- package/dist/client/okx/rest.d.ts +0 -10
- package/dist/client/okx/types.d.ts +0 -77
- package/dist/client/okx/ws.d.ts +0 -17
- package/dist/helper/factory.d.ts +0 -11
- package/dist/helper/index.d.ts +0 -8
- package/dist/helper/lighter/ethereum/abi.d.ts +0 -66
- package/dist/helper/lighter/ethereum/index.d.ts +0 -8
- package/dist/helper/lighter/ethereum/types.d.ts +0 -23
- package/dist/helper/lighter/helper.d.ts +0 -10
- package/dist/helper/lighter/index.d.ts +0 -7
- package/dist/helper/lighter/types.d.ts +0 -64
- package/dist/helper/types.d.ts +0 -12
- package/dist/sdk.d.ts +0 -44
- package/dist/syncer/base.d.ts +0 -47
- package/dist/syncer/binance/syncer.d.ts +0 -31
- package/dist/syncer/bybit/syncer.d.ts +0 -28
- package/dist/syncer/factory.d.ts +0 -22
- package/dist/syncer/hyperliquid/syncer.d.ts +0 -28
- package/dist/syncer/index.d.ts +0 -29
- package/dist/syncer/lighter/syncer.d.ts +0 -37
- package/dist/syncer/okx/syncer.d.ts +0 -29
- package/dist/tracker/base.d.ts +0 -79
- package/dist/tracker/binance/const.d.ts +0 -4
- package/dist/tracker/binance/mapper.d.ts +0 -14
- package/dist/tracker/binance/tracker.d.ts +0 -60
- package/dist/tracker/binance/types.d.ts +0 -6
- package/dist/tracker/bybit/mapper.d.ts +0 -15
- package/dist/tracker/bybit/tracker.d.ts +0 -51
- package/dist/tracker/bybit/types.d.ts +0 -7
- package/dist/tracker/hyperliquid/const.d.ts +0 -3
- package/dist/tracker/hyperliquid/mapper.d.ts +0 -12
- package/dist/tracker/hyperliquid/tracker.d.ts +0 -62
- package/dist/tracker/hyperliquid/types.d.ts +0 -23
- package/dist/tracker/index.d.ts +0 -38
- package/dist/tracker/lighter/const.d.ts +0 -3
- package/dist/tracker/lighter/mapper.d.ts +0 -16
- package/dist/tracker/lighter/tracker.d.ts +0 -53
- package/dist/tracker/lighter/types.d.ts +0 -16
- package/dist/tracker/okx/mapper.d.ts +0 -16
- package/dist/tracker/okx/tracker.d.ts +0 -51
- package/dist/tracker/okx/types.d.ts +0 -8
- package/dist/tracker/types.d.ts +0 -63
- package/dist/tracker/utils.d.ts +0 -11
- package/dist/types.d.ts +0 -50
package/dist/sdk.js
CHANGED
|
@@ -1,52 +1,65 @@
|
|
|
1
1
|
import { createExchangeWs } from './client';
|
|
2
2
|
import './helper';
|
|
3
3
|
import { createExchangeHelper } from './helper/factory';
|
|
4
|
+
import { checkAccountStatus } from './status';
|
|
4
5
|
import { createAccountSyncer } from './syncer';
|
|
5
6
|
import { createAccountTracker } from './tracker';
|
|
6
7
|
|
|
7
8
|
class ExchangesSDK {
|
|
8
9
|
sdk;
|
|
9
10
|
demo;
|
|
11
|
+
options;
|
|
10
12
|
constructor(config) {
|
|
11
13
|
this.sdk = config.sdk;
|
|
12
14
|
this.demo = config.demo ?? false;
|
|
15
|
+
this.options = config.options;
|
|
13
16
|
}
|
|
14
|
-
async connect(tradeAccountId
|
|
15
|
-
const
|
|
16
|
-
const ws = await createExchangeWs(
|
|
17
|
-
|
|
17
|
+
async connect(tradeAccountId) {
|
|
18
|
+
const connection = await this.fetchCredentials(tradeAccountId);
|
|
19
|
+
const ws = await createExchangeWs(connection.connector, {
|
|
20
|
+
demo: this.demo,
|
|
21
|
+
credentials: connection.credentials
|
|
22
|
+
});
|
|
23
|
+
return { ...connection, ws };
|
|
24
|
+
}
|
|
25
|
+
async status(connection) {
|
|
26
|
+
return checkAccountStatus(connection.connector, {
|
|
27
|
+
sdk: this.sdk,
|
|
28
|
+
connector: connection.connector,
|
|
29
|
+
account: connection.account,
|
|
30
|
+
credentials: connection.credentials,
|
|
31
|
+
statusOptions: this.options,
|
|
32
|
+
demo: this.demo
|
|
33
|
+
});
|
|
18
34
|
}
|
|
19
35
|
createTracker(connection) {
|
|
20
|
-
return createAccountTracker(connection.
|
|
36
|
+
return createAccountTracker(connection.connector, {
|
|
21
37
|
demo: this.demo,
|
|
38
|
+
account: connection.account,
|
|
22
39
|
credentials: connection.credentials,
|
|
23
40
|
ws: connection.ws
|
|
24
41
|
});
|
|
25
42
|
}
|
|
26
43
|
createHelper(exchange) {
|
|
27
|
-
|
|
44
|
+
switch (exchange) {
|
|
45
|
+
case "hyperliquid":
|
|
46
|
+
return createExchangeHelper({ exchange: "hyperliquid" });
|
|
47
|
+
case "lighter":
|
|
48
|
+
return createExchangeHelper({ exchange: "lighter", sdk: this.sdk });
|
|
49
|
+
}
|
|
28
50
|
}
|
|
29
51
|
createSyncer(connection) {
|
|
30
|
-
return createAccountSyncer(connection.
|
|
52
|
+
return createAccountSyncer(connection.connector, {
|
|
31
53
|
sdk: this.sdk,
|
|
32
|
-
connector: connection.
|
|
54
|
+
connector: connection.connector,
|
|
55
|
+
account: connection.account,
|
|
33
56
|
credentials: connection.credentials,
|
|
34
57
|
ws: connection.ws,
|
|
35
58
|
demo: this.demo
|
|
36
59
|
});
|
|
37
60
|
}
|
|
38
|
-
async fetchCredentials(tradeAccountId
|
|
39
|
-
|
|
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;
|
|
61
|
+
async fetchCredentials(tradeAccountId) {
|
|
62
|
+
return await this.sdk.core.accounts.credentials(tradeAccountId);
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const ACTIVE_STATUS = { status: "active", reasons: [] };
|
|
2
|
+
function activeStatus() {
|
|
3
|
+
return { ...ACTIVE_STATUS, reasons: [] };
|
|
4
|
+
}
|
|
5
|
+
function warningStatus(reasons) {
|
|
6
|
+
if (reasons.length === 0) return activeStatus();
|
|
7
|
+
return { status: "warning", reasons };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { activeStatus, warningStatus };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fetchAccountStatus } from '../../client/binance/rest';
|
|
2
|
+
import { warningStatus } from '../base';
|
|
3
|
+
|
|
4
|
+
async function checkBinanceAccountStatus(config) {
|
|
5
|
+
const reasons = [];
|
|
6
|
+
try {
|
|
7
|
+
await fetchAccountStatus(config.credentials, config.demo);
|
|
8
|
+
} catch {
|
|
9
|
+
reasons.push("api_key_invalid");
|
|
10
|
+
}
|
|
11
|
+
return warningStatus(reasons);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { checkBinanceAccountStatus };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fetchAccountInfo } from '../../client/bybit/rest';
|
|
2
|
+
import { warningStatus } from '../base';
|
|
3
|
+
|
|
4
|
+
async function checkBybitAccountStatus(config) {
|
|
5
|
+
const reasons = [];
|
|
6
|
+
try {
|
|
7
|
+
await fetchAccountInfo(config.credentials, config.demo);
|
|
8
|
+
} catch {
|
|
9
|
+
reasons.push("api_key_invalid");
|
|
10
|
+
}
|
|
11
|
+
return warningStatus(reasons);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { checkBybitAccountStatus };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { checkBinanceAccountStatus } from './binance/status';
|
|
2
|
+
import { checkBybitAccountStatus } from './bybit/status';
|
|
3
|
+
import { checkHyperliquidAccountStatus } from './hyperliquid/status';
|
|
4
|
+
import { checkLighterAccountStatus } from './lighter/status';
|
|
5
|
+
import { checkOkxAccountStatus } from './okx/status';
|
|
6
|
+
|
|
7
|
+
function checkAccountStatus(exchange, config) {
|
|
8
|
+
switch (exchange) {
|
|
9
|
+
case "binance":
|
|
10
|
+
return checkBinanceAccountStatus(config);
|
|
11
|
+
case "bybit":
|
|
12
|
+
return checkBybitAccountStatus(config);
|
|
13
|
+
case "okx":
|
|
14
|
+
return checkOkxAccountStatus(config);
|
|
15
|
+
case "hyperliquid":
|
|
16
|
+
return checkHyperliquidAccountStatus(config);
|
|
17
|
+
case "lighter":
|
|
18
|
+
return checkLighterAccountStatus(config);
|
|
19
|
+
default: {
|
|
20
|
+
const _exhaustive = exchange;
|
|
21
|
+
throw new Error(`Unsupported exchange: ${String(_exhaustive)}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { checkAccountStatus };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createExchangeHelper } from '../../helper/factory';
|
|
2
|
+
import { warningStatus } from '../base';
|
|
3
|
+
|
|
4
|
+
async function checkHyperliquidAccountStatus(config) {
|
|
5
|
+
const reasons = [];
|
|
6
|
+
const options = config.statusOptions;
|
|
7
|
+
if (!options?.builderAddress) {
|
|
8
|
+
throw new Error("Missing required hyperliquid connect options");
|
|
9
|
+
}
|
|
10
|
+
const helper = createExchangeHelper({ exchange: "hyperliquid" });
|
|
11
|
+
const metadata = config.account.metadata;
|
|
12
|
+
if (!metadata || !("agentWalletAddress" in metadata)) {
|
|
13
|
+
reasons.push("hyperliquid_api_wallet_invalid");
|
|
14
|
+
} else {
|
|
15
|
+
try {
|
|
16
|
+
const apiWalletValid = await helper.checkApiWallet({
|
|
17
|
+
userAddress: config.account.exchangeIdentifier,
|
|
18
|
+
agentWalletAddress: metadata.agentWalletAddress
|
|
19
|
+
});
|
|
20
|
+
if (!apiWalletValid) reasons.push("hyperliquid_api_wallet_invalid");
|
|
21
|
+
} catch {
|
|
22
|
+
reasons.push("hyperliquid_api_wallet_invalid");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const approved = await helper.checkBuilderFeeApproval(
|
|
27
|
+
config.account.exchangeIdentifier,
|
|
28
|
+
options.builderAddress
|
|
29
|
+
);
|
|
30
|
+
if (!approved) reasons.push("hyperliquid_builder_fee_not_approved");
|
|
31
|
+
} catch {
|
|
32
|
+
reasons.push("hyperliquid_builder_fee_not_approved");
|
|
33
|
+
}
|
|
34
|
+
return warningStatus(reasons);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { checkHyperliquidAccountStatus };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { fetchAccountMetadata } from '../../client/lighter/rest';
|
|
2
|
+
import { createExchangeHelper } from '../../helper/factory';
|
|
3
|
+
import { warningStatus } from '../base';
|
|
4
|
+
|
|
5
|
+
async function checkLighterAccountStatus(config) {
|
|
6
|
+
const reasons = [];
|
|
7
|
+
const options = config.statusOptions;
|
|
8
|
+
if (options?.integratorAccountIndex === void 0) {
|
|
9
|
+
throw new Error("Missing required lighter connect options");
|
|
10
|
+
}
|
|
11
|
+
const credentials = config.credentials;
|
|
12
|
+
const accountIndex = Number(config.account.exchangeIdentifier);
|
|
13
|
+
try {
|
|
14
|
+
const { token } = await config.sdk.core.misc.lighter.createAuthToken({
|
|
15
|
+
accountIndex,
|
|
16
|
+
apiKeyIndex: credentials.api_key_index,
|
|
17
|
+
apiPrivateKey: credentials.api_private_key
|
|
18
|
+
});
|
|
19
|
+
await fetchAccountMetadata(accountIndex, token);
|
|
20
|
+
} catch {
|
|
21
|
+
reasons.push("lighter_api_key_invalid");
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const helper = createExchangeHelper({ exchange: "lighter", sdk: config.sdk });
|
|
25
|
+
const approved = await helper.checkIntegratorApproval(accountIndex, options.integratorAccountIndex);
|
|
26
|
+
if (!approved) reasons.push("lighter_integrator_not_approved");
|
|
27
|
+
} catch {
|
|
28
|
+
reasons.push("lighter_integrator_not_approved");
|
|
29
|
+
}
|
|
30
|
+
return warningStatus(reasons);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { checkLighterAccountStatus };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fetchAccountConfig } from '../../client/okx/rest';
|
|
2
|
+
import { warningStatus } from '../base';
|
|
3
|
+
|
|
4
|
+
async function checkOkxAccountStatus(config) {
|
|
5
|
+
const reasons = [];
|
|
6
|
+
try {
|
|
7
|
+
await fetchAccountConfig(config.credentials, config.demo);
|
|
8
|
+
} catch {
|
|
9
|
+
reasons.push("api_key_invalid");
|
|
10
|
+
}
|
|
11
|
+
return warningStatus(reasons);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { checkOkxAccountStatus };
|
package/dist/syncer/base.js
CHANGED
|
@@ -3,12 +3,14 @@ import { computeSyncPayload } from '@pear-protocol/utils';
|
|
|
3
3
|
class BaseAccountSyncer {
|
|
4
4
|
sdk;
|
|
5
5
|
connector;
|
|
6
|
+
account;
|
|
6
7
|
credentials;
|
|
7
8
|
ws;
|
|
8
9
|
demo;
|
|
9
10
|
constructor(config) {
|
|
10
11
|
this.sdk = config.sdk;
|
|
11
12
|
this.connector = config.connector;
|
|
13
|
+
this.account = config.account;
|
|
12
14
|
this.credentials = config.credentials;
|
|
13
15
|
this.ws = config.ws;
|
|
14
16
|
this.demo = config.demo;
|
|
@@ -5,8 +5,7 @@ class HyperliquidAccountSyncer extends BaseAccountSyncer {
|
|
|
5
5
|
address;
|
|
6
6
|
constructor(config) {
|
|
7
7
|
super(config);
|
|
8
|
-
|
|
9
|
-
this.address = creds.accountIdentifier;
|
|
8
|
+
this.address = config.account.exchangeIdentifier;
|
|
10
9
|
}
|
|
11
10
|
async listExternalFills({
|
|
12
11
|
since,
|
|
@@ -10,7 +10,7 @@ class LighterAccountSyncer extends BaseAccountSyncer {
|
|
|
10
10
|
constructor(config) {
|
|
11
11
|
super(config);
|
|
12
12
|
const creds = config.credentials;
|
|
13
|
-
this.accountIndex = Number(
|
|
13
|
+
this.accountIndex = Number(config.account.exchangeIdentifier);
|
|
14
14
|
this.apiKeyIndex = creds.api_key_index;
|
|
15
15
|
this.apiPrivateKey = creds.api_private_key;
|
|
16
16
|
}
|
|
@@ -26,9 +26,8 @@ class HyperliquidAccountTracker extends BaseAccountTracker {
|
|
|
26
26
|
trackedAssetData = /* @__PURE__ */ new Map();
|
|
27
27
|
constructor(config) {
|
|
28
28
|
super(config);
|
|
29
|
-
const creds = config.credentials;
|
|
30
29
|
this.credentials = config.credentials;
|
|
31
|
-
this.address =
|
|
30
|
+
this.address = config.account.exchangeIdentifier;
|
|
32
31
|
this.ws = config.ws;
|
|
33
32
|
}
|
|
34
33
|
async start() {
|
package/dist/tracker/index.js
CHANGED
|
@@ -55,6 +55,7 @@ function createAccountTracker(exchange, config) {
|
|
|
55
55
|
tracker = new HyperliquidAccountTracker({
|
|
56
56
|
demo: config.demo,
|
|
57
57
|
onError: config.onError,
|
|
58
|
+
account: config.account,
|
|
58
59
|
credentials: config.credentials,
|
|
59
60
|
ws: ws.main
|
|
60
61
|
});
|
|
@@ -65,6 +66,7 @@ function createAccountTracker(exchange, config) {
|
|
|
65
66
|
tracker = new LighterAccountTracker({
|
|
66
67
|
demo: config.demo,
|
|
67
68
|
onError: config.onError,
|
|
69
|
+
account: config.account,
|
|
68
70
|
credentials: config.credentials,
|
|
69
71
|
ws: ws.main
|
|
70
72
|
});
|
|
@@ -14,9 +14,8 @@ class LighterAccountTracker extends BaseAccountTracker {
|
|
|
14
14
|
hasAssets = false;
|
|
15
15
|
constructor(config) {
|
|
16
16
|
super(config);
|
|
17
|
-
const creds = config.credentials;
|
|
18
17
|
this.credentials = config.credentials;
|
|
19
|
-
this.accountIdentifier =
|
|
18
|
+
this.accountIdentifier = config.account.exchangeIdentifier;
|
|
20
19
|
this.ws = config.ws;
|
|
21
20
|
}
|
|
22
21
|
async start() {
|
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.8",
|
|
4
4
|
"description": "Pear Protocol Exchanges SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
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.
|
|
28
|
+
"@pear-protocol/core-sdk": "^0.0.23",
|
|
29
|
+
"@pear-protocol/types": "^0.0.20",
|
|
30
|
+
"@pear-protocol/utils": "^0.0.20",
|
|
31
31
|
"bignumber.js": "^11.1.1",
|
|
32
32
|
"partysocket": "^1.0.3",
|
|
33
33
|
"viem": "^2.48.8"
|
package/dist/client/base-ws.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'partysocket';
|
|
2
|
-
|
|
3
|
-
interface WsMessage {
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}
|
|
6
|
-
type MessageListener = (data: string) => void;
|
|
7
|
-
type OpenListener = () => void;
|
|
8
|
-
declare abstract class BaseWs {
|
|
9
|
-
protected ws: WebSocket | null;
|
|
10
|
-
protected pingTimer: ReturnType<typeof setInterval> | null;
|
|
11
|
-
private messageListeners;
|
|
12
|
-
private openListeners;
|
|
13
|
-
private nextListenerId;
|
|
14
|
-
protected abstract getWsUrl(): string;
|
|
15
|
-
protected abstract getPingIntervalMs(): number;
|
|
16
|
-
protected abstract buildPingMessage(): WsMessage | string | null;
|
|
17
|
-
connect(): Promise<void>;
|
|
18
|
-
disconnect(): void;
|
|
19
|
-
get connected(): boolean;
|
|
20
|
-
send(msg: WsMessage | string): void;
|
|
21
|
-
addMessageListener(listener: MessageListener): string;
|
|
22
|
-
removeMessageListener(id: string): void;
|
|
23
|
-
addOpenListener(listener: OpenListener): string;
|
|
24
|
-
removeOpenListener(id: string): void;
|
|
25
|
-
destroy(): void;
|
|
26
|
-
private startPing;
|
|
27
|
-
private stopPing;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { BaseWs, type MessageListener, type OpenListener, type WsMessage };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BinanceCredentialsDTO } from '@pear-protocol/types';
|
|
2
|
-
import { BaseWs } from '../base-ws.js';
|
|
3
|
-
import { ExchangeWs } from '../exchange-ws.js';
|
|
4
|
-
import { BinanceUserDataWs, BinanceWsApi } from './ws.js';
|
|
5
|
-
import 'partysocket';
|
|
6
|
-
|
|
7
|
-
declare class BinanceExchangeWs extends ExchangeWs {
|
|
8
|
-
userData: BinanceUserDataWs;
|
|
9
|
-
wsApi: BinanceWsApi;
|
|
10
|
-
readonly exchange: "binance";
|
|
11
|
-
constructor(userData: BinanceUserDataWs, wsApi: BinanceWsApi);
|
|
12
|
-
protected connections(): BaseWs[];
|
|
13
|
-
static create(config: {
|
|
14
|
-
demo: boolean;
|
|
15
|
-
credentials: BinanceCredentialsDTO;
|
|
16
|
-
}): Promise<BinanceExchangeWs>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { BinanceExchangeWs };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BinanceCredentialsDTO } from '@pear-protocol/types';
|
|
2
|
-
import { BinanceRawAccountStatus, BinanceRawOrder, BinanceRawPositionRisk, BinanceRawUserTrade } from './types.js';
|
|
3
|
-
|
|
4
|
-
declare function createListenKey(apiKey: string, demo?: boolean): Promise<string>;
|
|
5
|
-
declare function keepAliveListenKey(apiKey: string, demo?: boolean): Promise<void>;
|
|
6
|
-
declare function fetchAccountStatus(creds: BinanceCredentialsDTO, demo: boolean): Promise<BinanceRawAccountStatus>;
|
|
7
|
-
declare function fetchPositionRisk(creds: BinanceCredentialsDTO, symbol: string, demo: boolean): Promise<BinanceRawPositionRisk | undefined>;
|
|
8
|
-
declare function fetchAllPositionRisk(creds: BinanceCredentialsDTO, demo: boolean): Promise<BinanceRawPositionRisk[]>;
|
|
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[]>;
|
|
12
|
-
|
|
13
|
-
export { createListenKey, fetchAccountStatus, fetchAllOrdersSince, fetchAllPositionRisk, fetchMultiAssetsMargin, fetchPositionRisk, fetchUserTradesSince, keepAliveListenKey };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { MarginMode } from '@pear-protocol/types';
|
|
2
|
-
|
|
3
|
-
interface BinanceRawPositionRisk {
|
|
4
|
-
symbol: string;
|
|
5
|
-
leverage: string;
|
|
6
|
-
marginType: MarginMode;
|
|
7
|
-
isAutoAddMargin: string;
|
|
8
|
-
isolatedMargin: string;
|
|
9
|
-
positionAmt: string;
|
|
10
|
-
entryPrice: string;
|
|
11
|
-
breakEvenPrice: string;
|
|
12
|
-
unRealizedProfit: string;
|
|
13
|
-
liquidationPrice: string;
|
|
14
|
-
markPrice: string;
|
|
15
|
-
maxNotionalValue: string;
|
|
16
|
-
positionSide: string;
|
|
17
|
-
notional: string;
|
|
18
|
-
isolatedWallet: string;
|
|
19
|
-
updateTime: number;
|
|
20
|
-
}
|
|
21
|
-
interface BinanceRawAsset {
|
|
22
|
-
asset: string;
|
|
23
|
-
walletBalance: string;
|
|
24
|
-
availableBalance: string;
|
|
25
|
-
unrealizedProfit: string;
|
|
26
|
-
marginBalance: string;
|
|
27
|
-
initialMargin: string;
|
|
28
|
-
maintMargin: string;
|
|
29
|
-
marginAvailable: boolean;
|
|
30
|
-
}
|
|
31
|
-
interface BinanceRawAccountStatus {
|
|
32
|
-
totalWalletBalance: string;
|
|
33
|
-
totalMarginBalance: string;
|
|
34
|
-
availableBalance: string;
|
|
35
|
-
totalUnrealizedProfit: string;
|
|
36
|
-
totalInitialMargin: string;
|
|
37
|
-
totalMaintMargin: string;
|
|
38
|
-
assets?: BinanceRawAsset[];
|
|
39
|
-
}
|
|
40
|
-
interface BinanceMultiAssetsMarginResponse {
|
|
41
|
-
multiAssetsMargin: boolean;
|
|
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
|
-
}
|
|
78
|
-
interface BinanceAssetIndex {
|
|
79
|
-
symbol: string;
|
|
80
|
-
time: number;
|
|
81
|
-
index: string;
|
|
82
|
-
bidBuffer: string;
|
|
83
|
-
askBuffer: string;
|
|
84
|
-
bidRate: string;
|
|
85
|
-
askRate: string;
|
|
86
|
-
autoExchangeBidBuffer: string;
|
|
87
|
-
autoExchangeAskBuffer: string;
|
|
88
|
-
autoExchangeBidRate: string;
|
|
89
|
-
autoExchangeAskRate: string;
|
|
90
|
-
}
|
|
91
|
-
interface BinanceRawUserDataEvent {
|
|
92
|
-
e?: string;
|
|
93
|
-
ac?: {
|
|
94
|
-
s: string;
|
|
95
|
-
l: string;
|
|
96
|
-
};
|
|
97
|
-
a?: {
|
|
98
|
-
B?: unknown[];
|
|
99
|
-
P?: unknown[];
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type { BinanceAssetIndex, BinanceMultiAssetsMarginResponse, BinanceRawAccountStatus, BinanceRawAsset, BinanceRawOrder, BinanceRawPositionRisk, BinanceRawUserDataEvent, BinanceRawUserTrade };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { BinanceCredentialsDTO } from '@pear-protocol/types';
|
|
2
|
-
import { BaseWs } from '../base-ws.js';
|
|
3
|
-
import 'partysocket';
|
|
4
|
-
|
|
5
|
-
type BinanceUserDataWsConfig = {
|
|
6
|
-
listenKey: string;
|
|
7
|
-
demo: boolean;
|
|
8
|
-
};
|
|
9
|
-
declare class BinanceUserDataWs extends BaseWs {
|
|
10
|
-
private readonly listenKey;
|
|
11
|
-
private readonly demo;
|
|
12
|
-
constructor(config: BinanceUserDataWsConfig);
|
|
13
|
-
protected getWsUrl(): string;
|
|
14
|
-
protected getPingIntervalMs(): number;
|
|
15
|
-
protected buildPingMessage(): null;
|
|
16
|
-
}
|
|
17
|
-
type BinanceWsApiConfig = {
|
|
18
|
-
demo: boolean;
|
|
19
|
-
};
|
|
20
|
-
declare class BinanceWsApi extends BaseWs {
|
|
21
|
-
private readonly demo;
|
|
22
|
-
private requestId;
|
|
23
|
-
constructor(config: BinanceWsApiConfig);
|
|
24
|
-
protected getWsUrl(): string;
|
|
25
|
-
protected getPingIntervalMs(): number;
|
|
26
|
-
protected buildPingMessage(): null;
|
|
27
|
-
sendSignedRequest(creds: BinanceCredentialsDTO, method: string, params?: Record<string, unknown>): Promise<number>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { BinanceUserDataWs, type BinanceUserDataWsConfig, BinanceWsApi, type BinanceWsApiConfig };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BybitCredentialsDTO } from '@pear-protocol/types';
|
|
2
|
-
import { BaseWs } from '../base-ws.js';
|
|
3
|
-
import { ExchangeWs } from '../exchange-ws.js';
|
|
4
|
-
import { BybitWs } from './ws.js';
|
|
5
|
-
import 'partysocket';
|
|
6
|
-
|
|
7
|
-
declare class BybitExchangeWs extends ExchangeWs {
|
|
8
|
-
main: BybitWs;
|
|
9
|
-
private readonly creds;
|
|
10
|
-
readonly exchange: "bybit";
|
|
11
|
-
constructor(main: BybitWs, creds: BybitCredentialsDTO);
|
|
12
|
-
protected connections(): BaseWs[];
|
|
13
|
-
authenticate(): Promise<void>;
|
|
14
|
-
static create(config: {
|
|
15
|
-
demo: boolean;
|
|
16
|
-
credentials: BybitCredentialsDTO;
|
|
17
|
-
}): Promise<BybitExchangeWs>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { BybitExchangeWs };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BybitCredentialsDTO } from '@pear-protocol/types';
|
|
2
|
-
import { BybitRawAccountInfo, BybitRawExecution, BybitRawPosition, BybitRawWallet } from './types.js';
|
|
3
|
-
|
|
4
|
-
declare function fetchWalletBalance(creds: BybitCredentialsDTO, demo: boolean): Promise<BybitRawWallet | undefined>;
|
|
5
|
-
declare function fetchPositions(creds: BybitCredentialsDTO, settleCoin: string, demo: boolean): Promise<BybitRawPosition[]>;
|
|
6
|
-
declare function fetchPositionLeverage(creds: BybitCredentialsDTO, symbol: string, demo: boolean): Promise<BybitRawPosition | undefined>;
|
|
7
|
-
declare function fetchAccountInfo(creds: BybitCredentialsDTO, demo: boolean): Promise<BybitRawAccountInfo>;
|
|
8
|
-
declare function fetchCollateralRatios(creds: BybitCredentialsDTO, demo: boolean): Promise<Map<string, string>>;
|
|
9
|
-
declare function fetchExecutionsSince(creds: BybitCredentialsDTO, since: Date, demo: boolean): Promise<BybitRawExecution[]>;
|
|
10
|
-
|
|
11
|
-
export { fetchAccountInfo, fetchCollateralRatios, fetchExecutionsSince, fetchPositionLeverage, fetchPositions, fetchWalletBalance };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
interface BybitRawCoin {
|
|
2
|
-
coin: string;
|
|
3
|
-
equity: string;
|
|
4
|
-
usdValue: string;
|
|
5
|
-
walletBalance: string;
|
|
6
|
-
unrealisedPnl: string;
|
|
7
|
-
totalPositionIM: string;
|
|
8
|
-
totalPositionMM: string;
|
|
9
|
-
totalOrderIM: string;
|
|
10
|
-
locked: string;
|
|
11
|
-
borrowAmount: string;
|
|
12
|
-
marginCollateral: boolean;
|
|
13
|
-
collateralSwitch: boolean;
|
|
14
|
-
}
|
|
15
|
-
interface BybitRawWallet {
|
|
16
|
-
totalEquity: string;
|
|
17
|
-
totalWalletBalance: string;
|
|
18
|
-
totalMarginBalance: string;
|
|
19
|
-
totalAvailableBalance: string;
|
|
20
|
-
totalPerpUPL: string;
|
|
21
|
-
totalInitialMargin: string;
|
|
22
|
-
totalMaintenanceMargin: string;
|
|
23
|
-
accountMMRate: string;
|
|
24
|
-
coin: BybitRawCoin[];
|
|
25
|
-
}
|
|
26
|
-
interface BybitRawAccountInfo {
|
|
27
|
-
marginMode: string;
|
|
28
|
-
updatedTime: string;
|
|
29
|
-
}
|
|
30
|
-
interface BybitRawCollateralTier {
|
|
31
|
-
collateralCoin: string;
|
|
32
|
-
rate: string;
|
|
33
|
-
collateralAmount: string;
|
|
34
|
-
}
|
|
35
|
-
interface BybitRawCollateralRatioEntry {
|
|
36
|
-
currency: string;
|
|
37
|
-
tiers: BybitRawCollateralTier[];
|
|
38
|
-
}
|
|
39
|
-
interface BybitRawPosition {
|
|
40
|
-
symbol: string;
|
|
41
|
-
side: string;
|
|
42
|
-
size: string;
|
|
43
|
-
avgPrice: string;
|
|
44
|
-
unrealisedPnl: string;
|
|
45
|
-
leverage: string;
|
|
46
|
-
tradeMode: string;
|
|
47
|
-
liqPrice: string;
|
|
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
|
-
}
|
|
62
|
-
interface BybitResponse<T> {
|
|
63
|
-
retCode: number;
|
|
64
|
-
retMsg: string;
|
|
65
|
-
result: T;
|
|
66
|
-
}
|
|
67
|
-
type BybitWsMessage = {
|
|
68
|
-
topic: 'wallet';
|
|
69
|
-
data: BybitRawWallet[];
|
|
70
|
-
} | {
|
|
71
|
-
topic: 'position';
|
|
72
|
-
data: BybitRawPosition[];
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export type { BybitRawAccountInfo, BybitRawCoin, BybitRawCollateralRatioEntry, BybitRawCollateralTier, BybitRawExecution, BybitRawPosition, BybitRawWallet, BybitResponse, BybitWsMessage };
|