@brokerize/client 1.11.0 → 1.12.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.
Files changed (62) hide show
  1. package/README.md +45 -0
  2. package/dist/apiCtx.d.ts +10 -2
  3. package/dist/apiCtx.js +4 -4
  4. package/dist/authorizedApiContext.d.ts +5 -0
  5. package/dist/authorizedApiContext.js +11 -2
  6. package/dist/cjs/apiCtx.d.ts +10 -2
  7. package/dist/cjs/apiCtx.js +4 -4
  8. package/dist/cjs/authorizedApiContext.d.ts +5 -0
  9. package/dist/cjs/authorizedApiContext.js +10 -1
  10. package/dist/cjs/errors.d.ts +60 -0
  11. package/dist/cjs/errors.js +48 -1
  12. package/dist/cjs/index.d.ts +4 -4
  13. package/dist/cjs/index.js +4 -1
  14. package/dist/cjs/modelExports.d.ts +2 -0
  15. package/dist/cjs/modelExports.js +3 -1
  16. package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfo.d.ts +60 -0
  17. package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfo.js +51 -0
  18. package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfoStatus.d.ts +22 -0
  19. package/dist/cjs/swagger/models/PortfolioOrderDetailsSyncInfoStatus.js +35 -0
  20. package/dist/cjs/swagger/models/PortfolioSyncInfoComplete.d.ts +7 -0
  21. package/dist/cjs/swagger/models/PortfolioSyncInfoComplete.js +6 -0
  22. package/dist/cjs/swagger/models/PortfolioSyncInfoCompleteSpecifics.d.ts +7 -0
  23. package/dist/cjs/swagger/models/PortfolioSyncInfoCompleteSpecifics.js +5 -0
  24. package/dist/cjs/swagger/models/PortfolioSyncInfoIncomplete.d.ts +7 -0
  25. package/dist/cjs/swagger/models/PortfolioSyncInfoIncomplete.js +6 -0
  26. package/dist/cjs/swagger/models/PortfolioSyncInfoIncompleteSpecifics.d.ts +7 -0
  27. package/dist/cjs/swagger/models/PortfolioSyncInfoIncompleteSpecifics.js +5 -0
  28. package/dist/cjs/swagger/models/TradeWarningReason.d.ts +1 -0
  29. package/dist/cjs/swagger/models/TradeWarningReason.js +1 -0
  30. package/dist/cjs/swagger/models/index.d.ts +2 -0
  31. package/dist/cjs/swagger/models/index.js +2 -0
  32. package/dist/cjs/websocketClient.d.ts +109 -2
  33. package/dist/cjs/websocketClient.js +416 -74
  34. package/dist/cjs/websocketTypes.d.ts +10 -0
  35. package/dist/client.d.ts +247 -46
  36. package/dist/errors.d.ts +60 -0
  37. package/dist/errors.js +44 -0
  38. package/dist/index.d.ts +4 -4
  39. package/dist/index.js +2 -2
  40. package/dist/modelExports.d.ts +2 -0
  41. package/dist/modelExports.js +1 -0
  42. package/dist/swagger/models/PortfolioOrderDetailsSyncInfo.d.ts +60 -0
  43. package/dist/swagger/models/PortfolioOrderDetailsSyncInfo.js +45 -0
  44. package/dist/swagger/models/PortfolioOrderDetailsSyncInfoStatus.d.ts +22 -0
  45. package/dist/swagger/models/PortfolioOrderDetailsSyncInfoStatus.js +29 -0
  46. package/dist/swagger/models/PortfolioSyncInfoComplete.d.ts +7 -0
  47. package/dist/swagger/models/PortfolioSyncInfoComplete.js +6 -0
  48. package/dist/swagger/models/PortfolioSyncInfoCompleteSpecifics.d.ts +7 -0
  49. package/dist/swagger/models/PortfolioSyncInfoCompleteSpecifics.js +5 -0
  50. package/dist/swagger/models/PortfolioSyncInfoIncomplete.d.ts +7 -0
  51. package/dist/swagger/models/PortfolioSyncInfoIncomplete.js +6 -0
  52. package/dist/swagger/models/PortfolioSyncInfoIncompleteSpecifics.d.ts +7 -0
  53. package/dist/swagger/models/PortfolioSyncInfoIncompleteSpecifics.js +5 -0
  54. package/dist/swagger/models/TradeWarningReason.d.ts +1 -0
  55. package/dist/swagger/models/TradeWarningReason.js +1 -0
  56. package/dist/swagger/models/index.d.ts +2 -0
  57. package/dist/swagger/models/index.js +2 -0
  58. package/dist/tsdoc-metadata.json +1 -1
  59. package/dist/websocketClient.d.ts +109 -2
  60. package/dist/websocketClient.js +416 -74
  61. package/dist/websocketTypes.d.ts +10 -0
  62. package/package.json +10 -9
package/dist/client.d.ts CHANGED
@@ -433,7 +433,7 @@ declare interface ApiResponse<T> {
433
433
  }
434
434
 
435
435
  export declare interface Auth {
436
- getToken: () => Promise<{
436
+ getToken: (opts?: GetTokenOptions) => Promise<{
437
437
  idToken: string;
438
438
  }>;
439
439
  }
@@ -1090,6 +1090,11 @@ export declare class AuthorizedApiContext {
1090
1090
  private readonly _orderApiCryptoService;
1091
1091
  private readonly _logoutSubject;
1092
1092
  private readonly _wsClient;
1093
+ /**
1094
+ * `true` if this context created the websocket client itself and therefore has to destroy it.
1095
+ * A client passed in by the application is owned by the application.
1096
+ */
1097
+ private readonly _ownsWsClient;
1093
1098
  private readonly _cache;
1094
1099
  private readonly _exportApi;
1095
1100
  private readonly _adminApi;
@@ -1497,6 +1502,18 @@ export declare class Brokerize {
1497
1502
  }): BrokerizeWebSocketClient;
1498
1503
  }
1499
1504
 
1505
+ /**
1506
+ * Thrown when a request is made on an `AuthorizedApiContext` that was already destroyed.
1507
+ *
1508
+ * `destroy()` aborts the context's `AbortController`, so a request that is already in flight
1509
+ * rejects with a `DOMException` named `AbortError`. This error carries the same `name`, so that
1510
+ * both cases can be handled with a single check (`err.name === "AbortError"`), the way `fetch`
1511
+ * itself rejects when handed an already-aborted signal.
1512
+ */
1513
+ export declare class BrokerizeAbortError extends Error {
1514
+ constructor(msg: string);
1515
+ }
1516
+
1500
1517
  export declare interface BrokerizeConfig {
1501
1518
  fetch?: WhatWgFetch;
1502
1519
  createAbortController?: () => AbortController;
@@ -1580,10 +1597,83 @@ export declare class BrokerizeTimeoutError extends BrokerizeError {
1580
1597
  export declare interface BrokerizeWebSocketClient {
1581
1598
  subscribeInvalidate: (subscribe: SubscribeInvalidateDetails, callback: Callback) => Subscription;
1582
1599
  subscribeDecoupledOperation: (subscribe: Pick<SubscribeDecoupledOperation, "sessionId" | "decoupledOperationId">, callback: Callback) => Subscription;
1600
+ subscribeConnectionState: (callback: ConnectionStateCallback) => Subscription;
1601
+ getConnectionState: () => WebSocketConnectionState;
1602
+ reconnect: () => void;
1603
+ }
1604
+
1605
+ /**
1606
+ * Optional behavior of `BrokerizeWebSocketClientImpl`. The defaults are what an application
1607
+ * wants; this exists for the rare case that they have to be tightened.
1608
+ */
1609
+ export declare type BrokerizeWebSocketClientOptions = {
1610
+ /**
1611
+ * How often in a row the server may reject our token before the client gives up and goes
1612
+ * `fatal`. Defaults to 10, which together with the backoff spans several minutes. Mainly here so
1613
+ * that tests do not have to wait that long.
1614
+ */
1615
+ maxConsecutiveAuthFailures?: number;
1616
+ };
1617
+
1618
+ /**
1619
+ * Every error reported by the websocket client is an instance of this class, so applications can
1620
+ * handle it like any other error (`instanceof Error`, `err.message`, stack trace) and can use the
1621
+ * same error handling as for the REST API, which reports `BrokerizeError`.
1622
+ */
1623
+ export declare class BrokerizeWebSocketError extends BrokerizeError {
1624
+ /**
1625
+ * If `true`, the affected subscription is over and will not receive any further data. Errors
1626
+ * that are passed to a subscription callback are always terminal; non-terminal errors are only
1627
+ * reported via `BrokerizeWebSocketClient.subscribeConnectionState`, because the client
1628
+ * recovers from them on its own.
1629
+ */
1630
+ readonly terminal: boolean;
1631
+ /**
1632
+ * The underlying error or event, if any.
1633
+ */
1634
+ readonly cause?: unknown;
1635
+ constructor({ msg, code, httpStatusCode, terminal, cause, }: BrokerizeWebSocketErrorParams);
1583
1636
  }
1584
1637
 
1585
- declare type BrokerizeWebSocketError = {
1638
+ /**
1639
+ * The error payload as it is sent over the websocket. Applications do not see this type: the
1640
+ * websocket client converts it into a `BrokerizeWebSocketError` (the exported error class) before
1641
+ * passing it on.
1642
+ */
1643
+ declare type BrokerizeWebSocketError_2 = {
1586
1644
  message: string;
1645
+ /**
1646
+ * A stable error code, if the server sends one. Preferred over matching `message`, which is
1647
+ * meant to be human-readable and may change.
1648
+ */
1649
+ code?: string;
1650
+ };
1651
+
1652
+ /**
1653
+ * Error codes used by {@link BrokerizeWebSocketError}.
1654
+ *
1655
+ * - `AUTH`: the websocket connection could not be authenticated. Same code as a failed token
1656
+ * refresh on the REST API, so applications can treat both identically.
1657
+ * - `WEBSOCKET_CONNECTION_FAILED`: the connection could not be established or was lost
1658
+ * (network error, failed handshake, closed socket). The client retries these automatically.
1659
+ * - `WEBSOCKET_PROTOCOL_ERROR`: a message from the server could not be parsed.
1660
+ * - `WEBSOCKET_ERROR`: any other error reported by the server.
1661
+ */
1662
+ export declare type BrokerizeWebSocketErrorCode = "AUTH" | "WEBSOCKET_CONNECTION_FAILED" | "WEBSOCKET_PROTOCOL_ERROR" | "WEBSOCKET_ERROR";
1663
+
1664
+ export declare type BrokerizeWebSocketErrorParams = {
1665
+ msg: string;
1666
+ code: BrokerizeWebSocketErrorCode;
1667
+ httpStatusCode?: number;
1668
+ /**
1669
+ * See {@link BrokerizeWebSocketError.terminal}.
1670
+ */
1671
+ terminal?: boolean;
1672
+ /**
1673
+ * The underlying error or event, if any (e.g. the rejection of `Auth.getToken` or the
1674
+ * `error` event of the websocket).
1675
+ */
1676
+ cause?: unknown;
1587
1677
  };
1588
1678
 
1589
1679
  /**
@@ -1839,6 +1929,11 @@ declare function BrokerMetaToJSON(value?: BrokerMeta | null): any;
1839
1929
 
1840
1930
  declare function BrokerMetaToJSONRecursive(value?: BrokerMeta | null, ignoreParent?: boolean): any;
1841
1931
 
1932
+ /**
1933
+ * Callback of a subscription. `err` is always a `BrokerizeWebSocketError` with
1934
+ * `terminal === true`: the subscription is over and will not receive any further data. Errors the
1935
+ * client recovers from on its own are reported via `subscribeConnectionState` instead.
1936
+ */
1842
1937
  export declare type Callback<T = any> = (err: any, data: T) => void;
1843
1938
 
1844
1939
  declare interface CancelDecoupledOperationLegacyRequest {
@@ -3217,7 +3312,7 @@ export declare type CognitoConfig = {
3217
3312
 
3218
3313
  export declare type CognitoFacade = {
3219
3314
  createSession: (cognitoPoolConfig: CognitoPoolConfig, authCfg: RegisteredUserAuthContextConfiguration) => {
3220
- getToken: () => Promise<{
3315
+ getToken: (opts?: GetTokenOptions) => Promise<{
3221
3316
  idToken: string;
3222
3317
  }>;
3223
3318
  };
@@ -3383,6 +3478,8 @@ declare function ConfirmOAuthResponseToJSON(value?: ConfirmOAuthResponse | null)
3383
3478
 
3384
3479
  declare function ConfirmOAuthResponseToJSONRecursive(value?: ConfirmOAuthResponse | null, ignoreParent?: boolean): any;
3385
3480
 
3481
+ export declare type ConnectionStateCallback = (state: WebSocketConnectionState) => void;
3482
+
3386
3483
  declare interface Consume {
3387
3484
  contentType: string;
3388
3485
  }
@@ -7154,6 +7251,15 @@ declare interface GetSecurityQuotesRequest {
7154
7251
  */
7155
7252
  declare function getSizeUnitsFromConstraints(preparedTrade: PreparedTrade, orderModel: OrderModel, direction: Direction, cashAccountId: string): string[];
7156
7253
 
7254
+ export declare type GetTokenOptions = {
7255
+ /**
7256
+ * Request a fresh token even if the currently known one is not expired yet. Used by the
7257
+ * websocket client to retry once after the server rejected a token, before giving up.
7258
+ * Implementations that cannot refresh on demand may ignore this.
7259
+ */
7260
+ forceRefresh?: boolean;
7261
+ };
7262
+
7157
7263
  declare interface GetTradeDraftsRequest {
7158
7264
  take?: number;
7159
7265
  skip?: number;
@@ -7328,6 +7434,12 @@ declare type InvalidateMessage = {
7328
7434
  subscriptionId: number;
7329
7435
  };
7330
7436
 
7437
+ /**
7438
+ * Check whether the given value is a `BrokerizeWebSocketError`. Prefer this over `instanceof`,
7439
+ * which fails if more than one copy of this package ends up in a dependency tree.
7440
+ */
7441
+ export declare function isBrokerizeWebSocketError(x: unknown): x is BrokerizeWebSocketError;
7442
+
7331
7443
  declare type Json = any;
7332
7444
 
7333
7445
  declare class JSONApiResponse<T> {
@@ -7897,6 +8009,8 @@ declare namespace Models {
7897
8009
  GetCostEstimationParams,
7898
8010
  GetOrderResponse,
7899
8011
  GetPortfolioOrdersResponse,
8012
+ PortfolioOrderDetailsSyncInfo,
8013
+ PortfolioOrderDetailsSyncInfoStatus,
7900
8014
  GetPortfolioPositionsResponse,
7901
8015
  GetPortfolioQuotesResponse,
7902
8016
  GetQuoteParams,
@@ -9212,6 +9326,15 @@ declare namespace openApiClient {
9212
9326
  PortfolioCalendarItemToJSONRecursive,
9213
9327
  PortfolioCalendarItemToJSON,
9214
9328
  PortfolioCalendarItem,
9329
+ PortfolioOrderDetailsSyncInfoFromJSON,
9330
+ PortfolioOrderDetailsSyncInfoFromJSONTyped,
9331
+ PortfolioOrderDetailsSyncInfoToJSONRecursive,
9332
+ PortfolioOrderDetailsSyncInfoToJSON,
9333
+ PortfolioOrderDetailsSyncInfo,
9334
+ PortfolioOrderDetailsSyncInfoStatusFromJSON,
9335
+ PortfolioOrderDetailsSyncInfoStatusFromJSONTyped,
9336
+ PortfolioOrderDetailsSyncInfoStatusToJSON,
9337
+ PortfolioOrderDetailsSyncInfoStatus,
9215
9338
  PortfolioQuotesFromJSON,
9216
9339
  PortfolioQuotesFromJSONTyped,
9217
9340
  PortfolioQuotesToJSONRecursive,
@@ -11223,6 +11346,77 @@ declare function PortfolioFromJSON(json: any): Portfolio;
11223
11346
 
11224
11347
  declare function PortfolioFromJSONTyped(json: any, ignoreDiscriminator: boolean): Portfolio;
11225
11348
 
11349
+ /**
11350
+ * Whether the *details* of the synced orders are already known — the executions, and with them the
11351
+ * execution prices and the fees.
11352
+ *
11353
+ * This is a second, independent axis next to the sync status: a portfolio counts as `COMPLETE` as
11354
+ * soon as every order has been loaded, but some brokers (flatex) report an order's executions only
11355
+ * when that single order is fetched individually, which happens during the sync for recent orders
11356
+ * only. The remaining ones are fetched in the background afterwards.
11357
+ *
11358
+ * It matters because every evaluation that reconstructs the past — the trade list, the trade
11359
+ * statistics, the value history — is built from executions alone. An order whose details are still
11360
+ * missing contributes nothing at all to them.
11361
+ *
11362
+ * Not reported on every endpoint; absent means "no statement", not "complete".
11363
+ * @export
11364
+ * @interface PortfolioOrderDetailsSyncInfo
11365
+ */
11366
+ declare interface PortfolioOrderDetailsSyncInfo {
11367
+ /**
11368
+ * Set while `status` is `PENDING`, absent once it is `COMPLETE`.
11369
+ *
11370
+ * Evaluations are complete for everything that happened after this point in time; before it,
11371
+ * executions may still be missing. It is the timestamp of the newest order whose details are
11372
+ * still outstanding — and it is that order, not the oldest one, because the reconstruction is
11373
+ * anchored at the current holdings and works backwards: a gap only affects what lies before it.
11374
+ *
11375
+ * The boundary moves backwards as the background fetch works through the backlog, newest first.
11376
+ * It is not a progress bar for the *amount* that is still missing: details fetched out of order
11377
+ * (a user opening an old order in the app fetches it right away) close a gap behind the
11378
+ * boundary and leave it where it is.
11379
+ *
11380
+ * Caveat: for an order whose details are missing, the broker has usually only told us when it
11381
+ * was *created*, not when it executed — an order that executed considerably later than it was
11382
+ * created can therefore sit slightly after this boundary.
11383
+ * @type {Date}
11384
+ * @memberof PortfolioOrderDetailsSyncInfo
11385
+ */
11386
+ completeFrom?: Date;
11387
+ /**
11388
+ *
11389
+ * @type {PortfolioOrderDetailsSyncInfoStatus}
11390
+ * @memberof PortfolioOrderDetailsSyncInfo
11391
+ */
11392
+ status: PortfolioOrderDetailsSyncInfoStatus;
11393
+ }
11394
+
11395
+ declare function PortfolioOrderDetailsSyncInfoFromJSON(json: any): PortfolioOrderDetailsSyncInfo;
11396
+
11397
+ declare function PortfolioOrderDetailsSyncInfoFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioOrderDetailsSyncInfo;
11398
+
11399
+ /**
11400
+ *
11401
+ * @export
11402
+ */
11403
+ declare const PortfolioOrderDetailsSyncInfoStatus: {
11404
+ readonly Complete: "COMPLETE";
11405
+ readonly Pending: "PENDING";
11406
+ };
11407
+
11408
+ declare type PortfolioOrderDetailsSyncInfoStatus = (typeof PortfolioOrderDetailsSyncInfoStatus)[keyof typeof PortfolioOrderDetailsSyncInfoStatus];
11409
+
11410
+ declare function PortfolioOrderDetailsSyncInfoStatusFromJSON(json: any): PortfolioOrderDetailsSyncInfoStatus;
11411
+
11412
+ declare function PortfolioOrderDetailsSyncInfoStatusFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioOrderDetailsSyncInfoStatus;
11413
+
11414
+ declare function PortfolioOrderDetailsSyncInfoStatusToJSON(value?: PortfolioOrderDetailsSyncInfoStatus | null): any;
11415
+
11416
+ declare function PortfolioOrderDetailsSyncInfoToJSON(value?: PortfolioOrderDetailsSyncInfo | null): any;
11417
+
11418
+ declare function PortfolioOrderDetailsSyncInfoToJSONRecursive(value?: PortfolioOrderDetailsSyncInfo | null, ignoreParent?: boolean): any;
11419
+
11226
11420
  /**
11227
11421
  *
11228
11422
  * @export
@@ -11330,16 +11524,6 @@ declare type PortfolioSyncInfo = ({
11330
11524
  status: "PENDING";
11331
11525
  } & PortfolioSyncInfoPending);
11332
11526
 
11333
- /**
11334
- * brokerize
11335
- * The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
11336
- *
11337
- *
11338
- *
11339
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11340
- * https://openapi-generator.tech
11341
- * Do not edit the class manually.
11342
- */
11343
11527
  /**
11344
11528
  *
11345
11529
  * @export
@@ -11358,6 +11542,12 @@ declare interface PortfolioSyncInfoComplete {
11358
11542
  * @memberof PortfolioSyncInfoComplete
11359
11543
  */
11360
11544
  lastSync: Date;
11545
+ /**
11546
+ *
11547
+ * @type {PortfolioOrderDetailsSyncInfo}
11548
+ * @memberof PortfolioSyncInfoComplete
11549
+ */
11550
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11361
11551
  }
11362
11552
 
11363
11553
  /**
@@ -11405,16 +11595,6 @@ declare function PortfolioSyncInfoCompleteFromJSON(json: any): PortfolioSyncInfo
11405
11595
 
11406
11596
  declare function PortfolioSyncInfoCompleteFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfoComplete;
11407
11597
 
11408
- /**
11409
- * brokerize
11410
- * The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
11411
- *
11412
- *
11413
- *
11414
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11415
- * https://openapi-generator.tech
11416
- * Do not edit the class manually.
11417
- */
11418
11598
  /**
11419
11599
  *
11420
11600
  * @export
@@ -11427,6 +11607,12 @@ declare interface PortfolioSyncInfoCompleteSpecifics {
11427
11607
  * @memberof PortfolioSyncInfoCompleteSpecifics
11428
11608
  */
11429
11609
  lastSync?: Date;
11610
+ /**
11611
+ *
11612
+ * @type {PortfolioOrderDetailsSyncInfo}
11613
+ * @memberof PortfolioSyncInfoCompleteSpecifics
11614
+ */
11615
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11430
11616
  }
11431
11617
 
11432
11618
  declare function PortfolioSyncInfoCompleteSpecificsFromJSON(json: any): PortfolioSyncInfoCompleteSpecifics;
@@ -11554,16 +11740,6 @@ declare function PortfolioSyncInfoFromJSON(json: any): PortfolioSyncInfo;
11554
11740
 
11555
11741
  declare function PortfolioSyncInfoFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfo;
11556
11742
 
11557
- /**
11558
- * brokerize
11559
- * The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
11560
- *
11561
- *
11562
- *
11563
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11564
- * https://openapi-generator.tech
11565
- * Do not edit the class manually.
11566
- */
11567
11743
  /**
11568
11744
  *
11569
11745
  * @export
@@ -11582,6 +11758,12 @@ declare interface PortfolioSyncInfoIncomplete {
11582
11758
  * @memberof PortfolioSyncInfoIncomplete
11583
11759
  */
11584
11760
  lastSync: Date;
11761
+ /**
11762
+ *
11763
+ * @type {PortfolioOrderDetailsSyncInfo}
11764
+ * @memberof PortfolioSyncInfoIncomplete
11765
+ */
11766
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11585
11767
  }
11586
11768
 
11587
11769
  /**
@@ -11629,16 +11811,6 @@ declare function PortfolioSyncInfoIncompleteFromJSON(json: any): PortfolioSyncIn
11629
11811
 
11630
11812
  declare function PortfolioSyncInfoIncompleteFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfoIncomplete;
11631
11813
 
11632
- /**
11633
- * brokerize
11634
- * The brokerize API allows clients to implement multi-brokerage with a unified interface. For more information, visit brokerize.com
11635
- *
11636
- *
11637
- *
11638
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11639
- * https://openapi-generator.tech
11640
- * Do not edit the class manually.
11641
- */
11642
11814
  /**
11643
11815
  *
11644
11816
  * @export
@@ -11651,6 +11823,12 @@ declare interface PortfolioSyncInfoIncompleteSpecifics {
11651
11823
  * @memberof PortfolioSyncInfoIncompleteSpecifics
11652
11824
  */
11653
11825
  lastSync?: Date;
11826
+ /**
11827
+ *
11828
+ * @type {PortfolioOrderDetailsSyncInfo}
11829
+ * @memberof PortfolioSyncInfoIncompleteSpecifics
11830
+ */
11831
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11654
11832
  }
11655
11833
 
11656
11834
  declare function PortfolioSyncInfoIncompleteSpecificsFromJSON(json: any): PortfolioSyncInfoIncompleteSpecifics;
@@ -15221,6 +15399,7 @@ declare function TradeWarningFromJSONTyped(json: any, ignoreDiscriminator: boole
15221
15399
  declare const TradeWarningReason: {
15222
15400
  readonly ExecutionsWithoutTimestamp: "executionsWithoutTimestamp";
15223
15401
  readonly InconsistentOrderHistory: "inconsistentOrderHistory";
15402
+ readonly OrderDetailsIncomplete: "orderDetailsIncomplete";
15224
15403
  readonly PositionNotFullyExplained: "positionNotFullyExplained";
15225
15404
  readonly MissingEodPrice: "missingEodPrice";
15226
15405
  readonly MissingFxRate: "missingFxRate";
@@ -15626,8 +15805,30 @@ declare type WebSocketCommandUnsubscribe = {
15626
15805
  subscriptionId: number;
15627
15806
  };
15628
15807
 
15808
+ export declare type WebSocketConnectionState = {
15809
+ status: WebSocketConnectionStatus;
15810
+ error?: BrokerizeWebSocketError;
15811
+ };
15812
+
15813
+ /**
15814
+ * - `closed`: not connected, because nothing is subscribed.
15815
+ * - `connecting`: the first connection attempt is in progress.
15816
+ * - `open`: connected and authenticated, live updates are being delivered.
15817
+ * - `reconnecting`: the connection failed or was lost and the client is retrying. `error` holds
15818
+ * the error that caused it. Subscriptions stay alive and receive a synthetic invalidate once
15819
+ * the connection is back.
15820
+ *
15821
+ * A rejected token lands here too, so an application can show that live updates are currently
15822
+ * unavailable - and why - while the client works on getting back in, instead of having to
15823
+ * rebuild everything over a token that expired in flight.
15824
+ * - `fatal`: the client gave up and is unusable. All subscriptions were terminated with `error`.
15825
+ * This only happens after the token has been rejected over and over for several minutes, i.e.
15826
+ * when the session is gone rather than stale. Call `reconnect()` or create a new client.
15827
+ */
15828
+ export declare type WebSocketConnectionStatus = "closed" | "connecting" | "open" | "reconnecting" | "fatal";
15829
+
15629
15830
  declare type WebSocketError = {
15630
- error: BrokerizeWebSocketError;
15831
+ error: BrokerizeWebSocketError_2;
15631
15832
  };
15632
15833
 
15633
15834
  declare interface WebSocketEventMap_2 {
@@ -15641,7 +15842,7 @@ declare type WebSocketMessage = WebSocketSubscriptionMessage | WebSocketError |
15641
15842
 
15642
15843
  declare type WebSocketMessageErrorOnSubscription = {
15643
15844
  subscriptionId: number;
15644
- error: BrokerizeWebSocketError;
15845
+ error: BrokerizeWebSocketError_2;
15645
15846
  };
15646
15847
 
15647
15848
  declare type WebSocketPingMessage = {
@@ -15668,7 +15869,7 @@ declare namespace WebSocketTypes {
15668
15869
  WebSocketMessageErrorOnSubscription,
15669
15870
  InvalidateMessage,
15670
15871
  UpdateDecoupledOperationMessage,
15671
- BrokerizeWebSocketError,
15872
+ BrokerizeWebSocketError_2 as BrokerizeWebSocketError,
15672
15873
  WebSocketError,
15673
15874
  DecoupledOperationState_2 as DecoupledOperationState,
15674
15875
  DecoupledOperationStatus_2 as DecoupledOperationStatus
package/dist/errors.d.ts CHANGED
@@ -79,3 +79,63 @@ export declare class BrokerizeTimeoutError extends BrokerizeError {
79
79
  * JSON parse error.
80
80
  */
81
81
  export declare function createErrorFromResponse(response: Response): Promise<BrokerizeError>;
82
+ /**
83
+ * Error codes used by {@link BrokerizeWebSocketError}.
84
+ *
85
+ * - `AUTH`: the websocket connection could not be authenticated. Same code as a failed token
86
+ * refresh on the REST API, so applications can treat both identically.
87
+ * - `WEBSOCKET_CONNECTION_FAILED`: the connection could not be established or was lost
88
+ * (network error, failed handshake, closed socket). The client retries these automatically.
89
+ * - `WEBSOCKET_PROTOCOL_ERROR`: a message from the server could not be parsed.
90
+ * - `WEBSOCKET_ERROR`: any other error reported by the server.
91
+ */
92
+ export type BrokerizeWebSocketErrorCode = "AUTH" | "WEBSOCKET_CONNECTION_FAILED" | "WEBSOCKET_PROTOCOL_ERROR" | "WEBSOCKET_ERROR";
93
+ export type BrokerizeWebSocketErrorParams = {
94
+ msg: string;
95
+ code: BrokerizeWebSocketErrorCode;
96
+ httpStatusCode?: number;
97
+ /**
98
+ * See {@link BrokerizeWebSocketError.terminal}.
99
+ */
100
+ terminal?: boolean;
101
+ /**
102
+ * The underlying error or event, if any (e.g. the rejection of `Auth.getToken` or the
103
+ * `error` event of the websocket).
104
+ */
105
+ cause?: unknown;
106
+ };
107
+ /**
108
+ * Every error reported by the websocket client is an instance of this class, so applications can
109
+ * handle it like any other error (`instanceof Error`, `err.message`, stack trace) and can use the
110
+ * same error handling as for the REST API, which reports `BrokerizeError`.
111
+ */
112
+ export declare class BrokerizeWebSocketError extends BrokerizeError {
113
+ /**
114
+ * If `true`, the affected subscription is over and will not receive any further data. Errors
115
+ * that are passed to a subscription callback are always terminal; non-terminal errors are only
116
+ * reported via `BrokerizeWebSocketClient.subscribeConnectionState`, because the client
117
+ * recovers from them on its own.
118
+ */
119
+ readonly terminal: boolean;
120
+ /**
121
+ * The underlying error or event, if any.
122
+ */
123
+ readonly cause?: unknown;
124
+ constructor({ msg, code, httpStatusCode, terminal, cause, }: BrokerizeWebSocketErrorParams);
125
+ }
126
+ /**
127
+ * Check whether the given value is a `BrokerizeWebSocketError`. Prefer this over `instanceof`,
128
+ * which fails if more than one copy of this package ends up in a dependency tree.
129
+ */
130
+ export declare function isBrokerizeWebSocketError(x: unknown): x is BrokerizeWebSocketError;
131
+ /**
132
+ * Thrown when a request is made on an `AuthorizedApiContext` that was already destroyed.
133
+ *
134
+ * `destroy()` aborts the context's `AbortController`, so a request that is already in flight
135
+ * rejects with a `DOMException` named `AbortError`. This error carries the same `name`, so that
136
+ * both cases can be handled with a single check (`err.name === "AbortError"`), the way `fetch`
137
+ * itself rejects when handed an already-aborted signal.
138
+ */
139
+ export declare class BrokerizeAbortError extends Error {
140
+ constructor(msg: string);
141
+ }
package/dist/errors.js CHANGED
@@ -68,3 +68,47 @@ export async function createErrorFromResponse(response) {
68
68
  code: "INTERNAL_SERVER_ERROR",
69
69
  });
70
70
  }
71
+ const DEFAULT_STATUS_CODES = {
72
+ AUTH: 401,
73
+ WEBSOCKET_CONNECTION_FAILED: 503,
74
+ WEBSOCKET_PROTOCOL_ERROR: 500,
75
+ WEBSOCKET_ERROR: 500,
76
+ };
77
+ /**
78
+ * Every error reported by the websocket client is an instance of this class, so applications can
79
+ * handle it like any other error (`instanceof Error`, `err.message`, stack trace) and can use the
80
+ * same error handling as for the REST API, which reports `BrokerizeError`.
81
+ */
82
+ export class BrokerizeWebSocketError extends BrokerizeError {
83
+ constructor({ msg, code, httpStatusCode, terminal, cause, }) {
84
+ super(httpStatusCode !== null && httpStatusCode !== void 0 ? httpStatusCode : DEFAULT_STATUS_CODES[code], { msg, code });
85
+ Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain (https://stackoverflow.com/questions/41102060/typescript-extending-error-class)
86
+ this.name = "BrokerizeWebSocketError";
87
+ this.terminal = terminal !== null && terminal !== void 0 ? terminal : false;
88
+ this.cause = cause;
89
+ }
90
+ }
91
+ /**
92
+ * Check whether the given value is a `BrokerizeWebSocketError`. Prefer this over `instanceof`,
93
+ * which fails if more than one copy of this package ends up in a dependency tree.
94
+ */
95
+ export function isBrokerizeWebSocketError(x) {
96
+ return (!!x &&
97
+ typeof x === "object" &&
98
+ x.name === "BrokerizeWebSocketError");
99
+ }
100
+ /**
101
+ * Thrown when a request is made on an `AuthorizedApiContext` that was already destroyed.
102
+ *
103
+ * `destroy()` aborts the context's `AbortController`, so a request that is already in flight
104
+ * rejects with a `DOMException` named `AbortError`. This error carries the same `name`, so that
105
+ * both cases can be handled with a single check (`err.name === "AbortError"`), the way `fetch`
106
+ * itself rejects when handed an already-aborted signal.
107
+ */
108
+ export class BrokerizeAbortError extends Error {
109
+ constructor(msg) {
110
+ super(msg);
111
+ Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain (https://stackoverflow.com/questions/41102060/typescript-extending-error-class)
112
+ this.name = "AbortError";
113
+ }
114
+ }
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { Auth, AuthContextConfiguration, BrokerizeConfig, CognitoConfig, CognitoFacade, CognitoPoolConfig, GuestAuthContextConfiguration, RegisteredUserAuthContextConfiguration, TokenSet } from "./apiCtx";
1
+ import { Auth, AuthContextConfiguration, BrokerizeConfig, CognitoConfig, CognitoFacade, CognitoPoolConfig, GetTokenOptions, GuestAuthContextConfiguration, RegisteredUserAuthContextConfiguration, TokenSet } from "./apiCtx";
2
2
  import { AuthorizedApiContext } from "./authorizedApiContext";
3
- import { BrokerizeError, BrokerizeTimeoutError } from "./errors";
3
+ import { BrokerizeAbortError, BrokerizeError, BrokerizeTimeoutError, BrokerizeWebSocketError, BrokerizeWebSocketErrorCode, BrokerizeWebSocketErrorParams, isBrokerizeWebSocketError } from "./errors";
4
4
  import * as openApiClient from "./swagger";
5
5
  import * as Models from "./modelExports";
6
- import { BrokerizeWebSocketClient, Callback, Subscription } from "./websocketClient";
6
+ import { BrokerizeWebSocketClient, BrokerizeWebSocketClientOptions, Callback, ConnectionStateCallback, Subscription, WebSocketConnectionState, WebSocketConnectionStatus } from "./websocketClient";
7
7
  import * as WebSocketTypes from "./websocketTypes";
8
8
  import * as Utils from "./utils";
9
- export { BrokerizeConfig, AuthContextConfiguration, AuthorizedApiContext, BrokerizeWebSocketClient, Models, WebSocketTypes, Subscription, Callback, Utils, BrokerizeError, BrokerizeTimeoutError, Auth, TokenSet, };
9
+ export { BrokerizeConfig, AuthContextConfiguration, AuthorizedApiContext, BrokerizeWebSocketClient, Models, WebSocketTypes, Subscription, Callback, Utils, BrokerizeError, BrokerizeTimeoutError, BrokerizeWebSocketError, BrokerizeWebSocketErrorCode, BrokerizeWebSocketErrorParams, BrokerizeAbortError, GetTokenOptions, isBrokerizeWebSocketError, ConnectionStateCallback, BrokerizeWebSocketClientOptions, WebSocketConnectionState, WebSocketConnectionStatus, Auth, TokenSet, };
10
10
  export { CognitoPoolConfig, RegisteredUserAuthContextConfiguration };
11
11
  export { CognitoConfig, CognitoFacade };
12
12
  export declare class Brokerize {
package/dist/index.js CHANGED
@@ -2,13 +2,13 @@
2
2
  but reduced to the parts actually used by bg-trading. */
3
3
  import { createAuth, createConfiguration, withAcceptLanguage, } from "./apiCtx.js";
4
4
  import { AuthorizedApiContext, getWebSocketURLByBasePath, } from "./authorizedApiContext.js";
5
- import { BrokerizeError, BrokerizeTimeoutError, createErrorFromResponse, } from "./errors.js";
5
+ import { BrokerizeAbortError, BrokerizeError, BrokerizeTimeoutError, BrokerizeWebSocketError, createErrorFromResponse, isBrokerizeWebSocketError, } from "./errors.js";
6
6
  import * as openApiClient from "./swagger/index.js";
7
7
  import * as Models from "./modelExports.js";
8
8
  import { BrokerizeWebSocketClientImpl, } from "./websocketClient.js";
9
9
  import * as WebSocketTypes from "./websocketTypes.js";
10
10
  import * as Utils from "./utils.js";
11
- export { AuthorizedApiContext, Models, WebSocketTypes, Utils, BrokerizeError, BrokerizeTimeoutError, };
11
+ export { AuthorizedApiContext, Models, WebSocketTypes, Utils, BrokerizeError, BrokerizeTimeoutError, BrokerizeWebSocketError, BrokerizeAbortError, isBrokerizeWebSocketError, };
12
12
  export class Brokerize {
13
13
  constructor(cfg) {
14
14
  if (!cfg.fetch) {
@@ -86,6 +86,8 @@ export { GetBrokersResponse } from "./swagger/models/GetBrokersResponse";
86
86
  export { GetCostEstimationParams } from "./swagger/models/GetCostEstimationParams";
87
87
  export { GetOrderResponse } from "./swagger/models/GetOrderResponse";
88
88
  export { GetPortfolioOrdersResponse } from "./swagger/models/GetPortfolioOrdersResponse";
89
+ export { PortfolioOrderDetailsSyncInfo } from "./swagger/models/PortfolioOrderDetailsSyncInfo";
90
+ export { PortfolioOrderDetailsSyncInfoStatus } from "./swagger/models/PortfolioOrderDetailsSyncInfoStatus";
89
91
  export { GetPortfolioPositionsResponse } from "./swagger/models/GetPortfolioPositionsResponse";
90
92
  export { GetPortfolioQuotesResponse } from "./swagger/models/GetPortfolioQuotesResponse";
91
93
  export { GetQuoteParams } from "./swagger/models/GetQuoteParams";
@@ -9,6 +9,7 @@ export { EnableSessionTanParamsKind } from "./swagger/models/EnableSessionTanPar
9
9
  export { GenericTableRowType } from "./swagger/models/GenericTableRowType.js";
10
10
  export { GenericTableRowValueLinkValueType } from "./swagger/models/GenericTableRowValueLinkValueType.js";
11
11
  export { GenericTableRowValueType } from "./swagger/models/GenericTableRowValueType.js";
12
+ export { PortfolioOrderDetailsSyncInfoStatus } from "./swagger/models/PortfolioOrderDetailsSyncInfoStatus.js";
12
13
  export { LoginResponseState } from "./swagger/models/LoginResponseState.js";
13
14
  export { OrderExtension } from "./swagger/models/OrderExtension.js";
14
15
  export { OrderModel } from "./swagger/models/OrderModel.js";