bybit-api 3.7.1-beta.0 → 3.7.2
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 +34 -6
- package/lib/constants/enum.d.ts +4 -1
- package/lib/constants/enum.js +4 -1
- package/lib/constants/enum.js.map +1 -1
- package/lib/rest-client-v5.d.ts +3 -3
- package/lib/rest-client-v5.js.map +1 -1
- package/lib/types/request/v5-trade.d.ts +2 -2
- package/lib/types/response/v5-market.d.ts +4 -1
- package/package.json +1 -13
- package/src/account-asset-client-v3.ts +0 -310
- package/src/account-asset-client.ts +0 -149
- package/src/constants/enum.ts +0 -105
- package/src/contract-client.ts +0 -360
- package/src/copy-trading-client.ts +0 -159
- package/src/index.ts +0 -18
- package/src/inverse-client.ts +0 -337
- package/src/inverse-futures-client.ts +0 -403
- package/src/linear-client.ts +0 -387
- package/src/rest-client-v5.ts +0 -1638
- package/src/spot-client-v3.ts +0 -303
- package/src/spot-client.ts +0 -180
- package/src/types/index.ts +0 -5
- package/src/types/request/account-asset.ts +0 -258
- package/src/types/request/contract.ts +0 -139
- package/src/types/request/copy-trading.ts +0 -53
- package/src/types/request/index.ts +0 -18
- package/src/types/request/inverse.ts +0 -135
- package/src/types/request/linear.ts +0 -201
- package/src/types/request/spot.ts +0 -89
- package/src/types/request/unified-margin.ts +0 -247
- package/src/types/request/usdc-options.ts +0 -134
- package/src/types/request/usdc-perp.ts +0 -100
- package/src/types/request/usdc-shared.ts +0 -39
- package/src/types/request/v5-account.ts +0 -40
- package/src/types/request/v5-asset.ts +0 -133
- package/src/types/request/v5-market.ts +0 -127
- package/src/types/request/v5-position.ts +0 -107
- package/src/types/request/v5-pre-upgrade.ts +0 -37
- package/src/types/request/v5-spot-leverage-token.ts +0 -23
- package/src/types/request/v5-trade.ts +0 -133
- package/src/types/request/v5-user.ts +0 -21
- package/src/types/response/account-asset.ts +0 -236
- package/src/types/response/contract.ts +0 -74
- package/src/types/response/index.ts +0 -13
- package/src/types/response/shared.ts +0 -19
- package/src/types/response/spot.ts +0 -17
- package/src/types/response/unified-margin.ts +0 -71
- package/src/types/response/usdt-perp.ts +0 -58
- package/src/types/response/v5-account.ts +0 -122
- package/src/types/response/v5-asset.ts +0 -170
- package/src/types/response/v5-market.ts +0 -271
- package/src/types/response/v5-position.ts +0 -118
- package/src/types/response/v5-spot-leverage-token.ts +0 -70
- package/src/types/response/v5-trade.ts +0 -103
- package/src/types/response/v5-user.ts +0 -58
- package/src/types/shared.ts +0 -175
- package/src/types/v5-shared.ts +0 -213
- package/src/types/websockets.ts +0 -115
- package/src/types/ws-events/failed-topic-subscription-confirmation.ts +0 -6
- package/src/types/ws-events/succeeded-topic-subscription-confirmation.ts +0 -6
- package/src/types/ws-events/topic-subscription-confirmation.ts +0 -7
- package/src/unified-margin-client.ts +0 -400
- package/src/usdc-option-client.ts +0 -333
- package/src/usdc-perpetual-client.ts +0 -312
- package/src/util/BaseRestClient.ts +0 -502
- package/src/util/WsStore.ts +0 -160
- package/src/util/browser-support.ts +0 -29
- package/src/util/index.ts +0 -5
- package/src/util/logger.ts +0 -26
- package/src/util/node-support.ts +0 -9
- package/src/util/requestUtils.ts +0 -171
- package/src/util/websocket-util.ts +0 -550
- package/src/websocket-client.ts +0 -1262
package/src/util/logger.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
/* eslint-disable no-unused-vars */
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4
|
-
export type LogParams = null | any;
|
|
5
|
-
|
|
6
|
-
export const DefaultLogger = {
|
|
7
|
-
/** Ping/pong events and other raw messages that might be noisy */
|
|
8
|
-
silly: (...params: LogParams): void => {
|
|
9
|
-
// console.log(params);
|
|
10
|
-
},
|
|
11
|
-
debug: (...params: LogParams): void => {
|
|
12
|
-
console.log(params);
|
|
13
|
-
},
|
|
14
|
-
notice: (...params: LogParams): void => {
|
|
15
|
-
console.log(params);
|
|
16
|
-
},
|
|
17
|
-
info: (...params: LogParams): void => {
|
|
18
|
-
console.info(params);
|
|
19
|
-
},
|
|
20
|
-
warning: (...params: LogParams): void => {
|
|
21
|
-
console.error(params);
|
|
22
|
-
},
|
|
23
|
-
error: (...params: LogParams): void => {
|
|
24
|
-
console.error(params);
|
|
25
|
-
},
|
|
26
|
-
};
|
package/src/util/node-support.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createHmac } from 'crypto';
|
|
2
|
-
|
|
3
|
-
/** This is async because the browser version uses a promise (browser-support) */
|
|
4
|
-
export async function signMessage(
|
|
5
|
-
message: string,
|
|
6
|
-
secret: string
|
|
7
|
-
): Promise<string> {
|
|
8
|
-
return createHmac('sha256', secret).update(message).digest('hex');
|
|
9
|
-
}
|
package/src/util/requestUtils.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { WebsocketSucceededTopicSubscriptionConfirmationEvent } from '../types/ws-events/succeeded-topic-subscription-confirmation';
|
|
2
|
-
import { WebsocketTopicSubscriptionConfirmationEvent } from '../types/ws-events/topic-subscription-confirmation';
|
|
3
|
-
|
|
4
|
-
export interface RestClientOptions {
|
|
5
|
-
/** Your API key */
|
|
6
|
-
key?: string;
|
|
7
|
-
|
|
8
|
-
/** Your API secret */
|
|
9
|
-
secret?: string;
|
|
10
|
-
|
|
11
|
-
/** Set to `true` to connect to testnet. Uses the live environment by default. */
|
|
12
|
-
testnet?: boolean;
|
|
13
|
-
|
|
14
|
-
/** Override the max size of the request window (in ms) */
|
|
15
|
-
recv_window?: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Disabled by default.
|
|
19
|
-
* This can help on machines with consistent latency problems.
|
|
20
|
-
*
|
|
21
|
-
* Note: this feature is not recommended as one slow request can cause problems
|
|
22
|
-
*/
|
|
23
|
-
enable_time_sync?: boolean;
|
|
24
|
-
|
|
25
|
-
/** How often to sync time drift with bybit servers */
|
|
26
|
-
sync_interval_ms?: number | string;
|
|
27
|
-
|
|
28
|
-
/** Determines whether to perform time synchronization before sending private requests */
|
|
29
|
-
syncTimeBeforePrivateRequests?: false;
|
|
30
|
-
|
|
31
|
-
/** Default: false. If true, we'll throw errors if any params are undefined */
|
|
32
|
-
strict_param_validation?: boolean;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Default: true.
|
|
36
|
-
* If true, request parameters will be URI encoded during the signing process.
|
|
37
|
-
* New behaviour introduced in v3.2.1 to fix rare parameter-driven sign errors with unified margin cursors containing "%".
|
|
38
|
-
*/
|
|
39
|
-
encodeSerialisedValues?: boolean;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Optionally override API protocol + domain
|
|
43
|
-
* e.g baseUrl: 'https://api.bytick.com'
|
|
44
|
-
**/
|
|
45
|
-
baseUrl?: string;
|
|
46
|
-
|
|
47
|
-
/** Default: true. whether to try and post-process request exceptions. */
|
|
48
|
-
parse_exceptions?: boolean;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Serialise a (flat) object into a query string
|
|
53
|
-
* @param params the object to serialise
|
|
54
|
-
* @param strict_validation throw if any properties are undefined
|
|
55
|
-
* @param sortProperties sort properties alphabetically before building a query string
|
|
56
|
-
* @param encodeSerialisedValues URL encode value before serialising
|
|
57
|
-
* @returns the params object as a serialised string key1=value1&key2=value2&etc
|
|
58
|
-
*/
|
|
59
|
-
export function serializeParams(
|
|
60
|
-
params: object = {},
|
|
61
|
-
strict_validation = false,
|
|
62
|
-
sortProperties = true,
|
|
63
|
-
encodeSerialisedValues = true,
|
|
64
|
-
): string {
|
|
65
|
-
const properties = sortProperties
|
|
66
|
-
? Object.keys(params).sort()
|
|
67
|
-
: Object.keys(params);
|
|
68
|
-
|
|
69
|
-
return properties
|
|
70
|
-
.map((key) => {
|
|
71
|
-
const value = encodeSerialisedValues
|
|
72
|
-
? encodeURIComponent(params[key])
|
|
73
|
-
: params[key];
|
|
74
|
-
|
|
75
|
-
if (strict_validation === true && typeof value === 'undefined') {
|
|
76
|
-
throw new Error(
|
|
77
|
-
'Failed to sign API request due to undefined parameter',
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
return `${key}=${value}`;
|
|
81
|
-
})
|
|
82
|
-
.join('&');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function getRestBaseUrl(
|
|
86
|
-
useTestnet: boolean,
|
|
87
|
-
restInverseOptions: RestClientOptions,
|
|
88
|
-
): string {
|
|
89
|
-
const exchangeBaseUrls = {
|
|
90
|
-
livenet: 'https://api.bybit.com',
|
|
91
|
-
testnet: 'https://api-testnet.bybit.com',
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
if (restInverseOptions.baseUrl) {
|
|
95
|
-
return restInverseOptions.baseUrl;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (useTestnet) {
|
|
99
|
-
return exchangeBaseUrls.testnet;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return exchangeBaseUrls.livenet;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
export function isWsPong(msg: any): boolean {
|
|
107
|
-
if (!msg) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (msg.pong || msg.ping) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (msg['op'] === 'pong') {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (msg['ret_msg'] === 'pong') {
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return (
|
|
123
|
-
msg.request &&
|
|
124
|
-
msg.request.op === 'ping' &&
|
|
125
|
-
msg.ret_msg === 'pong' &&
|
|
126
|
-
msg.success === true
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function isTopicSubscriptionConfirmation(
|
|
131
|
-
msg: unknown,
|
|
132
|
-
): msg is WebsocketTopicSubscriptionConfirmationEvent {
|
|
133
|
-
if (typeof msg !== 'object') {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
if (!msg) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (typeof msg['op'] !== 'string') {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (msg['op'] !== 'subscribe') {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function isTopicSubscriptionSuccess(
|
|
150
|
-
msg: unknown,
|
|
151
|
-
): msg is WebsocketSucceededTopicSubscriptionConfirmationEvent {
|
|
152
|
-
if (!isTopicSubscriptionConfirmation(msg)) return false;
|
|
153
|
-
return msg.success === true;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export const APIID = 'bybitapinode';
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Used to switch how authentication/requests work under the hood (primarily for SPOT since it's different there)
|
|
160
|
-
*/
|
|
161
|
-
export const REST_CLIENT_TYPE_ENUM = {
|
|
162
|
-
accountAsset: 'accountAsset',
|
|
163
|
-
inverse: 'inverse',
|
|
164
|
-
inverseFutures: 'inverseFutures',
|
|
165
|
-
linear: 'linear',
|
|
166
|
-
spot: 'spot',
|
|
167
|
-
v3: 'v3',
|
|
168
|
-
} as const;
|
|
169
|
-
|
|
170
|
-
export type RestClientType =
|
|
171
|
-
(typeof REST_CLIENT_TYPE_ENUM)[keyof typeof REST_CLIENT_TYPE_ENUM];
|