@finatic/client 0.0.139 → 0.0.141
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 +335 -446
- package/dist/index.d.ts +272 -515
- package/dist/index.js +531 -449
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +532 -449
- package/dist/index.mjs.map +1 -1
- package/dist/types/core/client/ApiClient.d.ts +81 -27
- package/dist/types/core/client/FinaticConnect.d.ts +53 -103
- package/dist/types/index.d.ts +1 -2
- package/dist/types/mocks/MockApiClient.d.ts +2 -4
- package/dist/types/mocks/utils.d.ts +0 -5
- package/dist/types/types/api/auth.d.ts +12 -30
- package/dist/types/types/api/broker.d.ts +117 -1
- package/package.json +7 -3
- package/src/core/client/ApiClient.ts +1978 -0
- package/src/core/client/FinaticConnect.ts +1557 -0
- package/src/core/portal/PortalUI.ts +300 -0
- package/src/index.d.ts +23 -0
- package/src/index.ts +99 -0
- package/src/mocks/MockApiClient.ts +1032 -0
- package/src/mocks/MockDataProvider.ts +986 -0
- package/src/mocks/MockFactory.ts +97 -0
- package/src/mocks/utils.ts +133 -0
- package/src/themes/portalPresets.ts +1307 -0
- package/src/types/api/auth.ts +112 -0
- package/src/types/api/broker.ts +461 -0
- package/src/types/api/core.ts +53 -0
- package/src/types/api/errors.ts +35 -0
- package/src/types/api/orders.ts +45 -0
- package/src/types/api/portfolio.ts +59 -0
- package/src/types/common/pagination.ts +138 -0
- package/src/types/connect.ts +56 -0
- package/src/types/index.ts +25 -0
- package/src/types/portal.ts +214 -0
- package/src/types/ui/theme.ts +105 -0
- package/src/utils/brokerUtils.ts +85 -0
- package/src/utils/errors.ts +104 -0
- package/src/utils/events.ts +54 -0
- package/src/utils/themeUtils.ts +146 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication-related types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface SessionInitResponse {
|
|
6
|
+
success: boolean;
|
|
7
|
+
message: string;
|
|
8
|
+
data: {
|
|
9
|
+
one_time_token: string;
|
|
10
|
+
expires_at: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// SessionResponseData moved below to match backend response format
|
|
15
|
+
|
|
16
|
+
// SessionStartResponse removed - using SessionResponse instead
|
|
17
|
+
|
|
18
|
+
export interface OtpRequestResponse {
|
|
19
|
+
success: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
data: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface OtpVerifyResponse {
|
|
25
|
+
success: boolean;
|
|
26
|
+
message: string;
|
|
27
|
+
data: {
|
|
28
|
+
access_token: string;
|
|
29
|
+
refresh_token: string;
|
|
30
|
+
user_id: string;
|
|
31
|
+
expires_in: number;
|
|
32
|
+
scope: string;
|
|
33
|
+
token_type: 'Bearer';
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface UserToken {
|
|
38
|
+
user_id: string;
|
|
39
|
+
// Removed token fields - we no longer use Supabase tokens in the SDK
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SessionValidationResponse {
|
|
43
|
+
valid: boolean;
|
|
44
|
+
company_id: string;
|
|
45
|
+
status: string;
|
|
46
|
+
is_sandbox: boolean; // Whether this session is in sandbox mode
|
|
47
|
+
environment: string; // Environment context (production or sandbox)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SessionAuthenticateResponse {
|
|
51
|
+
success: boolean;
|
|
52
|
+
message: string;
|
|
53
|
+
data: {
|
|
54
|
+
access_token: string;
|
|
55
|
+
refresh_token: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface RefreshTokenRequest {
|
|
60
|
+
refresh_token: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface RefreshTokenResponse {
|
|
64
|
+
success: boolean;
|
|
65
|
+
response_data: {
|
|
66
|
+
access_token: string;
|
|
67
|
+
refresh_token: string;
|
|
68
|
+
expires_at: string;
|
|
69
|
+
company_id: string;
|
|
70
|
+
company_name: string;
|
|
71
|
+
email_verified: boolean;
|
|
72
|
+
};
|
|
73
|
+
message: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TokenInfo {
|
|
77
|
+
accessToken: string;
|
|
78
|
+
refreshToken: string;
|
|
79
|
+
expiresAt: string;
|
|
80
|
+
userId?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface SessionResponseData {
|
|
84
|
+
session_id: string;
|
|
85
|
+
company_id: string;
|
|
86
|
+
status: string;
|
|
87
|
+
expires_at: string;
|
|
88
|
+
user_id?: string | null;
|
|
89
|
+
auto_login?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface SessionResponse {
|
|
93
|
+
success: boolean;
|
|
94
|
+
message: string;
|
|
95
|
+
data: SessionResponseData;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export enum SessionState {
|
|
99
|
+
PENDING = 'PENDING',
|
|
100
|
+
AUTHENTICATING = 'AUTHENTICATING',
|
|
101
|
+
ACTIVE = 'ACTIVE',
|
|
102
|
+
COMPLETED = 'COMPLETED',
|
|
103
|
+
EXPIRED = 'EXPIRED',
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type SessionStatus = SessionState;
|
|
107
|
+
|
|
108
|
+
export interface DeviceInfo {
|
|
109
|
+
ip_address: string;
|
|
110
|
+
user_agent: string;
|
|
111
|
+
fingerprint: string;
|
|
112
|
+
}
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Broker-related types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface BrokerAccount {
|
|
6
|
+
id: string;
|
|
7
|
+
user_broker_connection_id: string;
|
|
8
|
+
broker_provided_account_id: string;
|
|
9
|
+
account_name: string;
|
|
10
|
+
account_type: string;
|
|
11
|
+
currency: string;
|
|
12
|
+
cash_balance: number;
|
|
13
|
+
buying_power: number;
|
|
14
|
+
status: string;
|
|
15
|
+
/** ISO 8601 timestamp with timezone information */
|
|
16
|
+
created_at: string;
|
|
17
|
+
/** ISO 8601 timestamp with timezone information */
|
|
18
|
+
updated_at: string;
|
|
19
|
+
/** ISO 8601 timestamp with timezone information */
|
|
20
|
+
last_synced_at: string;
|
|
21
|
+
/** ISO 8601 timestamp with timezone information - when positions were last synced */
|
|
22
|
+
positions_synced_at: string | null;
|
|
23
|
+
/** ISO 8601 timestamp with timezone information - when orders were last synced */
|
|
24
|
+
orders_synced_at: string | null;
|
|
25
|
+
/** ISO 8601 timestamp with timezone information - when balances were last synced */
|
|
26
|
+
balances_synced_at: string | null;
|
|
27
|
+
/** ISO 8601 timestamp with timezone information - when the account was created */
|
|
28
|
+
account_created_at: string | null;
|
|
29
|
+
/** ISO 8601 timestamp with timezone information - when the account was last updated */
|
|
30
|
+
account_updated_at: string | null;
|
|
31
|
+
/** ISO 8601 timestamp with timezone information - when the first trade occurred */
|
|
32
|
+
account_first_trade_at: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface BrokerOrder {
|
|
36
|
+
id: string;
|
|
37
|
+
user_broker_connection_id: string;
|
|
38
|
+
broker_provided_account_id: string;
|
|
39
|
+
order_id: string;
|
|
40
|
+
symbol: string;
|
|
41
|
+
order_type: string;
|
|
42
|
+
side: 'buy' | 'sell';
|
|
43
|
+
quantity: number;
|
|
44
|
+
price: number;
|
|
45
|
+
status: string;
|
|
46
|
+
/** ISO 8601 timestamp with timezone information */
|
|
47
|
+
created_at: string;
|
|
48
|
+
/** ISO 8601 timestamp with timezone information */
|
|
49
|
+
updated_at: string;
|
|
50
|
+
/** ISO 8601 timestamp with timezone information, null if not filled */
|
|
51
|
+
filled_at: string | null;
|
|
52
|
+
filled_quantity: number;
|
|
53
|
+
filled_avg_price: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface BrokerPosition {
|
|
57
|
+
id: string;
|
|
58
|
+
user_broker_connection_id: string;
|
|
59
|
+
broker_provided_account_id: string;
|
|
60
|
+
symbol: string;
|
|
61
|
+
asset_type: string;
|
|
62
|
+
quantity: number;
|
|
63
|
+
average_price: number;
|
|
64
|
+
market_value: number;
|
|
65
|
+
cost_basis: number;
|
|
66
|
+
unrealized_gain_loss: number;
|
|
67
|
+
unrealized_gain_loss_percent: number;
|
|
68
|
+
current_price: number;
|
|
69
|
+
last_price: number;
|
|
70
|
+
/** ISO 8601 timestamp with timezone information */
|
|
71
|
+
last_price_updated_at: string;
|
|
72
|
+
/** ISO 8601 timestamp with timezone information */
|
|
73
|
+
created_at: string;
|
|
74
|
+
/** ISO 8601 timestamp with timezone information */
|
|
75
|
+
updated_at: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface BrokerBalance {
|
|
79
|
+
id: string;
|
|
80
|
+
account_id: string;
|
|
81
|
+
total_cash_value: number | null;
|
|
82
|
+
net_liquidation_value: number | null;
|
|
83
|
+
initial_margin: number | null;
|
|
84
|
+
maintenance_margin: number | null;
|
|
85
|
+
available_to_withdraw: number | null;
|
|
86
|
+
total_realized_pnl: number | null;
|
|
87
|
+
balance_created_at: string | null;
|
|
88
|
+
balance_updated_at: string | null;
|
|
89
|
+
is_end_of_day_snapshot: boolean | null;
|
|
90
|
+
raw_payload: any | null;
|
|
91
|
+
/** ISO 8601 timestamp with timezone information */
|
|
92
|
+
created_at: string;
|
|
93
|
+
/** ISO 8601 timestamp with timezone information */
|
|
94
|
+
updated_at: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface BrokerDataOptions {
|
|
98
|
+
broker_name?: string;
|
|
99
|
+
account_id?: string;
|
|
100
|
+
symbol?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface BrokerInfo {
|
|
104
|
+
id: string;
|
|
105
|
+
name: string;
|
|
106
|
+
display_name: string;
|
|
107
|
+
description: string;
|
|
108
|
+
website: string;
|
|
109
|
+
features: string[];
|
|
110
|
+
auth_type: 'oauth' | 'api_key';
|
|
111
|
+
logo_path: string;
|
|
112
|
+
is_active: boolean;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface BrokerOrderParams {
|
|
116
|
+
broker: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
117
|
+
order_id?: string; // Optional order_id field for modify operations
|
|
118
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
119
|
+
assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
|
|
120
|
+
action: 'Buy' | 'Sell';
|
|
121
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
122
|
+
accountNumber: string | number;
|
|
123
|
+
symbol: string;
|
|
124
|
+
orderQty: number;
|
|
125
|
+
price?: number;
|
|
126
|
+
stopPrice?: number;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface BrokerExtras {
|
|
130
|
+
robinhood?: {
|
|
131
|
+
extendedHours?: boolean;
|
|
132
|
+
marketHours?: 'regular_hours' | 'extended_hours';
|
|
133
|
+
trailType?: 'percentage' | 'amount';
|
|
134
|
+
};
|
|
135
|
+
ninjaTrader?: {
|
|
136
|
+
accountSpec?: string;
|
|
137
|
+
isAutomated?: boolean;
|
|
138
|
+
activationTime?: string;
|
|
139
|
+
text?: string;
|
|
140
|
+
pegDifference?: number;
|
|
141
|
+
expireTime?: string;
|
|
142
|
+
};
|
|
143
|
+
tastyTrade?: {
|
|
144
|
+
automatedSource?: boolean;
|
|
145
|
+
priceEffect?: 'Debit' | 'Credit';
|
|
146
|
+
externalIdentifier?: string;
|
|
147
|
+
partitionKey?: string;
|
|
148
|
+
preflightId?: string;
|
|
149
|
+
source?: string;
|
|
150
|
+
valueEffect?: 'Debit' | 'Credit';
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface BrokerConnection {
|
|
155
|
+
id: string;
|
|
156
|
+
broker_id: string;
|
|
157
|
+
user_id: string;
|
|
158
|
+
company_id: string;
|
|
159
|
+
status: 'connected' | 'disconnected' | 'error';
|
|
160
|
+
connected_at: string;
|
|
161
|
+
last_synced_at: string | null;
|
|
162
|
+
permissions: {
|
|
163
|
+
read: boolean;
|
|
164
|
+
write: boolean;
|
|
165
|
+
};
|
|
166
|
+
metadata: {
|
|
167
|
+
nickname?: string;
|
|
168
|
+
[key: string]: any;
|
|
169
|
+
};
|
|
170
|
+
needs_reauth: boolean;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Enhanced broker data types
|
|
174
|
+
export interface BrokerDataOrder {
|
|
175
|
+
id: string;
|
|
176
|
+
broker_id: string;
|
|
177
|
+
connection_id: string;
|
|
178
|
+
account_id: string;
|
|
179
|
+
order_id: string;
|
|
180
|
+
symbol: string;
|
|
181
|
+
order_type: string;
|
|
182
|
+
side: 'buy' | 'sell';
|
|
183
|
+
quantity: number;
|
|
184
|
+
price: number;
|
|
185
|
+
status: 'filled' | 'pending' | 'cancelled' | 'rejected' | 'partially_filled';
|
|
186
|
+
asset_type: 'stock' | 'option' | 'crypto' | 'future';
|
|
187
|
+
created_at: string;
|
|
188
|
+
updated_at: string;
|
|
189
|
+
filled_at?: string;
|
|
190
|
+
filled_quantity: number;
|
|
191
|
+
filled_avg_price: number;
|
|
192
|
+
metadata?: Record<string, any>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface BrokerDataPosition {
|
|
196
|
+
id: string;
|
|
197
|
+
broker_id: string;
|
|
198
|
+
connection_id: string;
|
|
199
|
+
account_id: string;
|
|
200
|
+
symbol: string;
|
|
201
|
+
asset_type: 'stock' | 'option' | 'crypto' | 'future';
|
|
202
|
+
side: 'long' | 'short';
|
|
203
|
+
quantity: number;
|
|
204
|
+
average_price: number;
|
|
205
|
+
market_value: number;
|
|
206
|
+
cost_basis: number;
|
|
207
|
+
unrealized_gain_loss: number;
|
|
208
|
+
unrealized_gain_loss_percent: number;
|
|
209
|
+
current_price: number;
|
|
210
|
+
last_price: number;
|
|
211
|
+
last_price_updated_at: string;
|
|
212
|
+
position_status: 'open' | 'closed';
|
|
213
|
+
created_at: string;
|
|
214
|
+
updated_at: string;
|
|
215
|
+
metadata?: Record<string, any>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface BrokerDataAccount {
|
|
219
|
+
id: string;
|
|
220
|
+
broker_id: string;
|
|
221
|
+
connection_id: string;
|
|
222
|
+
account_id: string;
|
|
223
|
+
account_name: string;
|
|
224
|
+
account_type: 'margin' | 'cash' | 'crypto_wallet' | 'live' | 'sim';
|
|
225
|
+
status: 'active' | 'inactive';
|
|
226
|
+
currency: string;
|
|
227
|
+
cash_balance: number;
|
|
228
|
+
buying_power: number;
|
|
229
|
+
equity: number;
|
|
230
|
+
created_at: string;
|
|
231
|
+
updated_at: string;
|
|
232
|
+
last_synced_at: string;
|
|
233
|
+
metadata?: Record<string, any>;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Filter types
|
|
237
|
+
export interface OrdersFilter {
|
|
238
|
+
broker_id?: string;
|
|
239
|
+
connection_id?: string;
|
|
240
|
+
account_id?: string;
|
|
241
|
+
symbol?: string;
|
|
242
|
+
status?: 'filled' | 'pending' | 'cancelled' | 'rejected' | 'partially_filled';
|
|
243
|
+
side?: 'buy' | 'sell';
|
|
244
|
+
asset_type?: 'stock' | 'option' | 'crypto' | 'future';
|
|
245
|
+
limit?: number;
|
|
246
|
+
offset?: number;
|
|
247
|
+
created_after?: string; // ISO 8601 format
|
|
248
|
+
created_before?: string; // ISO 8601 format
|
|
249
|
+
with_metadata?: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface PositionsFilter {
|
|
253
|
+
broker_id?: string;
|
|
254
|
+
connection_id?: string;
|
|
255
|
+
account_id?: string;
|
|
256
|
+
symbol?: string;
|
|
257
|
+
side?: 'long' | 'short';
|
|
258
|
+
asset_type?: 'stock' | 'option' | 'crypto' | 'future';
|
|
259
|
+
position_status?: 'open' | 'closed';
|
|
260
|
+
limit?: number;
|
|
261
|
+
offset?: number;
|
|
262
|
+
updated_after?: string; // ISO 8601 format
|
|
263
|
+
updated_before?: string; // ISO 8601 format
|
|
264
|
+
with_metadata?: boolean;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface AccountsFilter {
|
|
268
|
+
broker_id?: string;
|
|
269
|
+
connection_id?: string;
|
|
270
|
+
account_type?: 'margin' | 'cash' | 'crypto_wallet' | 'live' | 'sim';
|
|
271
|
+
status?: 'active' | 'inactive';
|
|
272
|
+
currency?: string;
|
|
273
|
+
limit?: number;
|
|
274
|
+
offset?: number;
|
|
275
|
+
with_metadata?: boolean;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export interface BalancesFilter {
|
|
279
|
+
broker_id?: string;
|
|
280
|
+
connection_id?: string;
|
|
281
|
+
account_id?: string;
|
|
282
|
+
is_end_of_day_snapshot?: boolean;
|
|
283
|
+
limit?: number;
|
|
284
|
+
offset?: number;
|
|
285
|
+
balance_created_after?: string; // ISO 8601 format
|
|
286
|
+
balance_created_before?: string; // ISO 8601 format
|
|
287
|
+
with_metadata?: boolean;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Response types for filtered data
|
|
291
|
+
export interface FilteredOrdersResponse {
|
|
292
|
+
orders: BrokerDataOrder[];
|
|
293
|
+
total: number;
|
|
294
|
+
limit: number;
|
|
295
|
+
offset: number;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface FilteredPositionsResponse {
|
|
299
|
+
positions: BrokerDataPosition[];
|
|
300
|
+
total: number;
|
|
301
|
+
limit: number;
|
|
302
|
+
offset: number;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface FilteredAccountsResponse {
|
|
306
|
+
accounts: BrokerDataAccount[];
|
|
307
|
+
total: number;
|
|
308
|
+
limit: number;
|
|
309
|
+
offset: number;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface FilteredBalancesResponse {
|
|
313
|
+
balances: BrokerBalance[];
|
|
314
|
+
total: number;
|
|
315
|
+
limit: number;
|
|
316
|
+
offset: number;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Disconnect company response types
|
|
320
|
+
export interface DisconnectCompanyResponse {
|
|
321
|
+
success: boolean;
|
|
322
|
+
response_data: {
|
|
323
|
+
connection_id: string;
|
|
324
|
+
action: 'company_access_removed' | 'connection_deleted';
|
|
325
|
+
remaining_companies?: number;
|
|
326
|
+
message: string;
|
|
327
|
+
};
|
|
328
|
+
message: string;
|
|
329
|
+
status_code: number;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Order detail types
|
|
333
|
+
export interface OrderFill {
|
|
334
|
+
id: string;
|
|
335
|
+
order_id: string;
|
|
336
|
+
leg_id: string | null;
|
|
337
|
+
price: number;
|
|
338
|
+
quantity: number;
|
|
339
|
+
executed_at: string;
|
|
340
|
+
execution_id: string | null;
|
|
341
|
+
trade_id: string | null;
|
|
342
|
+
venue: string | null;
|
|
343
|
+
commission_fee: number | null;
|
|
344
|
+
created_at: string;
|
|
345
|
+
updated_at: string;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface OrderEvent {
|
|
349
|
+
id: string;
|
|
350
|
+
order_id: string;
|
|
351
|
+
order_group_id: string | null;
|
|
352
|
+
event_type: string | null;
|
|
353
|
+
event_time: string;
|
|
354
|
+
event_id: string | null;
|
|
355
|
+
order_status: string | null;
|
|
356
|
+
inferred: boolean;
|
|
357
|
+
confidence: number | null;
|
|
358
|
+
reason_code: string | null;
|
|
359
|
+
recorded_at: string | null;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface OrderLeg {
|
|
363
|
+
id: string;
|
|
364
|
+
order_id: string;
|
|
365
|
+
leg_index: number;
|
|
366
|
+
asset_type: string;
|
|
367
|
+
broker_provided_symbol: string | null;
|
|
368
|
+
quantity: number;
|
|
369
|
+
filled_quantity: number | null;
|
|
370
|
+
avg_fill_price: number | null;
|
|
371
|
+
created_at: string | null;
|
|
372
|
+
updated_at: string | null;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface OrderGroupOrder extends BrokerDataOrder {
|
|
376
|
+
legs: OrderLeg[];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface OrderGroup {
|
|
380
|
+
id: string;
|
|
381
|
+
user_broker_connection_id: string | null;
|
|
382
|
+
created_at: string;
|
|
383
|
+
updated_at: string;
|
|
384
|
+
orders: OrderGroupOrder[];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Position detail types
|
|
388
|
+
export interface PositionLot {
|
|
389
|
+
id: string;
|
|
390
|
+
position_id: string | null;
|
|
391
|
+
user_broker_connection_id: string;
|
|
392
|
+
broker_provided_account_id: string;
|
|
393
|
+
instrument_key: string;
|
|
394
|
+
asset_type: string | null;
|
|
395
|
+
side: 'long' | 'short' | null;
|
|
396
|
+
open_quantity: number;
|
|
397
|
+
closed_quantity: number;
|
|
398
|
+
remaining_quantity: number;
|
|
399
|
+
open_price: number;
|
|
400
|
+
close_price_avg: number | null;
|
|
401
|
+
cost_basis: number;
|
|
402
|
+
cost_basis_w_commission: number;
|
|
403
|
+
realized_pl: number;
|
|
404
|
+
realized_pl_w_commission: number;
|
|
405
|
+
lot_opened_at: string;
|
|
406
|
+
lot_closed_at: string | null;
|
|
407
|
+
position_group_id: string | null;
|
|
408
|
+
created_at: string;
|
|
409
|
+
updated_at: string;
|
|
410
|
+
position_lot_fills?: PositionLotFill[];
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface PositionLotFill {
|
|
414
|
+
id: string;
|
|
415
|
+
lot_id: string;
|
|
416
|
+
order_fill_id: string;
|
|
417
|
+
fill_price: number;
|
|
418
|
+
fill_quantity: number;
|
|
419
|
+
executed_at: string;
|
|
420
|
+
commission_share: number | null;
|
|
421
|
+
created_at: string;
|
|
422
|
+
updated_at: string;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Filter types for detail endpoints
|
|
426
|
+
export interface OrderFillsFilter {
|
|
427
|
+
connection_id?: string;
|
|
428
|
+
limit?: number;
|
|
429
|
+
offset?: number;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export interface OrderEventsFilter {
|
|
433
|
+
connection_id?: string;
|
|
434
|
+
limit?: number;
|
|
435
|
+
offset?: number;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface OrderGroupsFilter {
|
|
439
|
+
broker_id?: string;
|
|
440
|
+
connection_id?: string;
|
|
441
|
+
limit?: number;
|
|
442
|
+
offset?: number;
|
|
443
|
+
created_after?: string;
|
|
444
|
+
created_before?: string;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface PositionLotsFilter {
|
|
448
|
+
broker_id?: string;
|
|
449
|
+
connection_id?: string;
|
|
450
|
+
account_id?: string;
|
|
451
|
+
symbol?: string;
|
|
452
|
+
position_id?: string;
|
|
453
|
+
limit?: number;
|
|
454
|
+
offset?: number;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
export interface PositionLotFillsFilter {
|
|
458
|
+
connection_id?: string;
|
|
459
|
+
limit?: number;
|
|
460
|
+
offset?: number;
|
|
461
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core API types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ApiPaginationInfo } from '../common/pagination';
|
|
6
|
+
|
|
7
|
+
export interface ApiConfig {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
sandbox?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ApiResponse<T> {
|
|
14
|
+
success: boolean;
|
|
15
|
+
response_data: T;
|
|
16
|
+
message: string;
|
|
17
|
+
status_code: number;
|
|
18
|
+
pagination?: ApiPaginationInfo;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ApiError {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
details?: Record<string, any>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface RequestHeaders {
|
|
28
|
+
'Content-Type': string;
|
|
29
|
+
'X-API-Key'?: string;
|
|
30
|
+
Authorization?: string;
|
|
31
|
+
'X-CSRF-Token'?: string;
|
|
32
|
+
token?: string;
|
|
33
|
+
'User-Agent'?: string;
|
|
34
|
+
'X-Device-Info'?: string;
|
|
35
|
+
'X-Request-ID'?: string;
|
|
36
|
+
'X-Request-Timestamp'?: string;
|
|
37
|
+
'X-Request-Signature'?: string;
|
|
38
|
+
[key: string]: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PortalResponse {
|
|
42
|
+
portalUrl: string;
|
|
43
|
+
token: string;
|
|
44
|
+
expiresIn: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface PortalUrlResponse {
|
|
48
|
+
success: boolean;
|
|
49
|
+
message: string;
|
|
50
|
+
data: {
|
|
51
|
+
portal_url: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error response types matching API documentation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface TradeAccessDeniedError {
|
|
6
|
+
success: false;
|
|
7
|
+
response_data: null;
|
|
8
|
+
message: string;
|
|
9
|
+
status_code: 403;
|
|
10
|
+
category: 'TRADE_ACCESS_DENIED';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OrderNotFoundError {
|
|
14
|
+
success: false;
|
|
15
|
+
response_data: null;
|
|
16
|
+
message: string;
|
|
17
|
+
status_code: 404;
|
|
18
|
+
category: 'ORDER_NOT_FOUND';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ValidationError {
|
|
22
|
+
success: false;
|
|
23
|
+
response_data: null;
|
|
24
|
+
message: string;
|
|
25
|
+
status_code: 400;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TradingNotEnabledError {
|
|
29
|
+
success: false;
|
|
30
|
+
response_data: null;
|
|
31
|
+
message: string;
|
|
32
|
+
status_code: 403;
|
|
33
|
+
code: 'TRADING_NOT_ENABLED';
|
|
34
|
+
requires_action: null;
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order-related types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface Order {
|
|
6
|
+
symbol: string;
|
|
7
|
+
side: 'buy' | 'sell';
|
|
8
|
+
quantity: number;
|
|
9
|
+
type_: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
10
|
+
price?: number;
|
|
11
|
+
stopPrice?: number;
|
|
12
|
+
timeInForce: 'day' | 'gtc' | 'opg' | 'cls' | 'ioc' | 'fok';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface OptionsOrder extends Order {
|
|
16
|
+
optionType: 'call' | 'put';
|
|
17
|
+
strikePrice: number;
|
|
18
|
+
expirationDate: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CryptoOrderOptions {
|
|
22
|
+
quantity?: number;
|
|
23
|
+
notional?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface OptionsOrderOptions {
|
|
27
|
+
strikePrice: number;
|
|
28
|
+
expirationDate: string;
|
|
29
|
+
optionType: 'call' | 'put';
|
|
30
|
+
contractSize?: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface OrderResponse {
|
|
34
|
+
success: boolean;
|
|
35
|
+
response_data: any; // More flexible for broker-specific response data
|
|
36
|
+
message: string;
|
|
37
|
+
status_code: number;
|
|
38
|
+
category?: string; // For error categorization
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface TradingContext {
|
|
42
|
+
broker?: string;
|
|
43
|
+
accountNumber?: string;
|
|
44
|
+
accountId?: string;
|
|
45
|
+
}
|