@huskly/schwab-client 0.1.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 ADDED
@@ -0,0 +1,269 @@
1
+ # @huskly/schwab-client
2
+
3
+ A TypeScript client library for the Schwab Market Data and Trading API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @huskly/schwab-client
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - Node.js >= 20.0.0
14
+ - A valid Schwab API access token
15
+
16
+ ## Usage
17
+
18
+ ```typescript
19
+ import { SchwabClient } from '@huskly/schwab-client';
20
+
21
+ const client = new SchwabClient('your-access-token');
22
+ ```
23
+
24
+ ### Market Data
25
+
26
+ #### Get Quotes
27
+
28
+ ```typescript
29
+ const quotes = await client.getQuotes(['AAPL', 'GOOGL', 'MSFT']);
30
+ console.log(quotes['AAPL'].quote.lastPrice);
31
+ ```
32
+
33
+ #### Get Price History
34
+
35
+ ```typescript
36
+ // Last 30 days
37
+ const history = await client.getPriceHistory({ symbol: 'AAPL', days: 30 });
38
+
39
+ // Custom date range
40
+ const history = await client.getPriceHistory({
41
+ symbol: 'AAPL',
42
+ startDate: Date.parse('2024-01-01'),
43
+ endDate: Date.now(),
44
+ });
45
+ ```
46
+
47
+ #### Get VIX Level
48
+
49
+ ```typescript
50
+ const vix = await client.getVixLevel();
51
+ console.log(`VIX: ${vix}`);
52
+ ```
53
+
54
+ #### Search Instruments
55
+
56
+ ```typescript
57
+ const results = await client.searchInstruments('AAPL', 'symbol-search');
58
+ ```
59
+
60
+ #### Get Market Movers
61
+
62
+ ```typescript
63
+ const movers = await client.getMovers('$SPX', 'PERCENT_CHANGE_UP');
64
+ console.log(movers.screeners);
65
+ ```
66
+
67
+ ### Options
68
+
69
+ #### Get Available Expiries
70
+
71
+ ```typescript
72
+ const expiries = await client.getAvailableExpiries(
73
+ 'SPY',
74
+ 'CALL',
75
+ '2025-01-01',
76
+ '2025-06-30'
77
+ );
78
+ ```
79
+
80
+ #### Get Option Chain
81
+
82
+ ```typescript
83
+ const chain = await client.getOptionChain('SPY', new Date('2025-01-17'));
84
+ for (const option of chain) {
85
+ console.log(`${option.symbol}: ${option.strike} ${option.isCall ? 'C' : 'P'} @ ${option.mid}`);
86
+ }
87
+ ```
88
+
89
+ #### Get Single Option Quote
90
+
91
+ ```typescript
92
+ const option = await client.getOptionQuote({
93
+ symbol: 'SPY',
94
+ expiry: new Date('2025-01-17'),
95
+ strike: 600,
96
+ type: 'call',
97
+ });
98
+ ```
99
+
100
+ ### Account
101
+
102
+ #### Get Account Balances
103
+
104
+ ```typescript
105
+ const balances = await client.getAccountBalances();
106
+ console.log(`Equity: $${balances.equity}`);
107
+ console.log(`Buying Power: $${balances.buyingPower}`);
108
+ console.log(`Cash: $${balances.cashBalance}`);
109
+ ```
110
+
111
+ #### Get Positions
112
+
113
+ ```typescript
114
+ // All positions
115
+ const positions = await client.getPositions();
116
+
117
+ // Filter by symbol
118
+ const applePositions = await client.getPositions('AAPL');
119
+ ```
120
+
121
+ #### Get Account Numbers
122
+
123
+ ```typescript
124
+ const accounts = await client.fetchAccountNumbers();
125
+ for (const account of accounts) {
126
+ console.log(`Account: ${account.accountNumber}, Hash: ${account.hashValue}`);
127
+ }
128
+ ```
129
+
130
+ #### Get Transaction History
131
+
132
+ ```typescript
133
+ const history = await client.fetchTransactionHistory(
134
+ new Date('2024-01-01'),
135
+ new Date()
136
+ );
137
+ ```
138
+
139
+ #### Get User Preferences
140
+
141
+ ```typescript
142
+ const prefs = await client.getUserPreference();
143
+ console.log(prefs.streamerInfo.streamerSocketUrl);
144
+ ```
145
+
146
+ ### Orders
147
+
148
+ #### Fetch Orders
149
+
150
+ ```typescript
151
+ const orders = await client.fetchOrders({
152
+ fromEnteredTime: new Date('2024-01-01'),
153
+ toEnteredTime: new Date(),
154
+ status: 'FILLED', // Optional filter
155
+ maxResults: 100, // Optional limit
156
+ });
157
+ ```
158
+
159
+ #### Place an Order
160
+
161
+ ```typescript
162
+ import type { SchwabOrderRequest } from '@huskly/schwab-client';
163
+
164
+ const order: SchwabOrderRequest = {
165
+ session: 'NORMAL',
166
+ duration: 'DAY',
167
+ orderType: 'LIMIT',
168
+ orderStrategyType: 'SINGLE',
169
+ price: 150.00,
170
+ orderLegCollection: [
171
+ {
172
+ instruction: 'BUY',
173
+ quantity: 10,
174
+ instrument: {
175
+ assetType: 'EQUITY',
176
+ symbol: 'AAPL',
177
+ },
178
+ },
179
+ ],
180
+ };
181
+
182
+ const accounts = await client.fetchAccountNumbers();
183
+ const { orderId } = await client.placeOrder(accounts[0].hashValue, order);
184
+ console.log(`Order placed: ${orderId}`);
185
+ ```
186
+
187
+ ### Utilities
188
+
189
+ #### Get Risk-Free Rate
190
+
191
+ ```typescript
192
+ const rate = await client.getRiskFreeRate(new Date());
193
+ // Returns 0.02 (2%)
194
+ ```
195
+
196
+ #### Get Current Date
197
+
198
+ ```typescript
199
+ const today = client.today();
200
+ ```
201
+
202
+ ## API Reference
203
+
204
+ ### Market Data Methods
205
+
206
+ | Method | Description |
207
+ |--------|-------------|
208
+ | `getQuotes(symbols)` | Get real-time quotes for multiple symbols |
209
+ | `getPriceHistory(args)` | Get historical price data |
210
+ | `getVixLevel()` | Get current VIX index level |
211
+ | `getAvailableExpiries(symbol, contractType, fromDate, toDate)` | Get available option expiration dates |
212
+ | `getOptionChain(symbol, expiry)` | Get full options chain for a symbol and expiry |
213
+ | `getOptionQuote(args)` | Get quote for a specific option contract |
214
+ | `searchInstruments(symbol, projection)` | Search for instruments |
215
+ | `getMovers(symbolId, sort?, frequency?)` | Get top market movers |
216
+
217
+ ### Account Methods
218
+
219
+ | Method | Description |
220
+ |--------|-------------|
221
+ | `getAccountEquity()` | Get total account equity |
222
+ | `getAccountBalances()` | Get detailed account balances |
223
+ | `getPositions(symbol?)` | Get account positions |
224
+ | `getExistingSpreads(symbol)` | Get existing option spreads |
225
+ | `fetchAccountNumbers()` | Get all linked account numbers |
226
+ | `fetchTransactionHistory(startDate?, endDate?)` | Get transaction history |
227
+ | `getUserPreference()` | Get user preferences and streaming info |
228
+
229
+ ### Order Methods
230
+
231
+ | Method | Description |
232
+ |--------|-------------|
233
+ | `fetchOrders(options)` | Get orders across all accounts |
234
+ | `fetchAccountOrders(accountHash, options)` | Get orders for specific account |
235
+ | `placeOrder(accountHash, order)` | Place a new order |
236
+
237
+ ## Types
238
+
239
+ All types are exported from the package:
240
+
241
+ ```typescript
242
+ import type {
243
+ SchwabQuoteResponse,
244
+ SchwabOrder,
245
+ SchwabOrderRequest,
246
+ SchwabPosition,
247
+ OptionQuote,
248
+ PriceHistoryCandle,
249
+ // ... and many more
250
+ } from '@huskly/schwab-client';
251
+ ```
252
+
253
+ ## Error Handling
254
+
255
+ The client throws errors for failed API requests:
256
+
257
+ ```typescript
258
+ try {
259
+ const quotes = await client.getQuotes(['INVALID']);
260
+ } catch (error) {
261
+ if (error.message.includes('Unauthorized')) {
262
+ // Token expired or invalid
263
+ }
264
+ }
265
+ ```
266
+
267
+ ## License
268
+
269
+ MIT
@@ -0,0 +1,5 @@
1
+ export { SchwabClient } from "./schwabClient.js";
2
+ export type { SchwabQuoteAssetMainType, SchwabQuoteReference, SchwabQuoteData, SchwabQuoteRegular, SchwabQuoteFundamental, SchwabQuoteResponse, OptionQuote, ExistingSpread, ISODateTime, SchwabSession, SchwabDuration, SchwabOrderType, SchwabComplexOrderStrategyType, SchwabRequestedDestination, SchwabLinkBasis, SchwabLinkType, SchwabStopType, SchwabPriceLinkBasis, SchwabTaxLotMethod, SchwabOrderLegType, SchwabInstruction, SchwabPositionEffect, SchwabQuantityType, SchwabDivCapGains, SchwabSpecialInstruction, SchwabOrderStrategyType, SchwabOrderStatus, SchwabAssetType, SchwabAccountBaseInstrument, SchwabCashEquivalentType, SchwabAccountCashEquivalent, SchwabAccountEquity, SchwabAccountFixedIncome, SchwabAccountMutualFund, SchwabApiCurrencyType, SchwabDeliverableAssetType, SchwabPutCall, SchwabOptionType, SchwabAccountApiOptionDeliverable, SchwabAccountOption, SchwabAccountsInstrument, SchwabOrderLeg, SchwabOrderActivityType, SchwabExecutionType, SchwabExecutionLeg, SchwabOrderActivity, SchwabOrder, SchwabOrdersResponse, SchwabInstrumentSearchProjection, SchwabInstrumentAssetType, SchwabFundamentalInstrument, SchwabBasicInstrument, SchwabBondInstrument, SchwabInstrumentResponse, SchwabInstrumentSearchResponse, SchwabMoversIndexSymbol, SchwabMoversSort, SchwabMoversFrequency, SchwabMoversDirection, SchwabMover, SchwabMoversResponse, SchwabOrderRequestInstrument, SchwabOrderRequestLeg, SchwabOrderRequest, PriceHistoryCandle, PriceHistoryResponse, } from "./types.js";
3
+ export type { SchwabAccountDetails, SchwabAccountPosition, SchwabAccount, SchwabPosition, SchwabInstrument, SchwabTransferItem, SchwabTransaction, SchwabAccountTransactionHistory, SchwabUserPreferenceAccount, SchwabStreamerInfo, SchwabOffer, SchwabUserPreference, } from "./schwabApiTypes.js";
4
+ export { ALL_SCHWAB_ORDER_TYPES, ALL_SCHWAB_INSTRUCTIONS } from "./types.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,YAAY,EAEV,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,WAAW,EACX,cAAc,EAEd,WAAW,EACX,aAAa,EACb,cAAc,EACd,eAAe,EACf,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,2BAA2B,EAC3B,wBAAwB,EACxB,2BAA2B,EAC3B,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,aAAa,EACb,gBAAgB,EAChB,iCAAiC,EACjC,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,EACX,oBAAoB,EAEpB,gCAAgC,EAChC,yBAAyB,EACzB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAE9B,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,oBAAoB,EAEpB,4BAA4B,EAC5B,qBAAqB,EACrB,kBAAkB,EAElB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // Main client
2
+ export { SchwabClient } from "./schwabClient.js";
3
+ // Constants
4
+ export { ALL_SCHWAB_ORDER_TYPES, ALL_SCHWAB_INSTRUCTIONS } from "./types.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AA8FjD,YAAY;AACZ,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,126 @@
1
+ export interface SchwabAccountDetails {
2
+ accountNumber: string;
3
+ positions: SchwabAccountPosition[];
4
+ liquidationValue: number;
5
+ availableFunds: number;
6
+ buyingPower: number;
7
+ cashBalance: number;
8
+ }
9
+ export interface SchwabAccountPosition {
10
+ symbol: string;
11
+ name: string;
12
+ amount: number;
13
+ averageTradePriceUsd: string;
14
+ value: number;
15
+ mark: string;
16
+ changePercent24Hr: string;
17
+ id: string;
18
+ type: "stock" | "option";
19
+ }
20
+ export interface SchwabAccount {
21
+ hashValue?: string;
22
+ securitiesAccount: {
23
+ accountNumber: string;
24
+ hashValue?: string;
25
+ positions: SchwabPosition[];
26
+ currentBalances: {
27
+ equity: number;
28
+ availableFunds: number;
29
+ buyingPower: number;
30
+ cashBalance: number;
31
+ liquidationValue: number;
32
+ };
33
+ };
34
+ }
35
+ export interface SchwabPosition {
36
+ shortQuantity: number;
37
+ longQuantity: number;
38
+ averagePrice: number;
39
+ currentDayProfitLoss: number;
40
+ currentDayProfitLossPercentage: number;
41
+ settledLongQuantity: number;
42
+ settledShortQuantity: number;
43
+ agedQuantity: number;
44
+ maintenanceRequirement: number;
45
+ averageLongPrice: number;
46
+ averageShortPrice: number;
47
+ taxLotAverageLongPrice: number;
48
+ taxLotAverageShortPrice: number;
49
+ longOpenProfitLoss: number;
50
+ shortOpenProfitLoss: number;
51
+ previousSessionLongQuantity: number;
52
+ previousSessionShortQuantity: number;
53
+ currentDayCost: number;
54
+ instrument: {
55
+ assetType: string;
56
+ cusip: string;
57
+ symbol: string;
58
+ underlyingSymbol?: string;
59
+ description: string;
60
+ instrumentId: number;
61
+ netChange?: number;
62
+ type: string;
63
+ };
64
+ marketValue: number;
65
+ }
66
+ export interface SchwabInstrument {
67
+ symbol?: string;
68
+ description?: string;
69
+ assetType?: string;
70
+ type?: string;
71
+ }
72
+ export interface SchwabTransferItem {
73
+ instrument?: SchwabInstrument;
74
+ amount?: number;
75
+ cost?: number;
76
+ fee?: number;
77
+ price?: number;
78
+ quantity?: number;
79
+ transferItemType?: string;
80
+ positionEffect?: string;
81
+ transactionId?: number;
82
+ }
83
+ export interface SchwabTransaction {
84
+ activityId: number;
85
+ time: string;
86
+ accountNumber: string;
87
+ type: string;
88
+ status: string;
89
+ subAccount: string;
90
+ tradeDate: string;
91
+ positionId: number;
92
+ orderId: number;
93
+ netAmount: number;
94
+ description?: string;
95
+ transferItems?: SchwabTransferItem[];
96
+ }
97
+ export interface SchwabAccountTransactionHistory {
98
+ accountNumber: string;
99
+ transactions: SchwabTransaction[];
100
+ }
101
+ export interface SchwabUserPreferenceAccount {
102
+ accountNumber: string;
103
+ primaryAccount: boolean;
104
+ type: string;
105
+ nickName: string;
106
+ accountColor: string;
107
+ displayAcctId: string;
108
+ autoPositionEffect: boolean;
109
+ }
110
+ export interface SchwabStreamerInfo {
111
+ streamerSocketUrl: string;
112
+ schwabClientCustomerId: string;
113
+ schwabClientCorrelId: string;
114
+ schwabClientChannel: string;
115
+ schwabClientFunctionId: string;
116
+ }
117
+ export interface SchwabOffer {
118
+ level2Permissions: boolean;
119
+ mktDataPermission: string;
120
+ }
121
+ export interface SchwabUserPreference {
122
+ accounts: SchwabUserPreferenceAccount[];
123
+ streamerInfo: SchwabStreamerInfo;
124
+ offers: SchwabOffer[];
125
+ }
126
+ //# sourceMappingURL=schwabApiTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schwabApiTypes.d.ts","sourceRoot":"","sources":["../src/schwabApiTypes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,qBAAqB,EAAE,CAAC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,M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E,CAAC;CACtC;AAED,MAAM,WAAW,+BAA+B;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,iBAAiB,EAAE,CAAC;CACnC;AAGD,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,2BAA2B,EAAE,CAAC;IACxC,YAAY,EAAE,kBAAkB,CAAC;IACjC,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=schwabApiTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schwabApiTypes.js","sourceRoot":"","sources":["../src/schwabApiTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,96 @@
1
+ import type { ExistingSpread, OptionQuote, PriceHistoryResponse, SchwabOrder, SchwabOrderRequest, SchwabOrderStatus, SchwabQuoteResponse, SchwabInstrumentSearchProjection, SchwabInstrumentResponse, SchwabMoversIndexSymbol, SchwabMoversSort, SchwabMoversFrequency, SchwabMoversResponse } from "./types.js";
2
+ import type { SchwabAccountTransactionHistory, SchwabPosition, SchwabTransaction, SchwabUserPreference } from "./schwabApiTypes.js";
3
+ /**
4
+ * Schwab Market Data and Trading API client.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { SchwabClient } from '@huskly/schwab-client';
9
+ *
10
+ * const client = new SchwabClient('your-access-token');
11
+ * const quotes = await client.getQuotes(['AAPL', 'GOOGL']);
12
+ * ```
13
+ */
14
+ export declare class SchwabClient {
15
+ private readonly accessToken;
16
+ /**
17
+ * Creates a new SchwabClient instance.
18
+ * @param accessToken - A valid Schwab API access token
19
+ */
20
+ constructor(accessToken: string);
21
+ today(): Date;
22
+ getRiskFreeRate(_date: Date): Promise<number>;
23
+ getQuotes(symbols: string[]): Promise<Record<string, SchwabQuoteResponse>>;
24
+ getPriceHistory({ symbol, days, startDate, endDate, }: {
25
+ symbol: string;
26
+ days?: number;
27
+ startDate?: number;
28
+ endDate?: number;
29
+ }): Promise<PriceHistoryResponse["candles"]>;
30
+ getVixLevel(): Promise<number | undefined>;
31
+ getAvailableExpiries(symbol: string, contractType: "PUT" | "CALL", fromDate: string, toDate: string): Promise<Date[]>;
32
+ getOptionChain(symbol: string, expiry: Date): Promise<OptionQuote[]>;
33
+ getOptionQuote(args: {
34
+ symbol: string;
35
+ expiry: Date;
36
+ strike: number;
37
+ type: "call" | "put";
38
+ }): Promise<OptionQuote | null>;
39
+ getAccountEquity(): Promise<number>;
40
+ getAccountBalances(): Promise<{
41
+ liquidationValue: number;
42
+ cashBalance: number;
43
+ availableFunds: number;
44
+ buyingPower: number;
45
+ equity: number;
46
+ }>;
47
+ getPositions(symbol?: string): Promise<SchwabPosition[]>;
48
+ getExistingSpreads(symbol: string): Promise<ExistingSpread[]>;
49
+ fetchAccountNumbers(): Promise<{
50
+ accountNumber: string;
51
+ hashValue: string;
52
+ }[]>;
53
+ fetchTransactionHistory(startDate?: Date, endDate?: Date): Promise<SchwabAccountTransactionHistory[]>;
54
+ fetchAccountTransactionHistory(accountHash: string, startDate?: Date, endDate?: Date): Promise<SchwabTransaction[]>;
55
+ fetchOrders(options: {
56
+ fromEnteredTime: Date;
57
+ toEnteredTime: Date;
58
+ maxResults?: number;
59
+ status?: SchwabOrderStatus;
60
+ }): Promise<{
61
+ accountNumber: string;
62
+ orders: SchwabOrder[];
63
+ }[]>;
64
+ fetchAccountOrders(accountHash: string, options: {
65
+ fromEnteredTime: Date;
66
+ toEnteredTime: Date;
67
+ maxResults?: number;
68
+ status?: SchwabOrderStatus;
69
+ }): Promise<SchwabOrder[]>;
70
+ /**
71
+ * Place an order for a specific account.
72
+ * Returns the order ID from the Location header on success.
73
+ */
74
+ placeOrder(accountHash: string, order: SchwabOrderRequest): Promise<{
75
+ orderId: string;
76
+ }>;
77
+ getUserPreference(): Promise<SchwabUserPreference>;
78
+ /**
79
+ * Search for instruments by symbol or description.
80
+ * @param symbol - The search term (symbol or description fragment)
81
+ * @param projection - The type of search to perform
82
+ * @returns Array of matching instruments
83
+ */
84
+ searchInstruments(symbol: string, projection: SchwabInstrumentSearchProjection): Promise<SchwabInstrumentResponse[]>;
85
+ /**
86
+ * Get top 10 movers for a specific index.
87
+ * @param symbolId - Index symbol ($DJI, $COMPX, $SPX, NYSE, NASDAQ, etc.)
88
+ * @param sort - Sort by VOLUME, TRADES, PERCENT_CHANGE_UP, or PERCENT_CHANGE_DOWN
89
+ * @param frequency - Frequency in minutes (0, 1, 5, 10, 30, 60). Default is 0.
90
+ * @returns List of top movers
91
+ */
92
+ getMovers(symbolId: SchwabMoversIndexSymbol, sort?: SchwabMoversSort, frequency?: SchwabMoversFrequency): Promise<SchwabMoversResponse>;
93
+ private headersToRecord;
94
+ private makeApiRequest;
95
+ }
96
+ //# sourceMappingURL=schwabClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schwabClient.d.ts","sourceRoot":"","sources":["../src/schwabClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,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