@pear-protocol/core-sdk 0.0.13 → 0.0.15
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/core/index.d.ts +1859 -0
- package/dist/{info → core}/index.js +130 -39
- package/dist/index.d.ts +2 -4
- package/dist/index.js +9 -13
- package/dist/types.d.ts +3 -9
- package/package.json +3 -3
- package/dist/info/index.d.ts +0 -708
- package/dist/trade/index.d.ts +0 -1152
- package/dist/trade/index.js +0 -92
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class Core {
|
|
2
2
|
client;
|
|
3
3
|
constructor(client) {
|
|
4
4
|
this.client = client;
|
|
@@ -44,40 +44,42 @@ class Info {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return await this.client.fetch(`/
|
|
47
|
+
executions = {
|
|
48
|
+
list: async (query, headers) => {
|
|
49
|
+
return await this.client.fetch(`/executions`, {
|
|
50
50
|
method: "GET",
|
|
51
|
-
headers
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
updateDisplayName: async (body, headers) => {
|
|
55
|
-
return await this.client.fetch(`/users/profile/display-name`, {
|
|
56
|
-
method: "PATCH",
|
|
57
51
|
headers,
|
|
58
|
-
|
|
52
|
+
query
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
fills = {
|
|
57
|
+
details: async (positionId, headers) => {
|
|
58
|
+
return await this.client.fetch(`/fills/${positionId}`, {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers
|
|
59
61
|
});
|
|
60
62
|
},
|
|
61
|
-
|
|
62
|
-
return await this.client.fetch(`/
|
|
63
|
-
method: "
|
|
63
|
+
list: async (query, headers) => {
|
|
64
|
+
return await this.client.fetch(`/fills`, {
|
|
65
|
+
method: "GET",
|
|
64
66
|
headers,
|
|
65
|
-
|
|
67
|
+
query
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
};
|
|
69
|
-
|
|
71
|
+
funding = {
|
|
70
72
|
list: async (query, headers) => {
|
|
71
|
-
return await this.client.fetch(`/
|
|
73
|
+
return await this.client.fetch(`/funding`, {
|
|
72
74
|
method: "GET",
|
|
73
75
|
headers,
|
|
74
76
|
query
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
|
-
|
|
80
|
+
instruments = {
|
|
79
81
|
list: async (query, headers) => {
|
|
80
|
-
return await this.client.fetch(`/
|
|
82
|
+
return await this.client.fetch(`/instruments`, {
|
|
81
83
|
method: "GET",
|
|
82
84
|
headers,
|
|
83
85
|
query
|
|
@@ -93,51 +95,140 @@ class Info {
|
|
|
93
95
|
});
|
|
94
96
|
}
|
|
95
97
|
};
|
|
96
|
-
|
|
97
|
-
details: async (positionId, headers) => {
|
|
98
|
-
return await this.client.fetch(`/fills/${positionId}`, {
|
|
99
|
-
method: "GET",
|
|
100
|
-
headers
|
|
101
|
-
});
|
|
102
|
-
},
|
|
98
|
+
prices = {
|
|
103
99
|
list: async (query, headers) => {
|
|
104
|
-
return await this.client.fetch(`/
|
|
100
|
+
return await this.client.fetch(`/prices`, {
|
|
105
101
|
method: "GET",
|
|
106
102
|
headers,
|
|
107
103
|
query
|
|
108
104
|
});
|
|
109
105
|
}
|
|
110
106
|
};
|
|
111
|
-
|
|
107
|
+
schedules = {
|
|
112
108
|
list: async (query, headers) => {
|
|
113
|
-
return await this.client.fetch(`/
|
|
109
|
+
return await this.client.fetch(`/schedules`, {
|
|
114
110
|
method: "GET",
|
|
115
111
|
headers,
|
|
116
112
|
query
|
|
117
113
|
});
|
|
114
|
+
},
|
|
115
|
+
create: async (body, headers) => {
|
|
116
|
+
return await this.client.fetch(`/schedules`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers,
|
|
119
|
+
body
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
cancel: async (scheduleId, headers) => {
|
|
123
|
+
return await this.client.fetch(`/schedules/${scheduleId}/cancel`, {
|
|
124
|
+
method: "PATCH",
|
|
125
|
+
headers
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
cancelAll: async (headers) => {
|
|
129
|
+
return await this.client.fetch(`/schedules/cancel-all`, {
|
|
130
|
+
method: "PATCH",
|
|
131
|
+
headers
|
|
132
|
+
});
|
|
118
133
|
}
|
|
119
134
|
};
|
|
120
|
-
|
|
135
|
+
trade = {
|
|
136
|
+
open: async (body, headers) => {
|
|
137
|
+
return await this.client.fetch(`/trade/open`, {
|
|
138
|
+
method: "POST",
|
|
139
|
+
headers,
|
|
140
|
+
body
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
adjust: async (positionId, body, headers) => {
|
|
144
|
+
return await this.client.fetch(`/trade/${positionId}/adjust`, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers,
|
|
147
|
+
body
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
close: async (positionId, body, headers) => {
|
|
151
|
+
return await this.client.fetch(`/trade/${positionId}/close`, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers,
|
|
154
|
+
body
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
closeAll: async (body, headers) => {
|
|
158
|
+
return await this.client.fetch(`/trade/close-all`, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
headers,
|
|
161
|
+
body
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
setLeverage: async (body, headers) => {
|
|
165
|
+
return await this.client.fetch(`/leverage`, {
|
|
166
|
+
method: "PUT",
|
|
167
|
+
headers,
|
|
168
|
+
body
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
triggers = {
|
|
121
173
|
list: async (query, headers) => {
|
|
122
|
-
return await this.client.fetch(`/
|
|
174
|
+
return await this.client.fetch(`/triggers`, {
|
|
123
175
|
method: "GET",
|
|
124
176
|
headers,
|
|
125
177
|
query
|
|
126
178
|
});
|
|
179
|
+
},
|
|
180
|
+
open: async (body, headers) => {
|
|
181
|
+
return await this.client.fetch(`/triggers/open`, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers,
|
|
184
|
+
body
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
close: async (body, headers) => {
|
|
188
|
+
return await this.client.fetch(`/triggers/close`, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
headers,
|
|
191
|
+
body
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
cancel: async (triggerId, headers) => {
|
|
195
|
+
return await this.client.fetch(`/triggers/${triggerId}/cancel`, {
|
|
196
|
+
method: "PATCH",
|
|
197
|
+
headers
|
|
198
|
+
});
|
|
199
|
+
},
|
|
200
|
+
cancelAll: async (headers) => {
|
|
201
|
+
return await this.client.fetch(`/triggers/cancel-all`, {
|
|
202
|
+
method: "PATCH",
|
|
203
|
+
headers
|
|
204
|
+
});
|
|
127
205
|
}
|
|
128
206
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return await this.client.fetch(`/
|
|
207
|
+
users = {
|
|
208
|
+
profile: async (headers) => {
|
|
209
|
+
return await this.client.fetch(`/users/profile`, {
|
|
132
210
|
method: "GET",
|
|
211
|
+
headers
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
updateDisplayName: async (body, headers) => {
|
|
215
|
+
return await this.client.fetch(`/users/profile/display-name`, {
|
|
216
|
+
method: "PATCH",
|
|
133
217
|
headers,
|
|
134
|
-
|
|
218
|
+
body
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
updatePreferences: async (body, headers) => {
|
|
222
|
+
return await this.client.fetch(`/users/preferences`, {
|
|
223
|
+
method: "PATCH",
|
|
224
|
+
headers,
|
|
225
|
+
body
|
|
135
226
|
});
|
|
136
227
|
}
|
|
137
228
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return await this.client.fetch(`/
|
|
229
|
+
statistics = {
|
|
230
|
+
daily: async (query, headers) => {
|
|
231
|
+
return await this.client.fetch(`/statistics/daily`, {
|
|
141
232
|
method: "GET",
|
|
142
233
|
headers,
|
|
143
234
|
query
|
|
@@ -146,4 +237,4 @@ class Info {
|
|
|
146
237
|
};
|
|
147
238
|
}
|
|
148
239
|
|
|
149
|
-
export {
|
|
240
|
+
export { Core };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Auth } from './auth/index.js';
|
|
2
|
-
import {
|
|
3
|
-
import { Trade } from './trade/index.js';
|
|
2
|
+
import { Core } from './core/index.js';
|
|
4
3
|
import { SDKConfig } from './types.js';
|
|
5
4
|
export { HttpTypes } from '@pear-protocol/types';
|
|
6
5
|
export * from '@pear-protocol/utils';
|
|
@@ -8,8 +7,7 @@ import './http.js';
|
|
|
8
7
|
|
|
9
8
|
declare class PearSDK {
|
|
10
9
|
auth: Auth;
|
|
11
|
-
|
|
12
|
-
info: Info;
|
|
10
|
+
core: Core;
|
|
13
11
|
constructor(config: SDKConfig);
|
|
14
12
|
}
|
|
15
13
|
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Auth } from './auth';
|
|
2
|
+
import { Core } from './core';
|
|
2
3
|
import { HttpClient } from './http';
|
|
3
|
-
import { Info } from './info';
|
|
4
|
-
import { Trade } from './trade';
|
|
5
4
|
import { FetchError } from './utils';
|
|
6
5
|
export * from '@pear-protocol/utils';
|
|
7
6
|
|
|
8
7
|
class PearSDK {
|
|
9
8
|
auth;
|
|
10
|
-
|
|
11
|
-
info;
|
|
9
|
+
core;
|
|
12
10
|
constructor(config) {
|
|
13
11
|
const authMode = config.auth?.type ?? "session";
|
|
14
12
|
const logger = config.logger ?? {
|
|
@@ -18,11 +16,9 @@ class PearSDK {
|
|
|
18
16
|
debug: config.debug ? console.debug : () => {
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
this.
|
|
24
|
-
this.trade = new Trade(apiClient);
|
|
25
|
-
this.info = new Info(apiClient);
|
|
19
|
+
const client = new HttpClient(config.url, authMode, config.logger, config.debug);
|
|
20
|
+
this.auth = new Auth(client);
|
|
21
|
+
this.core = new Core(client);
|
|
26
22
|
if (authMode === "session") {
|
|
27
23
|
let refreshInFlight = null;
|
|
28
24
|
const refreshSession = async () => {
|
|
@@ -52,11 +48,11 @@ class PearSDK {
|
|
|
52
48
|
throw new FetchError("Session expired. Please log in again.", "Unauthorized", 401);
|
|
53
49
|
}
|
|
54
50
|
};
|
|
55
|
-
|
|
51
|
+
client.useResponse(sessionRefreshMiddleware);
|
|
56
52
|
}
|
|
57
53
|
if (authMode === "bearer" && config.auth?.token) {
|
|
58
54
|
const getToken = config.auth.token;
|
|
59
|
-
|
|
55
|
+
client.useRequest(async (request, next) => {
|
|
60
56
|
const token = getToken();
|
|
61
57
|
if (token) {
|
|
62
58
|
request.headers.set("Authorization", `Bearer ${token}`);
|
|
@@ -65,7 +61,7 @@ class PearSDK {
|
|
|
65
61
|
});
|
|
66
62
|
if (config.onAuthError) {
|
|
67
63
|
const onAuthError = config.onAuthError;
|
|
68
|
-
|
|
64
|
+
client.useResponse(async (response) => {
|
|
69
65
|
if (response.status === 401) {
|
|
70
66
|
onAuthError();
|
|
71
67
|
throw new FetchError("Unauthorized. Token may be expired or revoked.", "Unauthorized", 401);
|
|
@@ -76,7 +72,7 @@ class PearSDK {
|
|
|
76
72
|
}
|
|
77
73
|
if (config.getTradeAccountId) {
|
|
78
74
|
const getTradeAccountId = config.getTradeAccountId;
|
|
79
|
-
|
|
75
|
+
client.useRequest(async (request, next) => {
|
|
80
76
|
const tradeAccountId = getTradeAccountId();
|
|
81
77
|
if (tradeAccountId) {
|
|
82
78
|
request.headers.set("x-trade-account-id", tradeAccountId);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
type AuthMode = 'session' | 'bearer';
|
|
2
2
|
type SDKConfig = {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* API endpoint.
|
|
5
5
|
*
|
|
6
|
-
* Example: 'https://
|
|
6
|
+
* Example: 'https://gateway.pearprotocol.io'
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Authentication endpoint.
|
|
11
|
-
*
|
|
12
|
-
* Example: 'https://auth.pear.garden'
|
|
13
|
-
*/
|
|
14
|
-
authUrl: string;
|
|
8
|
+
url: string;
|
|
15
9
|
/**
|
|
16
10
|
* Authentication transport mode:
|
|
17
11
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/core-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "Pear Protocol Core SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"typecheck": "tsc --noEmit"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@pear-protocol/types": "0.0.
|
|
29
|
-
"@pear-protocol/utils": "0.0.
|
|
28
|
+
"@pear-protocol/types": "0.0.13",
|
|
29
|
+
"@pear-protocol/utils": "0.0.13",
|
|
30
30
|
"qs": "^6.14.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|