cloreai 0.1.18 → 1.0.0
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 +286 -0
- package/build/{cloreai/CloreAI.d.ts → CloreAI.d.ts} +7 -11
- package/build/{cloreai/CloreAI.js → CloreAI.js} +29 -46
- package/build/Gigaspot.d.ts +17 -0
- package/build/Gigaspot.js +46 -0
- package/build/constants.d.ts +7 -0
- package/build/constants.js +7 -0
- package/build/endpoints/cancelOrder.d.ts +6 -0
- package/build/{cloreai/endpoints → endpoints}/cancelOrders.d.ts +1 -1
- package/build/{cloreai/endpoints → endpoints}/createGigaspotOrders.d.ts +1 -2
- package/build/{common/endpoints → endpoints}/createOrder.d.ts +3 -2
- package/build/{cloreai/endpoints → endpoints}/getGigaspot.d.ts +1 -2
- package/build/endpoints/marketplace.d.ts +24 -0
- package/build/{common/endpoints → endpoints}/myOrders.d.ts +15 -8
- package/build/{cloreai/endpoints → endpoints}/myServers.d.ts +1 -2
- package/build/endpoints/pohBalance.d.ts +31 -0
- package/build/{cloreai/endpoints → endpoints}/serverConfig.d.ts +1 -2
- package/build/endpoints/setServerSettings.d.ts +11 -0
- package/build/endpoints/setSpotPrice.d.ts +17 -0
- package/build/endpoints/spotMarketplace.d.ts +26 -0
- package/build/{cloreai/endpoints → endpoints}/wallets.d.ts +1 -2
- package/build/errors.d.ts +22 -0
- package/build/{common/constants.d.ts → helpers.d.ts} +5 -2
- package/build/{common/helpers.js → helpers.js} +15 -11
- package/build/index.d.ts +19 -3
- package/build/index.js +3 -3
- package/build/{common/types.d.ts → types.d.ts} +24 -14
- package/package.json +11 -26
- package/build/cloreai/endpoints/cancelOrder.d.ts +0 -6
- package/build/cloreai/endpoints/createOrder.d.ts +0 -4
- package/build/cloreai/endpoints/marketplace.d.ts +0 -6
- package/build/cloreai/endpoints/myOrders.d.ts +0 -9
- package/build/cloreai/endpoints/setServerSettings.d.ts +0 -9
- package/build/cloreai/endpoints/setSpotPrice.d.ts +0 -4
- package/build/cloreai/endpoints/spotMarketplace.d.ts +0 -9
- package/build/cloreai/index.d.ts +0 -17
- package/build/cloreai/index.js +0 -2
- package/build/cloreai/types.d.ts +0 -7
- package/build/common/constants.js +0 -16
- package/build/common/endpoints/cancelOrder.d.ts +0 -3
- package/build/common/endpoints/cancelOrder.js +0 -2
- package/build/common/endpoints/createOrder.js +0 -1
- package/build/common/endpoints/marketplace.d.ts +0 -19
- package/build/common/endpoints/marketplace.js +0 -1
- package/build/common/endpoints/myOrders.js +0 -1
- package/build/common/endpoints/setSpotPrice.d.ts +0 -16
- package/build/common/endpoints/spotMarketplace.d.ts +0 -19
- package/build/common/endpoints/spotMarketplace.js +0 -1
- package/build/common/errors.d.ts +0 -23
- package/build/common/helpers.d.ts +0 -6
- package/build/common/index.d.ts +0 -10
- package/build/common/index.js +0 -3
- package/build/common/types.js +0 -1
- package/build/webapi/WebAPI.d.ts +0 -22
- package/build/webapi/WebAPI.js +0 -80
- package/build/webapi/endpoints/cancelOrder.d.ts +0 -6
- package/build/webapi/endpoints/cancelOrder.js +0 -1
- package/build/webapi/endpoints/createOrder.d.ts +0 -4
- package/build/webapi/endpoints/createOrder.js +0 -1
- package/build/webapi/endpoints/marketplace.d.ts +0 -10
- package/build/webapi/endpoints/marketplace.js +0 -1
- package/build/webapi/endpoints/myOrders.d.ts +0 -15
- package/build/webapi/endpoints/myOrders.js +0 -1
- package/build/webapi/endpoints/setSpotPrice.d.ts +0 -4
- package/build/webapi/endpoints/setSpotPrice.js +0 -1
- package/build/webapi/endpoints/spotMarketplace.d.ts +0 -8
- package/build/webapi/endpoints/spotMarketplace.js +0 -1
- package/build/webapi/index.d.ts +0 -9
- package/build/webapi/index.js +0 -2
- package/build/webapi/types.d.ts +0 -7
- package/build/webapi/types.js +0 -1
- package/build/webapi.d.ts +0 -4
- package/build/webapi.js +0 -4
- /package/build/{cloreai/endpoints → endpoints}/cancelOrder.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/cancelOrders.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/createGigaspotOrders.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/createOrder.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/editGigaspotOrders.d.ts +0 -0
- /package/build/{cloreai/endpoints → endpoints}/editGigaspotOrders.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/getGigaspot.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/marketplace.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/myOrders.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/myServers.js +0 -0
- /package/build/{cloreai/endpoints/serverConfig.js → endpoints/pohBalance.js} +0 -0
- /package/build/{cloreai/endpoints/setServerSettings.js → endpoints/serverConfig.js} +0 -0
- /package/build/{cloreai/endpoints/setSpotPrice.js → endpoints/setServerSettings.js} +0 -0
- /package/build/{common/endpoints → endpoints}/setSpotPrice.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/spotMarketplace.js +0 -0
- /package/build/{cloreai/endpoints → endpoints}/wallets.js +0 -0
- /package/build/{common/errors.js → errors.js} +0 -0
- /package/build/{cloreai/types.js → types.js} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# cloreai
|
|
2
|
+
|
|
3
|
+
> CLORE.AI API client
|
|
4
|
+
|
|
5
|
+
Особенности:
|
|
6
|
+
|
|
7
|
+
- Базируется на [axios](https://github.com/axios/axios)
|
|
8
|
+
- Защищает от превышения rate limit (ошибки 429) через
|
|
9
|
+
[p-queue](https://github.com/sindresorhus/p-queue)
|
|
10
|
+
- Поддерживает GigaSPOT
|
|
11
|
+
|
|
12
|
+
Официальная документация: [clore.ai/api-docs](https://clore.ai/api-docs)
|
|
13
|
+
|
|
14
|
+
Официальная документация GigaSPOT:
|
|
15
|
+
[gigaspot-api-docs.clore.ai](https://gigaspot-api-docs.clore.ai)
|
|
16
|
+
|
|
17
|
+
## Установка
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
npm install cloreai
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Использование
|
|
24
|
+
|
|
25
|
+
### Создание экземпляра
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import CloreAI from 'cloreai'
|
|
29
|
+
|
|
30
|
+
const cloreai = new CloreAI({
|
|
31
|
+
apiKey: '<API_KEY>', // (required)
|
|
32
|
+
axiosOptions: {}, // (optional) Axios instance options https://github.com/axios/axios
|
|
33
|
+
queueOptions: {}, // (optional) Queue instance options https://github.com/sindresorhus/p-queue
|
|
34
|
+
queueOptionsCreateOrder: {}, // (optional) Create order queue instance options https://github.com/sindresorhus/p-queue
|
|
35
|
+
queueOptionsGigaspot: {}, // (optional) Gigaspot queue instance options https://github.com/sindresorhus/p-queue
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 1. wallets
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const wallets = await cloreai.wallets()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. my_servers
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
const myServers = await cloreai.myServers()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3. server_config
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
const serverConfig = await cloreai.serverConfig({
|
|
55
|
+
server_name: 'server_name',
|
|
56
|
+
})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 4. marketplace
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const marketplace = await cloreai.marketplace()
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 5. my_orders
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
const myOrders = await cloreai.myOrders() // Current orders
|
|
69
|
+
const allMyOrders = await cloreai.myOrders({ return_completed: true }) // All orders
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 6. spot_marketplace
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const spotMarketplace = await cloreai.spotMarketplace({
|
|
76
|
+
market: 6718, // Server id
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 7. set_server_settings
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
await cloreai.setServerSettings({
|
|
84
|
+
'name': 'name', // Server name
|
|
85
|
+
'availability': true,
|
|
86
|
+
'mrl': 24,
|
|
87
|
+
'on_demand': 50,
|
|
88
|
+
'spot': 50,
|
|
89
|
+
'CLORE-Blockchain_on_demand': 50,
|
|
90
|
+
'CLORE-Blockchain_spot': 50,
|
|
91
|
+
})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 8. set_spot_price
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
await cloreai.setSpotPrice({
|
|
98
|
+
order_id: 38176,
|
|
99
|
+
desired_price: 50,
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### 9. cancel_order
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
await cloreai.cancelOrder({
|
|
107
|
+
id: 6718,
|
|
108
|
+
issue: 'issue',
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 10. create_order
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
await cloreai.createOrder({
|
|
116
|
+
type: 'on-demand',
|
|
117
|
+
currency: 'CLORE-Blockchain',
|
|
118
|
+
image: 'cloreai/jupyter:ubuntu24.04-v2',
|
|
119
|
+
renting_server: 5738,
|
|
120
|
+
ports: { 22: 'tcp', 8888: 'http' },
|
|
121
|
+
env: { SSH_PASSWORD: 'SSH_PASSWORD', JUPYTER_TOKEN: 'JUPYTER_TOKEN' },
|
|
122
|
+
jupyter_token: 'jupyter_token',
|
|
123
|
+
ssh_password: 'ssh_password',
|
|
124
|
+
required_price: 50,
|
|
125
|
+
remember_password: true,
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 11. PoH Info
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const pohBalance = await cloreai.pohBalance()
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### GigaSPOT
|
|
136
|
+
|
|
137
|
+
#### getGigaspot
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const gigaspot = await cloreai.gigaspot.getGigaspot()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### createGigaspotOrders
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { gigaspotBaseImages } from 'cloreai'
|
|
147
|
+
|
|
148
|
+
await cloreai.gigaspot.createGigaspotOrders([
|
|
149
|
+
{
|
|
150
|
+
currency: 'CLORE-Blockchain',
|
|
151
|
+
image: gigaspotBaseImages.UBUNTU, // Use the base image constant
|
|
152
|
+
renting_server: 5941,
|
|
153
|
+
price: 50,
|
|
154
|
+
oc: [
|
|
155
|
+
{
|
|
156
|
+
pl: 150,
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
])
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
#### editGigaspotOrders
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
await cloreai.gigaspot.editGigaspotOrders([
|
|
167
|
+
{
|
|
168
|
+
order_id: 58991,
|
|
169
|
+
price: 50,
|
|
170
|
+
oc: [
|
|
171
|
+
{
|
|
172
|
+
pl: 150,
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
])
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### cancelOrders
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
await cloreai.gigaspot.cancelOrders({
|
|
183
|
+
order_ids: [8383],
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Конфигурация запросов
|
|
188
|
+
|
|
189
|
+
Каждый метод принимает опциональную конфигурацию запроса для axios последним
|
|
190
|
+
параметром, например:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const marketplace = await cloreai.marketplace({
|
|
194
|
+
// axios config
|
|
195
|
+
})
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Доступ к экземпляру axios
|
|
199
|
+
|
|
200
|
+
Используйте поле `cloreai.axios`.
|
|
201
|
+
|
|
202
|
+
Обратитесь к документации [axios](https://github.com/axios/axios).
|
|
203
|
+
|
|
204
|
+
### Доступ к экземплярам p-queue
|
|
205
|
+
|
|
206
|
+
Используйте поля:
|
|
207
|
+
|
|
208
|
+
- `cloreai.queue` - для основной очереди запросов
|
|
209
|
+
- `cloreai.queueCreateOrder` - для очереди запросов createOrder
|
|
210
|
+
- `cloreai.gigaspot.queue` - для очереди запросов gigaspot
|
|
211
|
+
|
|
212
|
+
Обратитесь к документации [p-queue](https://github.com/sindresorhus/p-queue).
|
|
213
|
+
|
|
214
|
+
### Обработка ошибок
|
|
215
|
+
|
|
216
|
+
Библиотека экспортирует следующие виды ошибок:
|
|
217
|
+
|
|
218
|
+
- `DatabaseError`
|
|
219
|
+
- `InvalidInputDataError`
|
|
220
|
+
- `InvalidApiTokenError`
|
|
221
|
+
- `InvalidEndpointError`
|
|
222
|
+
- `ExceededError`
|
|
223
|
+
- `OtherError`
|
|
224
|
+
- `UnknownError`
|
|
225
|
+
|
|
226
|
+
Все эти ошибки наследуются от `AxiosError`.
|
|
227
|
+
|
|
228
|
+
Проверяйте тип ошибки через оператор `instanceof`:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { AxiosError } from 'axios'
|
|
232
|
+
import { ExceededError } from 'cloreai'
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
const marketplace = await cloreai.marketplace()
|
|
236
|
+
} catch (error) {
|
|
237
|
+
if (error instanceof AxiosError) {
|
|
238
|
+
console.log('AxiosError')
|
|
239
|
+
|
|
240
|
+
if (error instanceof ExceededError) {
|
|
241
|
+
console.log('ExceededError')
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
throw error
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Rate limit
|
|
250
|
+
|
|
251
|
+
Все методы защищены от превышения rate limit через
|
|
252
|
+
[p-queue](https://github.com/sindresorhus/p-queue), они автоматически
|
|
253
|
+
задерживаются на нужное время, чтобы избежать превышения лимита.
|
|
254
|
+
|
|
255
|
+
Значения rate limit по умолчанию доступны как константы:
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
import {
|
|
259
|
+
RATE_LIMIT,
|
|
260
|
+
RATE_LIMIT_CREATE_ORDER,
|
|
261
|
+
RATE_LIMIT_GIGASPOT,
|
|
262
|
+
} from 'cloreai'
|
|
263
|
+
|
|
264
|
+
console.log(RATE_LIMIT)
|
|
265
|
+
console.log(RATE_LIMIT_CREATE_ORDER)
|
|
266
|
+
console.log(RATE_LIMIT_GIGASPOT)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Можно задать собственные значение rate limit для каждой очереди запросов:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
import CloreAI from 'cloreai'
|
|
273
|
+
|
|
274
|
+
const cloreai = new CloreAI({
|
|
275
|
+
apiKey: '<API_KEY>',
|
|
276
|
+
queueOptions: {
|
|
277
|
+
interval: 10000, // 10 seconds
|
|
278
|
+
},
|
|
279
|
+
queueOptionsCreateOrder: {
|
|
280
|
+
interval: 10000, // 10 seconds
|
|
281
|
+
},
|
|
282
|
+
queueOptionsGigaspot: {
|
|
283
|
+
interval: 10000, // 10 seconds
|
|
284
|
+
},
|
|
285
|
+
})
|
|
286
|
+
```
|
|
@@ -1,38 +1,34 @@
|
|
|
1
1
|
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
2
|
import PQueue from 'p-queue';
|
|
3
3
|
import type { CancelOrderRequestData, CancelOrderResponseData } from './endpoints/cancelOrder.js';
|
|
4
|
-
import type { CancelOrdersRequestData, CancelOrdersResponseData } from './endpoints/cancelOrders.js';
|
|
5
|
-
import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './endpoints/createGigaspotOrders.js';
|
|
6
4
|
import type { CreateOrderRequestData, CreateOrderResponseData } from './endpoints/createOrder.js';
|
|
7
|
-
import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './endpoints/editGigaspotOrders.js';
|
|
8
|
-
import type { GetGigaspotResponseData } from './endpoints/getGigaspot.js';
|
|
9
5
|
import type { MarketplaceResponseData } from './endpoints/marketplace.js';
|
|
10
6
|
import type { MyOrdersRequestParams, MyOrdersResponseData } from './endpoints/myOrders.js';
|
|
11
7
|
import type { MyServersResponseData } from './endpoints/myServers.js';
|
|
8
|
+
import type { PohBalanceResponseData } from './endpoints/pohBalance.js';
|
|
12
9
|
import type { ServerConfigRequestData, ServerConfigResponseData } from './endpoints/serverConfig.js';
|
|
13
10
|
import type { SetServerSettingsRequestData, SetServerSettingsResponseData } from './endpoints/setServerSettings.js';
|
|
14
11
|
import type { SetSpotPriceRequestData, SetSpotPriceResponseData } from './endpoints/setSpotPrice.js';
|
|
15
12
|
import type { SpotMarketplaceRequestParams, SpotMarketplaceResponseData } from './endpoints/spotMarketplace.js';
|
|
16
13
|
import type { WalletsResponseData } from './endpoints/wallets.js';
|
|
17
14
|
import type { Config } from './types.js';
|
|
15
|
+
import Gigaspot from './Gigaspot.js';
|
|
18
16
|
declare class CloreAI {
|
|
19
17
|
axios: AxiosInstance;
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
queue: PQueue;
|
|
19
|
+
queueCreateOrder: PQueue;
|
|
20
|
+
gigaspot: Gigaspot;
|
|
22
21
|
constructor(config: Config);
|
|
23
22
|
wallets(config?: AxiosRequestConfig): Promise<WalletsResponseData>;
|
|
24
23
|
myServers(config?: AxiosRequestConfig): Promise<MyServersResponseData>;
|
|
25
24
|
serverConfig(data: ServerConfigRequestData, config?: AxiosRequestConfig): Promise<ServerConfigResponseData>;
|
|
26
25
|
marketplace(config?: AxiosRequestConfig): Promise<MarketplaceResponseData>;
|
|
27
|
-
myOrders(params
|
|
26
|
+
myOrders(params?: MyOrdersRequestParams, config?: AxiosRequestConfig): Promise<MyOrdersResponseData>;
|
|
28
27
|
spotMarketplace(params: SpotMarketplaceRequestParams, config?: AxiosRequestConfig): Promise<SpotMarketplaceResponseData>;
|
|
29
28
|
setServerSettings(data: SetServerSettingsRequestData, config?: AxiosRequestConfig): Promise<SetServerSettingsResponseData>;
|
|
30
29
|
setSpotPrice(data: SetSpotPriceRequestData, config?: AxiosRequestConfig): Promise<SetSpotPriceResponseData>;
|
|
31
30
|
cancelOrder(data: CancelOrderRequestData, config?: AxiosRequestConfig): Promise<CancelOrderResponseData>;
|
|
32
31
|
createOrder(data: CreateOrderRequestData, config?: AxiosRequestConfig): Promise<CreateOrderResponseData>;
|
|
33
|
-
|
|
34
|
-
createGigaspotOrders(data: CreateGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<CreateGigaspotOrdersResponseData>;
|
|
35
|
-
editGigaspotOrders(data: EditGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<EditGigaspotOrdersResponseData>;
|
|
36
|
-
cancelOrders(data: CancelOrdersRequestData, config?: AxiosRequestConfig): Promise<CancelOrdersResponseData>;
|
|
32
|
+
pohBalance(config?: AxiosRequestConfig): Promise<PohBalanceResponseData>;
|
|
37
33
|
}
|
|
38
34
|
export default CloreAI;
|
|
@@ -1,27 +1,29 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import PQueue from 'p-queue';
|
|
3
|
-
import {
|
|
4
|
-
import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from '
|
|
5
|
-
import
|
|
3
|
+
import { RATE_LIMIT, RATE_LIMIT_CREATE_ORDER } from './constants.js';
|
|
4
|
+
import { DatabaseError, ExceededError, InvalidApiTokenError, InvalidEndpointError, InvalidInputDataError, OtherError, UnknownError } from './errors.js';
|
|
5
|
+
import Gigaspot from './Gigaspot.js';
|
|
6
|
+
import { getQueueOptions, priorityLevels, statusCodes } from './helpers.js';
|
|
6
7
|
class CloreAI {
|
|
7
8
|
axios;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
queue;
|
|
10
|
+
queueCreateOrder;
|
|
11
|
+
gigaspot;
|
|
10
12
|
constructor(config) {
|
|
11
|
-
this.
|
|
13
|
+
this.queue = new PQueue({
|
|
12
14
|
interval: RATE_LIMIT,
|
|
13
15
|
intervalCap: 1,
|
|
14
16
|
concurrency: 1,
|
|
15
|
-
...config.
|
|
17
|
+
...config.queueOptions,
|
|
16
18
|
});
|
|
17
|
-
this.
|
|
19
|
+
this.queueCreateOrder = new PQueue({
|
|
18
20
|
interval: RATE_LIMIT_CREATE_ORDER,
|
|
19
21
|
intervalCap: 1,
|
|
20
22
|
concurrency: 1,
|
|
21
|
-
...config.
|
|
23
|
+
...config.queueOptionsCreateOrder,
|
|
22
24
|
});
|
|
23
25
|
this.axios = axios.create({
|
|
24
|
-
...config.
|
|
26
|
+
...config.axiosOptions,
|
|
25
27
|
baseURL: 'https://api.clore.ai/v1',
|
|
26
28
|
});
|
|
27
29
|
this.axios.interceptors.request.use((request) => {
|
|
@@ -32,7 +34,9 @@ class CloreAI {
|
|
|
32
34
|
if (response.data.code === statusCodes.NORMAL) {
|
|
33
35
|
return response;
|
|
34
36
|
}
|
|
35
|
-
const errorMessage =
|
|
37
|
+
const errorMessage = response.data.error != null
|
|
38
|
+
? `Code "${response.data.code}", error "${response.data.error}"`
|
|
39
|
+
: `Code "${response.data.code}"`;
|
|
36
40
|
const axiosErrorParameters = [
|
|
37
41
|
errorMessage,
|
|
38
42
|
undefined,
|
|
@@ -57,93 +61,72 @@ class CloreAI {
|
|
|
57
61
|
throw new UnknownError(...axiosErrorParameters);
|
|
58
62
|
}
|
|
59
63
|
});
|
|
64
|
+
this.gigaspot = new Gigaspot(config, this.axios);
|
|
60
65
|
}
|
|
61
66
|
async wallets(config) {
|
|
62
|
-
const response = await this.
|
|
67
|
+
const response = await this.queue.add(async () => {
|
|
63
68
|
return await this.axios.get('/wallets', config);
|
|
64
69
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
65
70
|
return response.data;
|
|
66
71
|
}
|
|
67
72
|
async myServers(config) {
|
|
68
|
-
const response = await this.
|
|
73
|
+
const response = await this.queue.add(async () => {
|
|
69
74
|
return await this.axios.get('/my_servers', config);
|
|
70
75
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
71
76
|
return response.data;
|
|
72
77
|
}
|
|
73
78
|
async serverConfig(data, config) {
|
|
74
|
-
const response = await this.
|
|
79
|
+
const response = await this.queue.add(async () => {
|
|
75
80
|
return await this.axios.get('/server_config', { ...config, data });
|
|
76
81
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
77
82
|
return response.data;
|
|
78
83
|
}
|
|
79
84
|
async marketplace(config) {
|
|
80
|
-
const response = await this.
|
|
85
|
+
const response = await this.queue.add(async () => {
|
|
81
86
|
return await this.axios.get('/marketplace', config);
|
|
82
87
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
83
88
|
return response.data;
|
|
84
89
|
}
|
|
85
90
|
async myOrders(params, config) {
|
|
86
|
-
const response = await this.
|
|
91
|
+
const response = await this.queue.add(async () => {
|
|
87
92
|
return await this.axios.get('/my_orders', { ...config, params });
|
|
88
93
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
89
94
|
return response.data;
|
|
90
95
|
}
|
|
91
96
|
async spotMarketplace(params, config) {
|
|
92
|
-
const response = await this.
|
|
97
|
+
const response = await this.queue.add(async () => {
|
|
93
98
|
return await this.axios.get('/spot_marketplace', { ...config, params });
|
|
94
99
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
95
100
|
return response.data;
|
|
96
101
|
}
|
|
97
102
|
async setServerSettings(data, config) {
|
|
98
|
-
const response = await this.
|
|
103
|
+
const response = await this.queue.add(async () => {
|
|
99
104
|
return await this.axios.post('/set_server_settings', data, config);
|
|
100
105
|
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
101
106
|
return response.data;
|
|
102
107
|
}
|
|
103
108
|
async setSpotPrice(data, config) {
|
|
104
|
-
const response = await this.
|
|
109
|
+
const response = await this.queue.add(async () => {
|
|
105
110
|
return await this.axios.post('/set_spot_price', data, config);
|
|
106
111
|
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
107
112
|
return response.data;
|
|
108
113
|
}
|
|
109
114
|
async cancelOrder(data, config) {
|
|
110
|
-
const response = await this.
|
|
115
|
+
const response = await this.queue.add(async () => {
|
|
111
116
|
return await this.axios.post('/cancel_order', data, config);
|
|
112
117
|
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
113
118
|
return response.data;
|
|
114
119
|
}
|
|
115
120
|
async createOrder(data, config) {
|
|
116
|
-
const response = await this.
|
|
121
|
+
const response = await this.queueCreateOrder.add(async () => {
|
|
117
122
|
return await this.axios.post('/create_order', data, config);
|
|
118
123
|
}, getQueueOptions(priorityLevels.HIGHEST, config));
|
|
119
124
|
return response.data;
|
|
120
125
|
}
|
|
121
|
-
async
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const snapshot = await axios.get(response.data.v1_snapshot_url);
|
|
125
|
-
return {
|
|
126
|
-
...response.data,
|
|
127
|
-
snapshot: snapshot.data,
|
|
128
|
-
};
|
|
126
|
+
async pohBalance(config) {
|
|
127
|
+
const response = await this.queue.add(async () => {
|
|
128
|
+
return await this.axios.get('/poh_balance', config);
|
|
129
129
|
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
130
|
-
}
|
|
131
|
-
async createGigaspotOrders(data, config) {
|
|
132
|
-
const response = await this.rateLimitQueue.add(async () => {
|
|
133
|
-
return await this.axios.post('/create_gigaspot_orders', data, config);
|
|
134
|
-
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
135
|
-
return response.data;
|
|
136
|
-
}
|
|
137
|
-
async editGigaspotOrders(data, config) {
|
|
138
|
-
const response = await this.rateLimitQueue.add(async () => {
|
|
139
|
-
return await this.axios.post('/edit_gigaspot_orders', data, config);
|
|
140
|
-
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
141
|
-
return response.data;
|
|
142
|
-
}
|
|
143
|
-
async cancelOrders(data, config) {
|
|
144
|
-
const response = await this.rateLimitQueue.add(async () => {
|
|
145
|
-
return await this.axios.post('/cancel_orders', data, config);
|
|
146
|
-
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
147
130
|
return response.data;
|
|
148
131
|
}
|
|
149
132
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AxiosInstance, type AxiosRequestConfig } from 'axios';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
3
|
+
import type { CancelOrdersRequestData, CancelOrdersResponseData } from './endpoints/cancelOrders.js';
|
|
4
|
+
import type { CreateGigaspotOrdersRequestData, CreateGigaspotOrdersResponseData } from './endpoints/createGigaspotOrders.js';
|
|
5
|
+
import type { EditGigaspotOrdersRequestData, EditGigaspotOrdersResponseData } from './endpoints/editGigaspotOrders.js';
|
|
6
|
+
import type { GetGigaspotResponseData } from './endpoints/getGigaspot.js';
|
|
7
|
+
import type { Config } from './types.js';
|
|
8
|
+
declare class Gigaspot {
|
|
9
|
+
queue: PQueue;
|
|
10
|
+
private readonly axios;
|
|
11
|
+
constructor(config: Config, axios: AxiosInstance);
|
|
12
|
+
getGigaspot(config?: AxiosRequestConfig): Promise<GetGigaspotResponseData>;
|
|
13
|
+
createGigaspotOrders(data: CreateGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<CreateGigaspotOrdersResponseData>;
|
|
14
|
+
editGigaspotOrders(data: EditGigaspotOrdersRequestData, config?: AxiosRequestConfig): Promise<EditGigaspotOrdersResponseData>;
|
|
15
|
+
cancelOrders(data: CancelOrdersRequestData, config?: AxiosRequestConfig): Promise<CancelOrdersResponseData>;
|
|
16
|
+
}
|
|
17
|
+
export default Gigaspot;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
3
|
+
import { RATE_LIMIT_GIGASPOT } from './constants.js';
|
|
4
|
+
import { getQueueOptions, priorityLevels } from './helpers.js';
|
|
5
|
+
class Gigaspot {
|
|
6
|
+
queue;
|
|
7
|
+
axios;
|
|
8
|
+
constructor(config, axios) {
|
|
9
|
+
this.queue = new PQueue({
|
|
10
|
+
interval: RATE_LIMIT_GIGASPOT,
|
|
11
|
+
intervalCap: 1,
|
|
12
|
+
concurrency: 1,
|
|
13
|
+
...config.queueOptionsGigaspot,
|
|
14
|
+
});
|
|
15
|
+
this.axios = axios;
|
|
16
|
+
}
|
|
17
|
+
async getGigaspot(config) {
|
|
18
|
+
return await this.queue.add(async () => {
|
|
19
|
+
const response = await this.axios.get('/get_gigaspot', config);
|
|
20
|
+
const snapshot = await axios.get(response.data.v1_snapshot_url);
|
|
21
|
+
return {
|
|
22
|
+
...response.data,
|
|
23
|
+
snapshot: snapshot.data,
|
|
24
|
+
};
|
|
25
|
+
}, getQueueOptions(priorityLevels.NORMAL, config));
|
|
26
|
+
}
|
|
27
|
+
async createGigaspotOrders(data, config) {
|
|
28
|
+
const response = await this.queue.add(async () => {
|
|
29
|
+
return await this.axios.post('/create_gigaspot_orders', data, config);
|
|
30
|
+
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
async editGigaspotOrders(data, config) {
|
|
34
|
+
const response = await this.queue.add(async () => {
|
|
35
|
+
return await this.axios.post('/edit_gigaspot_orders', data, config);
|
|
36
|
+
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
37
|
+
return response.data;
|
|
38
|
+
}
|
|
39
|
+
async cancelOrders(data, config) {
|
|
40
|
+
const response = await this.queue.add(async () => {
|
|
41
|
+
return await this.axios.post('/cancel_orders', data, config);
|
|
42
|
+
}, getQueueOptions(priorityLevels.HIGH, config));
|
|
43
|
+
return response.data;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export default Gigaspot;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Currency, OrderType } from '../types.js';
|
|
1
|
+
import type { Currency, OrderType, ResponseData } from '../types.js';
|
|
2
2
|
export interface CreateOrderRequestDataBase {
|
|
3
3
|
type: OrderType;
|
|
4
4
|
currency: Currency;
|
|
@@ -22,4 +22,5 @@ export interface CreateOrderRequestDataSpot extends CreateOrderRequestDataBase {
|
|
|
22
22
|
type: 'spot';
|
|
23
23
|
spotprice: number;
|
|
24
24
|
}
|
|
25
|
-
export type
|
|
25
|
+
export type CreateOrderRequestData = CreateOrderRequestDataOnDemand | CreateOrderRequestDataSpot;
|
|
26
|
+
export type CreateOrderResponseData = ResponseData;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Currency, Pricing } from '
|
|
2
|
-
import type { ResponseData } from '../types.js';
|
|
1
|
+
import type { Currency, Pricing, ResponseData } from '../types.js';
|
|
3
2
|
export interface GetGigaspotResponseDataSnapshotServerBid {
|
|
4
3
|
owner: number;
|
|
5
4
|
id: number;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Currency, Price, ResponseData, Specs } from '../types.js';
|
|
2
|
+
export interface MarketplaceResponseDataServerRating {
|
|
3
|
+
avg: number;
|
|
4
|
+
cnt: number;
|
|
5
|
+
}
|
|
6
|
+
export interface MarketplaceResponseDataServer {
|
|
7
|
+
id: number;
|
|
8
|
+
owner: number;
|
|
9
|
+
mrl: number;
|
|
10
|
+
price: Price;
|
|
11
|
+
rented: boolean;
|
|
12
|
+
specs: Specs;
|
|
13
|
+
reliability: number;
|
|
14
|
+
allowed_coins: Currency[];
|
|
15
|
+
rating: MarketplaceResponseDataServerRating;
|
|
16
|
+
gpu_array: string[];
|
|
17
|
+
gigaspot: boolean;
|
|
18
|
+
oc?: boolean;
|
|
19
|
+
cuda_version: string;
|
|
20
|
+
}
|
|
21
|
+
export interface MarketplaceResponseData extends ResponseData {
|
|
22
|
+
servers: MarketplaceResponseDataServer[];
|
|
23
|
+
my_servers: number[];
|
|
24
|
+
}
|