@brokerize/client 1.11.0 → 1.12.1

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 +20 -0
  5. package/dist/authorizedApiContext.js +47 -5
  6. package/dist/cjs/apiCtx.d.ts +10 -2
  7. package/dist/cjs/apiCtx.js +4 -4
  8. package/dist/cjs/authorizedApiContext.d.ts +20 -0
  9. package/dist/cjs/authorizedApiContext.js +46 -4
  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 +118 -3
  33. package/dist/cjs/websocketClient.js +426 -74
  34. package/dist/cjs/websocketTypes.d.ts +10 -0
  35. package/dist/client.d.ts +262 -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 +118 -3
  60. package/dist/websocketClient.js +426 -74
  61. package/dist/websocketTypes.d.ts +10 -0
  62. package/package.json +10 -9
@@ -57,8 +57,18 @@ export type UpdateDecoupledOperationMessage = {
57
57
  subscriptionId: number;
58
58
  status: DecoupledOperationStatus;
59
59
  };
60
+ /**
61
+ * The error payload as it is sent over the websocket. Applications do not see this type: the
62
+ * websocket client converts it into a `BrokerizeWebSocketError` (the exported error class) before
63
+ * passing it on.
64
+ */
60
65
  export type BrokerizeWebSocketError = {
61
66
  message: string;
67
+ /**
68
+ * A stable error code, if the server sends one. Preferred over matching `message`, which is
69
+ * meant to be human-readable and may change.
70
+ */
71
+ code?: string;
62
72
  };
63
73
  export type WebSocketError = {
64
74
  error: BrokerizeWebSocketError;
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;
@@ -1099,6 +1104,21 @@ export declare class AuthorizedApiContext {
1099
1104
  private readonly _syncApi;
1100
1105
  private readonly _decoupledOperationsApi;
1101
1106
  constructor(cfg: BrokerizeConfig, auth: Auth, wsClient?: BrokerizeWebSocketClient);
1107
+ /**
1108
+ * The websocket client keeps one context around to refetch the status of a decoupled operation
1109
+ * with after an interrupted connection. That context has to outlive the connection, so it must
1110
+ * not simply be whichever one was constructed last: child contexts are commonly created per
1111
+ * request and destroyed again, and a destroyed context cannot perform that request.
1112
+ *
1113
+ * The first context attaches and keeps the client - that is the one that created it, and the
1114
+ * children, which are handed the very same client, leave it alone.
1115
+ */
1116
+ private _attachToWsClient;
1117
+ /**
1118
+ * Counterpart of `_attachToWsClient`: leave no destroyed context behind, so that a context
1119
+ * created later can take over.
1120
+ */
1121
+ private _detachFromWsClient;
1102
1122
  createChildContext(): AuthorizedApiContext;
1103
1123
  private _initRequestInit;
1104
1124
  getBrokers(): Promise<openApiClient.GetBrokersResponse>;
@@ -1497,6 +1517,18 @@ export declare class Brokerize {
1497
1517
  }): BrokerizeWebSocketClient;
1498
1518
  }
1499
1519
 
1520
+ /**
1521
+ * Thrown when a request is made on an `AuthorizedApiContext` that was already destroyed.
1522
+ *
1523
+ * `destroy()` aborts the context's `AbortController`, so a request that is already in flight
1524
+ * rejects with a `DOMException` named `AbortError`. This error carries the same `name`, so that
1525
+ * both cases can be handled with a single check (`err.name === "AbortError"`), the way `fetch`
1526
+ * itself rejects when handed an already-aborted signal.
1527
+ */
1528
+ export declare class BrokerizeAbortError extends Error {
1529
+ constructor(msg: string);
1530
+ }
1531
+
1500
1532
  export declare interface BrokerizeConfig {
1501
1533
  fetch?: WhatWgFetch;
1502
1534
  createAbortController?: () => AbortController;
@@ -1580,10 +1612,83 @@ export declare class BrokerizeTimeoutError extends BrokerizeError {
1580
1612
  export declare interface BrokerizeWebSocketClient {
1581
1613
  subscribeInvalidate: (subscribe: SubscribeInvalidateDetails, callback: Callback) => Subscription;
1582
1614
  subscribeDecoupledOperation: (subscribe: Pick<SubscribeDecoupledOperation, "sessionId" | "decoupledOperationId">, callback: Callback) => Subscription;
1615
+ subscribeConnectionState: (callback: ConnectionStateCallback) => Subscription;
1616
+ getConnectionState: () => WebSocketConnectionState;
1617
+ reconnect: () => void;
1583
1618
  }
1584
1619
 
1585
- declare type BrokerizeWebSocketError = {
1620
+ /**
1621
+ * Optional behavior of `BrokerizeWebSocketClientImpl`. The defaults are what an application
1622
+ * wants; this exists for the rare case that they have to be tightened.
1623
+ */
1624
+ export declare type BrokerizeWebSocketClientOptions = {
1625
+ /**
1626
+ * How often in a row the server may reject our token before the client gives up and goes
1627
+ * `fatal`. Defaults to 10, which together with the backoff spans several minutes. Mainly here so
1628
+ * that tests do not have to wait that long.
1629
+ */
1630
+ maxConsecutiveAuthFailures?: number;
1631
+ };
1632
+
1633
+ /**
1634
+ * Every error reported by the websocket client is an instance of this class, so applications can
1635
+ * handle it like any other error (`instanceof Error`, `err.message`, stack trace) and can use the
1636
+ * same error handling as for the REST API, which reports `BrokerizeError`.
1637
+ */
1638
+ export declare class BrokerizeWebSocketError extends BrokerizeError {
1639
+ /**
1640
+ * If `true`, the affected subscription is over and will not receive any further data. Errors
1641
+ * that are passed to a subscription callback are always terminal; non-terminal errors are only
1642
+ * reported via `BrokerizeWebSocketClient.subscribeConnectionState`, because the client
1643
+ * recovers from them on its own.
1644
+ */
1645
+ readonly terminal: boolean;
1646
+ /**
1647
+ * The underlying error or event, if any.
1648
+ */
1649
+ readonly cause?: unknown;
1650
+ constructor({ msg, code, httpStatusCode, terminal, cause, }: BrokerizeWebSocketErrorParams);
1651
+ }
1652
+
1653
+ /**
1654
+ * The error payload as it is sent over the websocket. Applications do not see this type: the
1655
+ * websocket client converts it into a `BrokerizeWebSocketError` (the exported error class) before
1656
+ * passing it on.
1657
+ */
1658
+ declare type BrokerizeWebSocketError_2 = {
1586
1659
  message: string;
1660
+ /**
1661
+ * A stable error code, if the server sends one. Preferred over matching `message`, which is
1662
+ * meant to be human-readable and may change.
1663
+ */
1664
+ code?: string;
1665
+ };
1666
+
1667
+ /**
1668
+ * Error codes used by {@link BrokerizeWebSocketError}.
1669
+ *
1670
+ * - `AUTH`: the websocket connection could not be authenticated. Same code as a failed token
1671
+ * refresh on the REST API, so applications can treat both identically.
1672
+ * - `WEBSOCKET_CONNECTION_FAILED`: the connection could not be established or was lost
1673
+ * (network error, failed handshake, closed socket). The client retries these automatically.
1674
+ * - `WEBSOCKET_PROTOCOL_ERROR`: a message from the server could not be parsed.
1675
+ * - `WEBSOCKET_ERROR`: any other error reported by the server.
1676
+ */
1677
+ export declare type BrokerizeWebSocketErrorCode = "AUTH" | "WEBSOCKET_CONNECTION_FAILED" | "WEBSOCKET_PROTOCOL_ERROR" | "WEBSOCKET_ERROR";
1678
+
1679
+ export declare type BrokerizeWebSocketErrorParams = {
1680
+ msg: string;
1681
+ code: BrokerizeWebSocketErrorCode;
1682
+ httpStatusCode?: number;
1683
+ /**
1684
+ * See {@link BrokerizeWebSocketError.terminal}.
1685
+ */
1686
+ terminal?: boolean;
1687
+ /**
1688
+ * The underlying error or event, if any (e.g. the rejection of `Auth.getToken` or the
1689
+ * `error` event of the websocket).
1690
+ */
1691
+ cause?: unknown;
1587
1692
  };
1588
1693
 
1589
1694
  /**
@@ -1839,6 +1944,11 @@ declare function BrokerMetaToJSON(value?: BrokerMeta | null): any;
1839
1944
 
1840
1945
  declare function BrokerMetaToJSONRecursive(value?: BrokerMeta | null, ignoreParent?: boolean): any;
1841
1946
 
1947
+ /**
1948
+ * Callback of a subscription. `err` is always a `BrokerizeWebSocketError` with
1949
+ * `terminal === true`: the subscription is over and will not receive any further data. Errors the
1950
+ * client recovers from on its own are reported via `subscribeConnectionState` instead.
1951
+ */
1842
1952
  export declare type Callback<T = any> = (err: any, data: T) => void;
1843
1953
 
1844
1954
  declare interface CancelDecoupledOperationLegacyRequest {
@@ -3217,7 +3327,7 @@ export declare type CognitoConfig = {
3217
3327
 
3218
3328
  export declare type CognitoFacade = {
3219
3329
  createSession: (cognitoPoolConfig: CognitoPoolConfig, authCfg: RegisteredUserAuthContextConfiguration) => {
3220
- getToken: () => Promise<{
3330
+ getToken: (opts?: GetTokenOptions) => Promise<{
3221
3331
  idToken: string;
3222
3332
  }>;
3223
3333
  };
@@ -3383,6 +3493,8 @@ declare function ConfirmOAuthResponseToJSON(value?: ConfirmOAuthResponse | null)
3383
3493
 
3384
3494
  declare function ConfirmOAuthResponseToJSONRecursive(value?: ConfirmOAuthResponse | null, ignoreParent?: boolean): any;
3385
3495
 
3496
+ export declare type ConnectionStateCallback = (state: WebSocketConnectionState) => void;
3497
+
3386
3498
  declare interface Consume {
3387
3499
  contentType: string;
3388
3500
  }
@@ -7154,6 +7266,15 @@ declare interface GetSecurityQuotesRequest {
7154
7266
  */
7155
7267
  declare function getSizeUnitsFromConstraints(preparedTrade: PreparedTrade, orderModel: OrderModel, direction: Direction, cashAccountId: string): string[];
7156
7268
 
7269
+ export declare type GetTokenOptions = {
7270
+ /**
7271
+ * Request a fresh token even if the currently known one is not expired yet. Used by the
7272
+ * websocket client to retry once after the server rejected a token, before giving up.
7273
+ * Implementations that cannot refresh on demand may ignore this.
7274
+ */
7275
+ forceRefresh?: boolean;
7276
+ };
7277
+
7157
7278
  declare interface GetTradeDraftsRequest {
7158
7279
  take?: number;
7159
7280
  skip?: number;
@@ -7328,6 +7449,12 @@ declare type InvalidateMessage = {
7328
7449
  subscriptionId: number;
7329
7450
  };
7330
7451
 
7452
+ /**
7453
+ * Check whether the given value is a `BrokerizeWebSocketError`. Prefer this over `instanceof`,
7454
+ * which fails if more than one copy of this package ends up in a dependency tree.
7455
+ */
7456
+ export declare function isBrokerizeWebSocketError(x: unknown): x is BrokerizeWebSocketError;
7457
+
7331
7458
  declare type Json = any;
7332
7459
 
7333
7460
  declare class JSONApiResponse<T> {
@@ -7897,6 +8024,8 @@ declare namespace Models {
7897
8024
  GetCostEstimationParams,
7898
8025
  GetOrderResponse,
7899
8026
  GetPortfolioOrdersResponse,
8027
+ PortfolioOrderDetailsSyncInfo,
8028
+ PortfolioOrderDetailsSyncInfoStatus,
7900
8029
  GetPortfolioPositionsResponse,
7901
8030
  GetPortfolioQuotesResponse,
7902
8031
  GetQuoteParams,
@@ -9212,6 +9341,15 @@ declare namespace openApiClient {
9212
9341
  PortfolioCalendarItemToJSONRecursive,
9213
9342
  PortfolioCalendarItemToJSON,
9214
9343
  PortfolioCalendarItem,
9344
+ PortfolioOrderDetailsSyncInfoFromJSON,
9345
+ PortfolioOrderDetailsSyncInfoFromJSONTyped,
9346
+ PortfolioOrderDetailsSyncInfoToJSONRecursive,
9347
+ PortfolioOrderDetailsSyncInfoToJSON,
9348
+ PortfolioOrderDetailsSyncInfo,
9349
+ PortfolioOrderDetailsSyncInfoStatusFromJSON,
9350
+ PortfolioOrderDetailsSyncInfoStatusFromJSONTyped,
9351
+ PortfolioOrderDetailsSyncInfoStatusToJSON,
9352
+ PortfolioOrderDetailsSyncInfoStatus,
9215
9353
  PortfolioQuotesFromJSON,
9216
9354
  PortfolioQuotesFromJSONTyped,
9217
9355
  PortfolioQuotesToJSONRecursive,
@@ -11223,6 +11361,77 @@ declare function PortfolioFromJSON(json: any): Portfolio;
11223
11361
 
11224
11362
  declare function PortfolioFromJSONTyped(json: any, ignoreDiscriminator: boolean): Portfolio;
11225
11363
 
11364
+ /**
11365
+ * Whether the *details* of the synced orders are already known — the executions, and with them the
11366
+ * execution prices and the fees.
11367
+ *
11368
+ * This is a second, independent axis next to the sync status: a portfolio counts as `COMPLETE` as
11369
+ * soon as every order has been loaded, but some brokers (flatex) report an order's executions only
11370
+ * when that single order is fetched individually, which happens during the sync for recent orders
11371
+ * only. The remaining ones are fetched in the background afterwards.
11372
+ *
11373
+ * It matters because every evaluation that reconstructs the past — the trade list, the trade
11374
+ * statistics, the value history — is built from executions alone. An order whose details are still
11375
+ * missing contributes nothing at all to them.
11376
+ *
11377
+ * Not reported on every endpoint; absent means "no statement", not "complete".
11378
+ * @export
11379
+ * @interface PortfolioOrderDetailsSyncInfo
11380
+ */
11381
+ declare interface PortfolioOrderDetailsSyncInfo {
11382
+ /**
11383
+ * Set while `status` is `PENDING`, absent once it is `COMPLETE`.
11384
+ *
11385
+ * Evaluations are complete for everything that happened after this point in time; before it,
11386
+ * executions may still be missing. It is the timestamp of the newest order whose details are
11387
+ * still outstanding — and it is that order, not the oldest one, because the reconstruction is
11388
+ * anchored at the current holdings and works backwards: a gap only affects what lies before it.
11389
+ *
11390
+ * The boundary moves backwards as the background fetch works through the backlog, newest first.
11391
+ * It is not a progress bar for the *amount* that is still missing: details fetched out of order
11392
+ * (a user opening an old order in the app fetches it right away) close a gap behind the
11393
+ * boundary and leave it where it is.
11394
+ *
11395
+ * Caveat: for an order whose details are missing, the broker has usually only told us when it
11396
+ * was *created*, not when it executed — an order that executed considerably later than it was
11397
+ * created can therefore sit slightly after this boundary.
11398
+ * @type {Date}
11399
+ * @memberof PortfolioOrderDetailsSyncInfo
11400
+ */
11401
+ completeFrom?: Date;
11402
+ /**
11403
+ *
11404
+ * @type {PortfolioOrderDetailsSyncInfoStatus}
11405
+ * @memberof PortfolioOrderDetailsSyncInfo
11406
+ */
11407
+ status: PortfolioOrderDetailsSyncInfoStatus;
11408
+ }
11409
+
11410
+ declare function PortfolioOrderDetailsSyncInfoFromJSON(json: any): PortfolioOrderDetailsSyncInfo;
11411
+
11412
+ declare function PortfolioOrderDetailsSyncInfoFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioOrderDetailsSyncInfo;
11413
+
11414
+ /**
11415
+ *
11416
+ * @export
11417
+ */
11418
+ declare const PortfolioOrderDetailsSyncInfoStatus: {
11419
+ readonly Complete: "COMPLETE";
11420
+ readonly Pending: "PENDING";
11421
+ };
11422
+
11423
+ declare type PortfolioOrderDetailsSyncInfoStatus = (typeof PortfolioOrderDetailsSyncInfoStatus)[keyof typeof PortfolioOrderDetailsSyncInfoStatus];
11424
+
11425
+ declare function PortfolioOrderDetailsSyncInfoStatusFromJSON(json: any): PortfolioOrderDetailsSyncInfoStatus;
11426
+
11427
+ declare function PortfolioOrderDetailsSyncInfoStatusFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioOrderDetailsSyncInfoStatus;
11428
+
11429
+ declare function PortfolioOrderDetailsSyncInfoStatusToJSON(value?: PortfolioOrderDetailsSyncInfoStatus | null): any;
11430
+
11431
+ declare function PortfolioOrderDetailsSyncInfoToJSON(value?: PortfolioOrderDetailsSyncInfo | null): any;
11432
+
11433
+ declare function PortfolioOrderDetailsSyncInfoToJSONRecursive(value?: PortfolioOrderDetailsSyncInfo | null, ignoreParent?: boolean): any;
11434
+
11226
11435
  /**
11227
11436
  *
11228
11437
  * @export
@@ -11330,16 +11539,6 @@ declare type PortfolioSyncInfo = ({
11330
11539
  status: "PENDING";
11331
11540
  } & PortfolioSyncInfoPending);
11332
11541
 
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
11542
  /**
11344
11543
  *
11345
11544
  * @export
@@ -11358,6 +11557,12 @@ declare interface PortfolioSyncInfoComplete {
11358
11557
  * @memberof PortfolioSyncInfoComplete
11359
11558
  */
11360
11559
  lastSync: Date;
11560
+ /**
11561
+ *
11562
+ * @type {PortfolioOrderDetailsSyncInfo}
11563
+ * @memberof PortfolioSyncInfoComplete
11564
+ */
11565
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11361
11566
  }
11362
11567
 
11363
11568
  /**
@@ -11405,16 +11610,6 @@ declare function PortfolioSyncInfoCompleteFromJSON(json: any): PortfolioSyncInfo
11405
11610
 
11406
11611
  declare function PortfolioSyncInfoCompleteFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfoComplete;
11407
11612
 
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
11613
  /**
11419
11614
  *
11420
11615
  * @export
@@ -11427,6 +11622,12 @@ declare interface PortfolioSyncInfoCompleteSpecifics {
11427
11622
  * @memberof PortfolioSyncInfoCompleteSpecifics
11428
11623
  */
11429
11624
  lastSync?: Date;
11625
+ /**
11626
+ *
11627
+ * @type {PortfolioOrderDetailsSyncInfo}
11628
+ * @memberof PortfolioSyncInfoCompleteSpecifics
11629
+ */
11630
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11430
11631
  }
11431
11632
 
11432
11633
  declare function PortfolioSyncInfoCompleteSpecificsFromJSON(json: any): PortfolioSyncInfoCompleteSpecifics;
@@ -11554,16 +11755,6 @@ declare function PortfolioSyncInfoFromJSON(json: any): PortfolioSyncInfo;
11554
11755
 
11555
11756
  declare function PortfolioSyncInfoFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfo;
11556
11757
 
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
11758
  /**
11568
11759
  *
11569
11760
  * @export
@@ -11582,6 +11773,12 @@ declare interface PortfolioSyncInfoIncomplete {
11582
11773
  * @memberof PortfolioSyncInfoIncomplete
11583
11774
  */
11584
11775
  lastSync: Date;
11776
+ /**
11777
+ *
11778
+ * @type {PortfolioOrderDetailsSyncInfo}
11779
+ * @memberof PortfolioSyncInfoIncomplete
11780
+ */
11781
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11585
11782
  }
11586
11783
 
11587
11784
  /**
@@ -11629,16 +11826,6 @@ declare function PortfolioSyncInfoIncompleteFromJSON(json: any): PortfolioSyncIn
11629
11826
 
11630
11827
  declare function PortfolioSyncInfoIncompleteFromJSONTyped(json: any, ignoreDiscriminator: boolean): PortfolioSyncInfoIncomplete;
11631
11828
 
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
11829
  /**
11643
11830
  *
11644
11831
  * @export
@@ -11651,6 +11838,12 @@ declare interface PortfolioSyncInfoIncompleteSpecifics {
11651
11838
  * @memberof PortfolioSyncInfoIncompleteSpecifics
11652
11839
  */
11653
11840
  lastSync?: Date;
11841
+ /**
11842
+ *
11843
+ * @type {PortfolioOrderDetailsSyncInfo}
11844
+ * @memberof PortfolioSyncInfoIncompleteSpecifics
11845
+ */
11846
+ orderDetails?: PortfolioOrderDetailsSyncInfo;
11654
11847
  }
11655
11848
 
11656
11849
  declare function PortfolioSyncInfoIncompleteSpecificsFromJSON(json: any): PortfolioSyncInfoIncompleteSpecifics;
@@ -15221,6 +15414,7 @@ declare function TradeWarningFromJSONTyped(json: any, ignoreDiscriminator: boole
15221
15414
  declare const TradeWarningReason: {
15222
15415
  readonly ExecutionsWithoutTimestamp: "executionsWithoutTimestamp";
15223
15416
  readonly InconsistentOrderHistory: "inconsistentOrderHistory";
15417
+ readonly OrderDetailsIncomplete: "orderDetailsIncomplete";
15224
15418
  readonly PositionNotFullyExplained: "positionNotFullyExplained";
15225
15419
  readonly MissingEodPrice: "missingEodPrice";
15226
15420
  readonly MissingFxRate: "missingFxRate";
@@ -15626,8 +15820,30 @@ declare type WebSocketCommandUnsubscribe = {
15626
15820
  subscriptionId: number;
15627
15821
  };
15628
15822
 
15823
+ export declare type WebSocketConnectionState = {
15824
+ status: WebSocketConnectionStatus;
15825
+ error?: BrokerizeWebSocketError;
15826
+ };
15827
+
15828
+ /**
15829
+ * - `closed`: not connected, because nothing is subscribed.
15830
+ * - `connecting`: the first connection attempt is in progress.
15831
+ * - `open`: connected and authenticated, live updates are being delivered.
15832
+ * - `reconnecting`: the connection failed or was lost and the client is retrying. `error` holds
15833
+ * the error that caused it. Subscriptions stay alive and receive a synthetic invalidate once
15834
+ * the connection is back.
15835
+ *
15836
+ * A rejected token lands here too, so an application can show that live updates are currently
15837
+ * unavailable - and why - while the client works on getting back in, instead of having to
15838
+ * rebuild everything over a token that expired in flight.
15839
+ * - `fatal`: the client gave up and is unusable. All subscriptions were terminated with `error`.
15840
+ * This only happens after the token has been rejected over and over for several minutes, i.e.
15841
+ * when the session is gone rather than stale. Call `reconnect()` or create a new client.
15842
+ */
15843
+ export declare type WebSocketConnectionStatus = "closed" | "connecting" | "open" | "reconnecting" | "fatal";
15844
+
15629
15845
  declare type WebSocketError = {
15630
- error: BrokerizeWebSocketError;
15846
+ error: BrokerizeWebSocketError_2;
15631
15847
  };
15632
15848
 
15633
15849
  declare interface WebSocketEventMap_2 {
@@ -15641,7 +15857,7 @@ declare type WebSocketMessage = WebSocketSubscriptionMessage | WebSocketError |
15641
15857
 
15642
15858
  declare type WebSocketMessageErrorOnSubscription = {
15643
15859
  subscriptionId: number;
15644
- error: BrokerizeWebSocketError;
15860
+ error: BrokerizeWebSocketError_2;
15645
15861
  };
15646
15862
 
15647
15863
  declare type WebSocketPingMessage = {
@@ -15668,7 +15884,7 @@ declare namespace WebSocketTypes {
15668
15884
  WebSocketMessageErrorOnSubscription,
15669
15885
  InvalidateMessage,
15670
15886
  UpdateDecoupledOperationMessage,
15671
- BrokerizeWebSocketError,
15887
+ BrokerizeWebSocketError_2 as BrokerizeWebSocketError,
15672
15888
  WebSocketError,
15673
15889
  DecoupledOperationState_2 as DecoupledOperationState,
15674
15890
  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";