topstepx-api 1.0.3 → 2.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/CHANGELOG.md +145 -0
- package/MIGRATION.md +515 -0
- package/README.md +143 -38
- package/dist/index.cjs +599 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +346 -197
- package/dist/index.d.ts +346 -197
- package/dist/index.js +593 -85
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -41,12 +41,12 @@ const client = new TopstepXClient({
|
|
|
41
41
|
await client.connect();
|
|
42
42
|
|
|
43
43
|
// Get accounts
|
|
44
|
-
const
|
|
45
|
-
console.log('Accounts:', accounts);
|
|
44
|
+
const response = await client.accounts.search({ onlyActiveAccounts: true });
|
|
45
|
+
console.log('Accounts:', response.accounts);
|
|
46
46
|
|
|
47
47
|
// Place a market order
|
|
48
48
|
const order = await client.orders.place({
|
|
49
|
-
accountId: accounts[0].id,
|
|
49
|
+
accountId: response.accounts[0].id,
|
|
50
50
|
contractId: 'CON.F.US.ENQ.M25',
|
|
51
51
|
type: OrderType.Market,
|
|
52
52
|
side: OrderSide.Buy,
|
|
@@ -106,11 +106,18 @@ Access via `client.accounts`
|
|
|
106
106
|
Search for accounts.
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
|
-
const
|
|
109
|
+
const response = await client.accounts.search({
|
|
110
110
|
onlyActiveAccounts: boolean;
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
// Returns:
|
|
113
|
+
// Returns: SearchAccountsResponse
|
|
114
|
+
interface SearchAccountsResponse {
|
|
115
|
+
accounts: Account[];
|
|
116
|
+
success: boolean;
|
|
117
|
+
errorCode: number;
|
|
118
|
+
errorMessage: string | null;
|
|
119
|
+
}
|
|
120
|
+
|
|
114
121
|
interface Account {
|
|
115
122
|
id: number;
|
|
116
123
|
name: string;
|
|
@@ -145,7 +152,13 @@ const result = await client.orders.place({
|
|
|
145
152
|
linkedOrderId?: number; // Optional linked order (OCO)
|
|
146
153
|
});
|
|
147
154
|
|
|
148
|
-
// Returns:
|
|
155
|
+
// Returns: PlaceOrderResponse
|
|
156
|
+
interface PlaceOrderResponse {
|
|
157
|
+
orderId: number;
|
|
158
|
+
success: boolean;
|
|
159
|
+
errorCode: number;
|
|
160
|
+
errorMessage: string | null;
|
|
161
|
+
}
|
|
149
162
|
```
|
|
150
163
|
|
|
151
164
|
#### cancel
|
|
@@ -153,10 +166,17 @@ const result = await client.orders.place({
|
|
|
153
166
|
Cancel an existing order.
|
|
154
167
|
|
|
155
168
|
```typescript
|
|
156
|
-
await client.orders.cancel({
|
|
169
|
+
const response = await client.orders.cancel({
|
|
157
170
|
accountId: number;
|
|
158
171
|
orderId: number;
|
|
159
172
|
});
|
|
173
|
+
|
|
174
|
+
// Returns: CancelOrderResponse
|
|
175
|
+
interface CancelOrderResponse {
|
|
176
|
+
success: boolean;
|
|
177
|
+
errorCode: number;
|
|
178
|
+
errorMessage: string | null;
|
|
179
|
+
}
|
|
160
180
|
```
|
|
161
181
|
|
|
162
182
|
#### modify
|
|
@@ -164,7 +184,7 @@ await client.orders.cancel({
|
|
|
164
184
|
Modify an existing order.
|
|
165
185
|
|
|
166
186
|
```typescript
|
|
167
|
-
await client.orders.modify({
|
|
187
|
+
const response = await client.orders.modify({
|
|
168
188
|
accountId: number;
|
|
169
189
|
orderId: number;
|
|
170
190
|
size?: number;
|
|
@@ -172,6 +192,13 @@ await client.orders.modify({
|
|
|
172
192
|
stopPrice?: number;
|
|
173
193
|
trailPrice?: number;
|
|
174
194
|
});
|
|
195
|
+
|
|
196
|
+
// Returns: ModifyOrderResponse
|
|
197
|
+
interface ModifyOrderResponse {
|
|
198
|
+
success: boolean;
|
|
199
|
+
errorCode: number;
|
|
200
|
+
errorMessage: string | null;
|
|
201
|
+
}
|
|
175
202
|
```
|
|
176
203
|
|
|
177
204
|
#### search
|
|
@@ -179,13 +206,20 @@ await client.orders.modify({
|
|
|
179
206
|
Search historical orders.
|
|
180
207
|
|
|
181
208
|
```typescript
|
|
182
|
-
const
|
|
209
|
+
const response = await client.orders.search({
|
|
183
210
|
accountId: number;
|
|
184
211
|
startTimestamp?: string; // ISO 8601 format
|
|
185
212
|
endTimestamp?: string;
|
|
186
213
|
});
|
|
187
214
|
|
|
188
|
-
// Returns:
|
|
215
|
+
// Returns: SearchOrdersResponse
|
|
216
|
+
interface SearchOrdersResponse {
|
|
217
|
+
orders: Order[];
|
|
218
|
+
success: boolean;
|
|
219
|
+
errorCode: number;
|
|
220
|
+
errorMessage: string | null;
|
|
221
|
+
}
|
|
222
|
+
|
|
189
223
|
interface Order {
|
|
190
224
|
id: number;
|
|
191
225
|
accountId: number;
|
|
@@ -206,9 +240,17 @@ interface Order {
|
|
|
206
240
|
Get currently open orders.
|
|
207
241
|
|
|
208
242
|
```typescript
|
|
209
|
-
const
|
|
243
|
+
const response = await client.orders.searchOpen({
|
|
210
244
|
accountId: number;
|
|
211
245
|
});
|
|
246
|
+
|
|
247
|
+
// Returns: SearchOpenOrdersResponse
|
|
248
|
+
interface SearchOpenOrdersResponse {
|
|
249
|
+
orders: Order[];
|
|
250
|
+
success: boolean;
|
|
251
|
+
errorCode: number;
|
|
252
|
+
errorMessage: string | null;
|
|
253
|
+
}
|
|
212
254
|
```
|
|
213
255
|
|
|
214
256
|
---
|
|
@@ -222,11 +264,18 @@ Access via `client.positions`
|
|
|
222
264
|
Get open positions.
|
|
223
265
|
|
|
224
266
|
```typescript
|
|
225
|
-
const
|
|
267
|
+
const response = await client.positions.searchOpen({
|
|
226
268
|
accountId: number;
|
|
227
269
|
});
|
|
228
270
|
|
|
229
|
-
// Returns:
|
|
271
|
+
// Returns: SearchOpenPositionsResponse
|
|
272
|
+
interface SearchOpenPositionsResponse {
|
|
273
|
+
positions: Position[];
|
|
274
|
+
success: boolean;
|
|
275
|
+
errorCode: number;
|
|
276
|
+
errorMessage: string | null;
|
|
277
|
+
}
|
|
278
|
+
|
|
230
279
|
interface Position {
|
|
231
280
|
id: number;
|
|
232
281
|
accountId: number;
|
|
@@ -243,10 +292,17 @@ interface Position {
|
|
|
243
292
|
Close a position entirely.
|
|
244
293
|
|
|
245
294
|
```typescript
|
|
246
|
-
await client.positions.close({
|
|
295
|
+
const response = await client.positions.close({
|
|
247
296
|
accountId: number;
|
|
248
297
|
contractId: string;
|
|
249
298
|
});
|
|
299
|
+
|
|
300
|
+
// Returns: ClosePositionResponse
|
|
301
|
+
interface ClosePositionResponse {
|
|
302
|
+
success: boolean;
|
|
303
|
+
errorCode: number;
|
|
304
|
+
errorMessage: string | null;
|
|
305
|
+
}
|
|
250
306
|
```
|
|
251
307
|
|
|
252
308
|
#### partialClose
|
|
@@ -254,11 +310,18 @@ await client.positions.close({
|
|
|
254
310
|
Partially close a position.
|
|
255
311
|
|
|
256
312
|
```typescript
|
|
257
|
-
await client.positions.partialClose({
|
|
313
|
+
const response = await client.positions.partialClose({
|
|
258
314
|
accountId: number;
|
|
259
315
|
contractId: string;
|
|
260
316
|
size: number; // Number of contracts to close
|
|
261
317
|
});
|
|
318
|
+
|
|
319
|
+
// Returns: PartialClosePositionResponse
|
|
320
|
+
interface PartialClosePositionResponse {
|
|
321
|
+
success: boolean;
|
|
322
|
+
errorCode: number;
|
|
323
|
+
errorMessage: string | null;
|
|
324
|
+
}
|
|
262
325
|
```
|
|
263
326
|
|
|
264
327
|
---
|
|
@@ -272,13 +335,20 @@ Access via `client.trades`
|
|
|
272
335
|
Search trade history.
|
|
273
336
|
|
|
274
337
|
```typescript
|
|
275
|
-
const
|
|
338
|
+
const response = await client.trades.search({
|
|
276
339
|
accountId: number;
|
|
277
340
|
startTimestamp: string; // ISO 8601 format
|
|
278
341
|
endTimestamp: string;
|
|
279
342
|
});
|
|
280
343
|
|
|
281
|
-
// Returns:
|
|
344
|
+
// Returns: SearchTradesResponse
|
|
345
|
+
interface SearchTradesResponse {
|
|
346
|
+
trades: Trade[];
|
|
347
|
+
success: boolean;
|
|
348
|
+
errorCode: number;
|
|
349
|
+
errorMessage: string | null;
|
|
350
|
+
}
|
|
351
|
+
|
|
282
352
|
interface Trade {
|
|
283
353
|
id: number;
|
|
284
354
|
accountId: number;
|
|
@@ -305,12 +375,19 @@ Access via `client.contracts`
|
|
|
305
375
|
Search for contracts/symbols.
|
|
306
376
|
|
|
307
377
|
```typescript
|
|
308
|
-
const
|
|
378
|
+
const response = await client.contracts.search({
|
|
309
379
|
searchText: string; // e.g., "ES", "NQ", "CL"
|
|
310
380
|
live: boolean; // true for live, false for sim
|
|
311
381
|
});
|
|
312
382
|
|
|
313
|
-
// Returns:
|
|
383
|
+
// Returns: SearchContractsResponse
|
|
384
|
+
interface SearchContractsResponse {
|
|
385
|
+
contracts: Contract[];
|
|
386
|
+
success: boolean;
|
|
387
|
+
errorCode: number;
|
|
388
|
+
errorMessage: string | null;
|
|
389
|
+
}
|
|
390
|
+
|
|
314
391
|
interface Contract {
|
|
315
392
|
id: string;
|
|
316
393
|
name: string;
|
|
@@ -326,12 +403,18 @@ interface Contract {
|
|
|
326
403
|
Get a specific contract by ID.
|
|
327
404
|
|
|
328
405
|
```typescript
|
|
329
|
-
const
|
|
406
|
+
const response = await client.contracts.searchById({
|
|
330
407
|
contractId: string; // e.g., "CON.F.US.ENQ.M25"
|
|
331
408
|
live: boolean;
|
|
332
409
|
});
|
|
333
410
|
|
|
334
|
-
// Returns:
|
|
411
|
+
// Returns: SearchContractByIdResponse
|
|
412
|
+
interface SearchContractByIdResponse {
|
|
413
|
+
contract: Contract | null;
|
|
414
|
+
success: boolean;
|
|
415
|
+
errorCode: number;
|
|
416
|
+
errorMessage: string | null;
|
|
417
|
+
}
|
|
335
418
|
```
|
|
336
419
|
|
|
337
420
|
---
|
|
@@ -347,7 +430,7 @@ Get historical OHLCV bars.
|
|
|
347
430
|
```typescript
|
|
348
431
|
import { BarUnit } from 'topstepx-api';
|
|
349
432
|
|
|
350
|
-
const
|
|
433
|
+
const response = await client.history.retrieveBars({
|
|
351
434
|
contractId: string;
|
|
352
435
|
live: boolean;
|
|
353
436
|
startTime: string; // ISO 8601 format
|
|
@@ -358,7 +441,14 @@ const bars = await client.history.retrieveBars({
|
|
|
358
441
|
includePartialBar: boolean;
|
|
359
442
|
});
|
|
360
443
|
|
|
361
|
-
// Returns:
|
|
444
|
+
// Returns: RetrieveBarsResponse
|
|
445
|
+
interface RetrieveBarsResponse {
|
|
446
|
+
bars: Bar[];
|
|
447
|
+
success: boolean;
|
|
448
|
+
errorCode: number;
|
|
449
|
+
errorMessage: string | null;
|
|
450
|
+
}
|
|
451
|
+
|
|
362
452
|
interface Bar {
|
|
363
453
|
t: string; // timestamp
|
|
364
454
|
o: number; // open
|
|
@@ -428,7 +518,7 @@ client.marketHub.on('depth', ({ contractId, data }) => {
|
|
|
428
518
|
#### Event Types
|
|
429
519
|
|
|
430
520
|
```typescript
|
|
431
|
-
interface
|
|
521
|
+
interface MarketQuote {
|
|
432
522
|
symbol: string;
|
|
433
523
|
lastPrice: number;
|
|
434
524
|
bestBid: number;
|
|
@@ -612,23 +702,23 @@ async function main() {
|
|
|
612
702
|
console.log('Connected to TopstepX');
|
|
613
703
|
|
|
614
704
|
// Get accounts
|
|
615
|
-
const
|
|
616
|
-
const account = accounts[0];
|
|
705
|
+
const accountsResponse = await client.accounts.search({ onlyActiveAccounts: true });
|
|
706
|
+
const account = accountsResponse.accounts[0];
|
|
617
707
|
console.log(`Using account: ${account.name} (${account.id})`);
|
|
618
708
|
|
|
619
709
|
// Search for ES contract
|
|
620
|
-
const
|
|
710
|
+
const contractsResponse = await client.contracts.search({
|
|
621
711
|
searchText: 'ES',
|
|
622
712
|
live: false,
|
|
623
713
|
});
|
|
624
|
-
const esContract = contracts.find(c => c.activeContract);
|
|
714
|
+
const esContract = contractsResponse.contracts.find(c => c.activeContract);
|
|
625
715
|
console.log(`Found contract: ${esContract?.id}`);
|
|
626
716
|
|
|
627
717
|
// Get historical data
|
|
628
718
|
const endTime = new Date();
|
|
629
719
|
const startTime = new Date(endTime.getTime() - 24 * 60 * 60 * 1000);
|
|
630
720
|
|
|
631
|
-
const
|
|
721
|
+
const barsResponse = await client.history.retrieveBars({
|
|
632
722
|
contractId: esContract!.id,
|
|
633
723
|
live: false,
|
|
634
724
|
startTime: startTime.toISOString(),
|
|
@@ -638,7 +728,7 @@ async function main() {
|
|
|
638
728
|
limit: 24,
|
|
639
729
|
includePartialBar: false,
|
|
640
730
|
});
|
|
641
|
-
console.log(`Retrieved ${bars.length} hourly bars`);
|
|
731
|
+
console.log(`Retrieved ${barsResponse.bars.length} hourly bars`);
|
|
642
732
|
|
|
643
733
|
// Subscribe to real-time quotes
|
|
644
734
|
client.marketHub.on('quote', ({ contractId, data }) => {
|
|
@@ -660,13 +750,13 @@ async function main() {
|
|
|
660
750
|
type: OrderType.Limit,
|
|
661
751
|
side: OrderSide.Buy,
|
|
662
752
|
size: 1,
|
|
663
|
-
limitPrice: bars[bars.length - 1].c - 10, // 10 points below last close
|
|
753
|
+
limitPrice: barsResponse.bars[barsResponse.bars.length - 1].c - 10, // 10 points below last close
|
|
664
754
|
});
|
|
665
755
|
console.log(`Placed order: ${order.orderId}`);
|
|
666
756
|
|
|
667
757
|
// Check open orders
|
|
668
|
-
const
|
|
669
|
-
console.log(`Open orders: ${
|
|
758
|
+
const openOrdersResponse = await client.orders.searchOpen({ accountId: account.id });
|
|
759
|
+
console.log(`Open orders: ${openOrdersResponse.orders.length}`);
|
|
670
760
|
|
|
671
761
|
// Cancel the order
|
|
672
762
|
await client.orders.cancel({
|
|
@@ -705,7 +795,7 @@ import type {
|
|
|
705
795
|
TopstepXClientConfig,
|
|
706
796
|
TopstepXClientEvents,
|
|
707
797
|
|
|
708
|
-
// REST
|
|
798
|
+
// REST shared
|
|
709
799
|
Account,
|
|
710
800
|
Order,
|
|
711
801
|
Position,
|
|
@@ -713,14 +803,29 @@ import type {
|
|
|
713
803
|
Contract,
|
|
714
804
|
Bar,
|
|
715
805
|
|
|
716
|
-
//
|
|
806
|
+
// Response shared
|
|
807
|
+
SearchAccountsResponse,
|
|
808
|
+
PlaceOrderResponse,
|
|
809
|
+
CancelOrderResponse,
|
|
810
|
+
ModifyOrderResponse,
|
|
811
|
+
SearchOrdersResponse,
|
|
812
|
+
SearchOpenOrdersResponse,
|
|
813
|
+
SearchOpenPositionsResponse,
|
|
814
|
+
ClosePositionResponse,
|
|
815
|
+
PartialClosePositionResponse,
|
|
816
|
+
SearchTradesResponse,
|
|
817
|
+
SearchContractsResponse,
|
|
818
|
+
SearchContractByIdResponse,
|
|
819
|
+
RetrieveBarsResponse,
|
|
820
|
+
|
|
821
|
+
// Request shared
|
|
717
822
|
PlaceOrderRequest,
|
|
718
823
|
ModifyOrderRequest,
|
|
719
|
-
|
|
824
|
+
SearchOrdersRequestInterface,
|
|
720
825
|
RetrieveBarsRequest,
|
|
721
826
|
|
|
722
|
-
// WebSocket
|
|
723
|
-
|
|
827
|
+
// WebSocket shared
|
|
828
|
+
MarketQuote,
|
|
724
829
|
MarketTrade,
|
|
725
830
|
MarketDepth,
|
|
726
831
|
OrderUpdate,
|