@pear-protocol/core-sdk 0.0.14 → 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.
@@ -1,4 +1,4 @@
1
- class Info {
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
- users = {
48
- profile: async (headers) => {
49
- return await this.client.fetch(`/users/profile`, {
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
- body
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
- updatePreferences: async (body, headers) => {
62
- return await this.client.fetch(`/users/preferences`, {
63
- method: "PATCH",
63
+ list: async (query, headers) => {
64
+ return await this.client.fetch(`/fills`, {
65
+ method: "GET",
64
66
  headers,
65
- body
67
+ query
66
68
  });
67
69
  }
68
70
  };
69
- schedules = {
71
+ funding = {
70
72
  list: async (query, headers) => {
71
- return await this.client.fetch(`/schedules`, {
73
+ return await this.client.fetch(`/funding`, {
72
74
  method: "GET",
73
75
  headers,
74
76
  query
75
77
  });
76
78
  }
77
79
  };
78
- triggers = {
80
+ instruments = {
79
81
  list: async (query, headers) => {
80
- return await this.client.fetch(`/triggers`, {
82
+ return await this.client.fetch(`/instruments`, {
81
83
  method: "GET",
82
84
  headers,
83
85
  query
@@ -93,54 +95,134 @@ class Info {
93
95
  });
94
96
  }
95
97
  };
96
- fills = {
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(`/fills`, {
100
+ return await this.client.fetch(`/prices`, {
105
101
  method: "GET",
106
102
  headers,
107
103
  query
108
104
  });
109
105
  }
110
106
  };
111
- executions = {
107
+ schedules = {
112
108
  list: async (query, headers) => {
113
- return await this.client.fetch(`/executions`, {
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
- instruments = {
121
- list: async (query, headers) => {
122
- return await this.client.fetch(`/instruments`, {
123
- method: "GET",
135
+ trade = {
136
+ open: async (body, headers) => {
137
+ return await this.client.fetch(`/trade/open`, {
138
+ method: "POST",
124
139
  headers,
125
- query
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
126
169
  });
127
170
  }
128
171
  };
129
- prices = {
172
+ triggers = {
130
173
  list: async (query, headers) => {
131
- return await this.client.fetch(`/prices`, {
174
+ return await this.client.fetch(`/triggers`, {
132
175
  method: "GET",
133
176
  headers,
134
177
  query
135
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
+ });
136
205
  }
137
206
  };
138
- funding = {
139
- list: async (query, headers) => {
140
- return await this.client.fetch(`/funding`, {
207
+ users = {
208
+ profile: async (headers) => {
209
+ return await this.client.fetch(`/users/profile`, {
141
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",
142
217
  headers,
143
- query
218
+ body
219
+ });
220
+ },
221
+ updatePreferences: async (body, headers) => {
222
+ return await this.client.fetch(`/users/preferences`, {
223
+ method: "PATCH",
224
+ headers,
225
+ body
144
226
  });
145
227
  }
146
228
  };
@@ -155,4 +237,4 @@ class Info {
155
237
  };
156
238
  }
157
239
 
158
- export { Info };
240
+ export { Core };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Auth } from './auth/index.js';
2
- import { Info } from './info/index.js';
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
- trade: Trade;
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
- trade;
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 apiClient = new HttpClient(config.apiUrl, authMode, config.logger, config.debug);
22
- const authClient = new HttpClient(config.authUrl, authMode, config.logger, config.debug);
23
- this.auth = new Auth(authClient);
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
- apiClient.useResponse(sessionRefreshMiddleware);
51
+ client.useResponse(sessionRefreshMiddleware);
56
52
  }
57
53
  if (authMode === "bearer" && config.auth?.token) {
58
54
  const getToken = config.auth.token;
59
- apiClient.useRequest(async (request, next) => {
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
- apiClient.useResponse(async (response) => {
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
- apiClient.useRequest(async (request, next) => {
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
- * Trade + Info endpoints.
4
+ * API endpoint.
5
5
  *
6
- * Example: 'https://api.pear.garden'
6
+ * Example: 'https://gateway.pearprotocol.io'
7
7
  */
8
- apiUrl: string;
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.14",
3
+ "version": "0.0.15",
4
4
  "description": "Pear Protocol Core SDK",
5
5
  "private": false,
6
6
  "type": "module",