Skip to content

Commit ec3eb9c

Browse files
committed
Update readme documentation to reflect new API response structures.
1 parent dc57a13 commit ec3eb9c

1 file changed

Lines changed: 139 additions & 34 deletions

File tree

README.md

Lines changed: 139 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const client = new TopstepXClient({
4141
await client.connect();
4242

4343
// Get accounts
44-
const accounts = await client.accounts.search({ onlyActiveAccounts: true });
45-
console.log('Accounts:', accounts);
44+
const response = await client.accounts.search({ onlyActiveAccounts: true });
45+
console.log('Accounts:', response.accounts);
4646

4747
// Place a market order
4848
const order = await client.orders.place({
49-
accountId: accounts[0].id,
49+
accountId: response.accounts[0].id,
5050
contractId: 'CON.F.US.ENQ.M25',
5151
type: OrderType.Market,
5252
side: OrderSide.Buy,
@@ -106,11 +106,18 @@ Access via `client.accounts`
106106
Search for accounts.
107107

108108
```typescript
109-
const accounts = await client.accounts.search({
109+
const response = await client.accounts.search({
110110
onlyActiveAccounts: boolean;
111111
});
112112

113-
// Returns: Account[]
113+
// Returns: SearchAccountsResponse
114+
interface SearchAccountsResponse {
115+
accounts: Account[];
116+
success: boolean;
117+
errorCode: number;
118+
errorMessage: string | null;
119+
}
120+
114121
interface Account {
115122
id: number;
116123
name: string;
@@ -145,47 +152,74 @@ const result = await client.orders.place({
145152
linkedOrderId?: number; // Optional linked order (OCO)
146153
});
147154

148-
// Returns: { orderId: number, success: boolean, ... }
155+
// Returns: PlaceOrderResponse
156+
interface PlaceOrderResponse {
157+
orderId: number;
158+
success: boolean;
159+
errorCode: number;
160+
errorMessage: string | null;
161+
}
149162
```
150163

151164
#### cancel
152165

153166
Cancel an existing order.
154167

155168
```typescript
156-
await client.orders.cancel({
169+
const response = await client.orders.cancel({
157170
accountId: number;
158171
orderId: number;
159172
});
173+
174+
// Returns: CancelOrderResponse
175+
interface CancelOrderResponse {
176+
success: boolean;
177+
errorCode: number;
178+
errorMessage: string | null;
179+
}
160180
```
161181

162182
#### modify
163183

164184
Modify an existing order.
165185

166186
```typescript
167-
await client.orders.modify({
187+
const response = await client.orders.modify({
168188
accountId: number;
169189
orderId: number;
170190
size?: number;
171191
limitPrice?: number;
172192
stopPrice?: number;
173193
trailPrice?: number;
174194
});
195+
196+
// Returns: ModifyOrderResponse
197+
interface ModifyOrderResponse {
198+
success: boolean;
199+
errorCode: number;
200+
errorMessage: string | null;
201+
}
175202
```
176203

177204
#### search
178205

179206
Search historical orders.
180207

181208
```typescript
182-
const orders = await client.orders.search({
209+
const response = await client.orders.search({
183210
accountId: number;
184211
startTimestamp?: string; // ISO 8601 format
185212
endTimestamp?: string;
186213
});
187214

188-
// Returns: Order[]
215+
// Returns: SearchOrdersResponse
216+
interface SearchOrdersResponse {
217+
orders: Order[];
218+
success: boolean;
219+
errorCode: number;
220+
errorMessage: string | null;
221+
}
222+
189223
interface Order {
190224
id: number;
191225
accountId: number;
@@ -206,9 +240,17 @@ interface Order {
206240
Get currently open orders.
207241

208242
```typescript
209-
const openOrders = await client.orders.searchOpen({
243+
const response = await client.orders.searchOpen({
210244
accountId: number;
211245
});
246+
247+
// Returns: SearchOpenOrdersResponse
248+
interface SearchOpenOrdersResponse {
249+
orders: Order[];
250+
success: boolean;
251+
errorCode: number;
252+
errorMessage: string | null;
253+
}
212254
```
213255

214256
---
@@ -222,11 +264,18 @@ Access via `client.positions`
222264
Get open positions.
223265

224266
```typescript
225-
const positions = await client.positions.searchOpen({
267+
const response = await client.positions.searchOpen({
226268
accountId: number;
227269
});
228270

229-
// Returns: Position[]
271+
// Returns: SearchOpenPositionsResponse
272+
interface SearchOpenPositionsResponse {
273+
positions: Position[];
274+
success: boolean;
275+
errorCode: number;
276+
errorMessage: string | null;
277+
}
278+
230279
interface Position {
231280
id: number;
232281
accountId: number;
@@ -243,22 +292,36 @@ interface Position {
243292
Close a position entirely.
244293

245294
```typescript
246-
await client.positions.close({
295+
const response = await client.positions.close({
247296
accountId: number;
248297
contractId: string;
249298
});
299+
300+
// Returns: ClosePositionResponse
301+
interface ClosePositionResponse {
302+
success: boolean;
303+
errorCode: number;
304+
errorMessage: string | null;
305+
}
250306
```
251307

252308
#### partialClose
253309

254310
Partially close a position.
255311

256312
```typescript
257-
await client.positions.partialClose({
313+
const response = await client.positions.partialClose({
258314
accountId: number;
259315
contractId: string;
260316
size: number; // Number of contracts to close
261317
});
318+
319+
// Returns: PartialClosePositionResponse
320+
interface PartialClosePositionResponse {
321+
success: boolean;
322+
errorCode: number;
323+
errorMessage: string | null;
324+
}
262325
```
263326

264327
---
@@ -272,13 +335,20 @@ Access via `client.trades`
272335
Search trade history.
273336

274337
```typescript
275-
const trades = await client.trades.search({
338+
const response = await client.trades.search({
276339
accountId: number;
277340
startTimestamp: string; // ISO 8601 format
278341
endTimestamp: string;
279342
});
280343

281-
// Returns: Trade[]
344+
// Returns: SearchTradesResponse
345+
interface SearchTradesResponse {
346+
trades: Trade[];
347+
success: boolean;
348+
errorCode: number;
349+
errorMessage: string | null;
350+
}
351+
282352
interface Trade {
283353
id: number;
284354
accountId: number;
@@ -305,12 +375,19 @@ Access via `client.contracts`
305375
Search for contracts/symbols.
306376

307377
```typescript
308-
const contracts = await client.contracts.search({
378+
const response = await client.contracts.search({
309379
searchText: string; // e.g., "ES", "NQ", "CL"
310380
live: boolean; // true for live, false for sim
311381
});
312382

313-
// Returns: Contract[]
383+
// Returns: SearchContractsResponse
384+
interface SearchContractsResponse {
385+
contracts: Contract[];
386+
success: boolean;
387+
errorCode: number;
388+
errorMessage: string | null;
389+
}
390+
314391
interface Contract {
315392
id: string;
316393
name: string;
@@ -326,12 +403,18 @@ interface Contract {
326403
Get a specific contract by ID.
327404

328405
```typescript
329-
const contract = await client.contracts.searchById({
406+
const response = await client.contracts.searchById({
330407
contractId: string; // e.g., "CON.F.US.ENQ.M25"
331408
live: boolean;
332409
});
333410

334-
// Returns: Contract | null
411+
// Returns: SearchContractByIdResponse
412+
interface SearchContractByIdResponse {
413+
contract: Contract | null;
414+
success: boolean;
415+
errorCode: number;
416+
errorMessage: string | null;
417+
}
335418
```
336419

337420
---
@@ -347,7 +430,7 @@ Get historical OHLCV bars.
347430
```typescript
348431
import { BarUnit } from 'topstepx-api';
349432

350-
const bars = await client.history.retrieveBars({
433+
const response = await client.history.retrieveBars({
351434
contractId: string;
352435
live: boolean;
353436
startTime: string; // ISO 8601 format
@@ -358,7 +441,14 @@ const bars = await client.history.retrieveBars({
358441
includePartialBar: boolean;
359442
});
360443

361-
// Returns: Bar[]
444+
// Returns: RetrieveBarsResponse
445+
interface RetrieveBarsResponse {
446+
bars: Bar[];
447+
success: boolean;
448+
errorCode: number;
449+
errorMessage: string | null;
450+
}
451+
362452
interface Bar {
363453
t: string; // timestamp
364454
o: number; // open
@@ -428,7 +518,7 @@ client.marketHub.on('depth', ({ contractId, data }) => {
428518
#### Event Types
429519

430520
```typescript
431-
interface Quote {
521+
interface MarketQuote {
432522
symbol: string;
433523
lastPrice: number;
434524
bestBid: number;
@@ -612,23 +702,23 @@ async function main() {
612702
console.log('Connected to TopstepX');
613703

614704
// Get accounts
615-
const accounts = await client.accounts.search({ onlyActiveAccounts: true });
616-
const account = accounts[0];
705+
const accountsResponse = await client.accounts.search({ onlyActiveAccounts: true });
706+
const account = accountsResponse.accounts[0];
617707
console.log(`Using account: ${account.name} (${account.id})`);
618708

619709
// Search for ES contract
620-
const contracts = await client.contracts.search({
710+
const contractsResponse = await client.contracts.search({
621711
searchText: 'ES',
622712
live: false,
623713
});
624-
const esContract = contracts.find(c => c.activeContract);
714+
const esContract = contractsResponse.contracts.find(c => c.activeContract);
625715
console.log(`Found contract: ${esContract?.id}`);
626716

627717
// Get historical data
628718
const endTime = new Date();
629719
const startTime = new Date(endTime.getTime() - 24 * 60 * 60 * 1000);
630720

631-
const bars = await client.history.retrieveBars({
721+
const barsResponse = await client.history.retrieveBars({
632722
contractId: esContract!.id,
633723
live: false,
634724
startTime: startTime.toISOString(),
@@ -638,7 +728,7 @@ async function main() {
638728
limit: 24,
639729
includePartialBar: false,
640730
});
641-
console.log(`Retrieved ${bars.length} hourly bars`);
731+
console.log(`Retrieved ${barsResponse.bars.length} hourly bars`);
642732

643733
// Subscribe to real-time quotes
644734
client.marketHub.on('quote', ({ contractId, data }) => {
@@ -660,13 +750,13 @@ async function main() {
660750
type: OrderType.Limit,
661751
side: OrderSide.Buy,
662752
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
664754
});
665755
console.log(`Placed order: ${order.orderId}`);
666756

667757
// Check open orders
668-
const openOrders = await client.orders.searchOpen({ accountId: account.id });
669-
console.log(`Open orders: ${openOrders.length}`);
758+
const openOrdersResponse = await client.orders.searchOpen({ accountId: account.id });
759+
console.log(`Open orders: ${openOrdersResponse.orders.length}`);
670760

671761
// Cancel the order
672762
await client.orders.cancel({
@@ -713,14 +803,29 @@ import type {
713803
Contract,
714804
Bar,
715805

806+
// Response types
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+
716821
// Request types
717822
PlaceOrderRequest,
718823
ModifyOrderRequest,
719824
SearchOrdersRequest,
720825
RetrieveBarsRequest,
721826

722827
// WebSocket types
723-
Quote,
828+
MarketQuote,
724829
MarketTrade,
725830
MarketDepth,
726831
OrderUpdate,

0 commit comments

Comments
 (0)