@flexemarkets/fm-sdk 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -3,10 +3,12 @@
3
3
  *
4
4
  * Port of fm.client (Python) / fm.Flexemarkets (Java).
5
5
  */
6
- import type { Account, Allotment, ClientConnection, Holding, ManagerOtpBundle, Market, MarketCall, Marketplace, Order, ParticipantState, Person, Security, Session, TickGrid, Token, Widget, WidgetPush, MarketplaceRobot, RobotParameterConfig, RobotParameterControl } from "./types.js";
6
+ import type { Account, Allotment, CallIndicative, CurrentSession, ClientConnection, Holding, ManagerOtpBundle, Market, MarketCall, Marketplace, Order, ParticipantState, Person, Security, Session, TickGrid, Token, Widget, WidgetPush, MarketplaceRobot, RobotParameterConfig, RobotParameterControl } from "./types.js";
7
7
  import { EventListener, type EventCallback } from "./stomp.js";
8
+ import { type PendingOrder } from "./order-stream.js";
8
9
  import { type Desk, type Subscription } from "./desk.js";
9
10
  import type { Snapshot } from "./snapshot.js";
11
+ import { Page } from "./page.js";
10
12
  export declare const DEFAULT_ENDPOINT = "https://api.flexemarkets.com";
11
13
  /**
12
14
  * Base of every Flexemarkets error.
@@ -46,6 +48,19 @@ export declare class ConnectionFailedError extends FlexemarketsError {
46
48
  }
47
49
  export declare class ConfigurationError extends FlexemarketsError {
48
50
  }
51
+ /**
52
+ * An order was sent and no answer to it can now arrive.
53
+ *
54
+ * Not a refusal: fm-server may well have placed it. Thrown for an order sent
55
+ * over the socket that was still unanswered when its stream closed. Placing it
56
+ * again under a new submission risks holding the position twice; read the
57
+ * book, or the orders, to learn whether it stands. `submissionId` is the id it
58
+ * was sent under, which the order carries if it was placed.
59
+ */
60
+ export declare class OrderOutcomeUnknownError extends FlexemarketsError {
61
+ readonly submissionId: string | null;
62
+ constructor(message: string, submissionId?: string | null);
63
+ }
49
64
  /**
50
65
  * A response the SDK has no better name for, carrying its status and body.
51
66
  *
@@ -99,6 +114,8 @@ export declare function parseAccount(data: JsonObject | null | undefined): Accou
99
114
  export declare function parseToken(data: JsonObject): Token;
100
115
  export declare function parseSecurity(data: JsonObject): Security;
101
116
  export declare function parseMarket(data: JsonObject): Market;
117
+ export declare function parseCurrentSession(data: JsonObject): CurrentSession;
118
+ export declare function parseCallIndicative(data: JsonObject): CallIndicative;
102
119
  export declare function parseMarketCall(data: JsonObject): MarketCall;
103
120
  export declare function parseMarketplace(data: JsonObject): Marketplace;
104
121
  export declare function parseSession(data: JsonObject): Session;
@@ -155,6 +172,12 @@ export declare function loadConfig(): Record<string, string>;
155
172
  * order carried the whole JSON document.
156
173
  */
157
174
  export declare function detail(body: string): string;
175
+ /**
176
+ * The error for a refusal with this status and failure body. REST reads the
177
+ * status off the response; the socket's ORDER-REJECTED carries it in the body.
178
+ * One mapping, so an order refused either way throws the same thing.
179
+ */
180
+ export declare function refused(status: number, body: string): FlexemarketsError;
158
181
  /** How long a request may take, start to finish, before it is given up. */
159
182
  export declare const REQUEST_TIMEOUT_MS = 30000;
160
183
  /** The timeout in force: {@link REQUEST_TIMEOUT_MS}, unless a test has shortened it. */
@@ -233,6 +256,14 @@ export declare class Flexemarkets {
233
256
  * `Snapshot.NO_SEQ` when the header is absent.
234
257
  */
235
258
  private _getSnapshot;
259
+ /** GET a body the answer needs a response header beside: a snapshot's sequence, a page's next link. */
260
+ private _getRead;
261
+ /**
262
+ * A page of a collection: `url` with `?limit=` and `?before=`, and the
263
+ * `before` of the page after it read from the `Link: <...>; rel="next"` the
264
+ * server sends while older rows remain.
265
+ */
266
+ private _page;
236
267
  /** PATCH with a JSON body -- the shape every session transition takes. */
237
268
  private _patch;
238
269
  /** PUT with a JSON body -- a robot parameter's configuration, say. */
@@ -273,6 +304,11 @@ export declare class Flexemarkets {
273
304
  deleteMyAccount(): Promise<void>;
274
305
  /** Every account on the server. Admin-only. */
275
306
  accounts(): Promise<Account[]>;
307
+ /**
308
+ * A page of `accounts()`: the newest `limit`, or of those whose id is below
309
+ * `before` -- a page's `next`. The server answers at most 5,000.
310
+ */
311
+ accountsPage(limit: number, before?: number): Promise<Page<Account>>;
276
312
  /** Delete an account. Destructive, and takes its users with it. */
277
313
  deleteAccount(accountId: number): Promise<void>;
278
314
  /** Create a user in the caller's account. */
@@ -301,8 +337,14 @@ export declare class Flexemarkets {
301
337
  * the latter. `carry` is whether what a call leaves unfilled waits for the
302
338
  * next one rather than being cancelled. A call market cannot be private, so
303
339
  * there is no flag for it here; the server refuses the combination.
340
+ *
341
+ * `callBook` is what the book shows during the call:
342
+ * {@link MARKET_CALL_BOOK_SEALED}, a participant's own orders only, or
343
+ * {@link MARKET_CALL_BOOK_INDICATIVE}, also the price it would clear at now
344
+ * and the volume. Left out, the server makes it sealed. Needs fm-server
345
+ * 4.17; an older one ignores it.
304
346
  */
305
- createCallMarket(marketplaceId: number, symbol: string, name: string, price: TickGrid, units?: TickGrid, intervalSeconds?: number | null, carry?: boolean): Promise<Market>;
347
+ createCallMarket(marketplaceId: number, symbol: string, name: string, price: TickGrid, units?: TickGrid, intervalSeconds?: number | null, carry?: boolean, callBook?: string): Promise<Market>;
306
348
  /**
307
349
  * Mint one-time passcodes for the given users.
308
350
  *
@@ -321,6 +363,15 @@ export declare class Flexemarkets {
321
363
  * header, where 0.3 posted it as a multipart upload to an `/uploads`
322
364
  * segment. Bytes, not a string, so the file's own encoding survives.
323
365
  */
366
+ /**
367
+ * Send a create under an `Idempotency-Key`, and once more under the same key
368
+ * if its answer was lost. A create that lost its connection may or may not
369
+ * have landed; fm-server 4.17 answers a key it already holds with what it
370
+ * answered the first time (its IdempotencyFilter), so the resend makes one
371
+ * marketplace, market or call, never two. Orders do the same with their own
372
+ * `submissionId`.
373
+ */
374
+ private _create;
324
375
  private _sendCsv;
325
376
  /** CSV as the request body, declared text/csv; see {@link _sendCsv}. */
326
377
  private _sendCsvContent;
@@ -333,8 +384,36 @@ export declare class Flexemarkets {
333
384
  /** The V1 route of one marketplace, under which nearly everything lives. */
334
385
  private _marketplace;
335
386
  marketplaces(): Promise<Marketplace[]>;
387
+ /**
388
+ * A page of `marketplaces()`: the newest `limit`, or of those whose id is below
389
+ * `before` -- a page's `next`. The server answers at most 5,000.
390
+ */
391
+ marketplacesPage(limit: number, before?: number): Promise<Page<Marketplace>>;
392
+ /**
393
+ * Each marketplace `marketplaces()` lists that has a session, with that
394
+ * session: one read where `session()` would be one per marketplace. A
395
+ * marketplace that has never opened a session is left out.
396
+ */
397
+ currentSessions(): Promise<CurrentSession[]>;
398
+ /**
399
+ * A page of `currentSessions()`, paged by marketplace as `marketplacesPage()`
400
+ * pages: the current sessions of exactly the marketplaces that page holds. One
401
+ * with no session is left out, so a page can hold fewer rows than `limit` and
402
+ * still have a `next`.
403
+ */
404
+ currentSessionsPage(limit: number, before?: number): Promise<Page<CurrentSession>>;
336
405
  marketplace(marketplaceId: number): Promise<Marketplace>;
337
406
  markets(marketplaceId: number): Promise<Market[]>;
407
+ /**
408
+ * What an indicative call market's book would clear at now: the price and
409
+ * volume a call would make, read on subscribe. The stream then delivers
410
+ * each change as a {@link CallIndicative}; apply those with a higher `seq`
411
+ * for the same session.
412
+ *
413
+ * Only for a market that `showsIndicative()`, while a session is open; the
414
+ * server refuses a sealed market, a continuous one, or no session.
415
+ */
416
+ indicative(marketplaceId: number, marketId: number): Promise<CallIndicative>;
338
417
  /**
339
418
  * The token this connection signed in with.
340
419
  *
@@ -362,6 +441,11 @@ export declare class Flexemarkets {
362
441
  * already does.
363
442
  */
364
443
  sessions(marketplaceId: number): Promise<Session[]>;
444
+ /**
445
+ * A page of `sessions()`: the newest `limit`, or of those whose id is below
446
+ * `before` -- a page's `next`. The server answers at most 5,000.
447
+ */
448
+ sessionsPage(marketplaceId: number, limit: number, before?: number): Promise<Page<Session>>;
365
449
  session(marketplaceId: number): Promise<Session>;
366
450
  /**
367
451
  * Place a limit order.
@@ -381,6 +465,28 @@ export declare class Flexemarkets {
381
465
  ownerTargetId?: number;
382
466
  clientDescription?: string;
383
467
  }): Promise<Order>;
468
+ /**
469
+ * Place a limit order without waiting for the answer.
470
+ *
471
+ * The order goes over the marketplace's socket and the {@link PendingOrder}
472
+ * this resolves to is there at once: the next order can go before this one
473
+ * is matched, and fm-server still matches them in the order sent. Its
474
+ * `result()` is the order, or the refusal {@link submitLimit} would have
475
+ * thrown -- or {@link OrderOutcomeUnknownError} if the socket closed before
476
+ * the answer came. The socket opens with the first order sent this way and
477
+ * stays open until {@link close}; at most `MAX_IN_FLIGHT` orders are
478
+ * unanswered at once, and this waits, in turn, while they are. The arguments
479
+ * are {@link submitLimit}'s. See docs/SUBMIT-RATE.md.
480
+ */
481
+ sendLimit(marketplaceId: number, marketId: number, side: string, units: number, price: number, options?: {
482
+ ownerTarget?: string;
483
+ ownerTargetId?: number;
484
+ clientDescription?: string;
485
+ }): Promise<PendingOrder>;
486
+ /** The body of a limit order, named with a fresh submission id. */
487
+ private _limitOrder;
488
+ /** The marketplace's order socket, opened on first use; one open for concurrent first callers. */
489
+ private _orderStream;
384
490
  /**
385
491
  * Cross the book: buy at the highest price this market allows, sell at the
386
492
  * lowest. Immediate or cancel — whatever does not fill is cancelled.
@@ -447,6 +553,12 @@ export declare class Flexemarkets {
447
553
  symbol?: string;
448
554
  sessionIds?: number[];
449
555
  }): Promise<Order[]>;
556
+ /**
557
+ * A page of `orders()` with no filter -- cancellations left out, as there:
558
+ * the newest `limit`, or of those whose id is below `before` -- a page's
559
+ * `next`. The server answers at most 5,000.
560
+ */
561
+ ordersPage(marketplaceId: number, limit: number, before?: number): Promise<Page<Order>>;
450
562
  /**
451
563
  * One market's traded legs, as many as the server gives in one read
452
564
  * ({@link MAX_TRADED_LEGS}), in the server's order.
@@ -468,6 +580,11 @@ export declare class Flexemarkets {
468
580
  * filter on the result.
469
581
  */
470
582
  connections(marketplaceId: number): Promise<ClientConnection[]>;
583
+ /**
584
+ * A page of `connections()`: the newest `limit`, or of those whose id is below
585
+ * `before` -- a page's `next`. The server answers at most 5,000.
586
+ */
587
+ connectionsPage(marketplaceId: number, limit: number, before?: number): Promise<Page<ClientConnection>>;
471
588
  /**
472
589
  * Create a marketplace from its JSON definition, returning what was made.
473
590
  *
@@ -496,6 +613,11 @@ export declare class Flexemarkets {
496
613
  private _sessionState;
497
614
  /** Everyone in the caller's account. */
498
615
  users(): Promise<Person[]>;
616
+ /**
617
+ * A page of `users()`: the newest `limit`, or of those whose id is below
618
+ * `before` -- a page's `next`. The server answers at most 5,000.
619
+ */
620
+ usersPage(limit: number, before?: number): Promise<Page<Person>>;
499
621
  /** The opening positions of one allocation. */
500
622
  allotments(marketplaceId: number, allocationId: number): Promise<Allotment[]>;
501
623
  /**
@@ -596,6 +718,11 @@ export declare class Flexemarkets {
596
718
  clearNow(marketplaceId: number, marketId: number): Promise<MarketCall>;
597
719
  /** Every call the marketplace's call markets have made, oldest first; one session's with `sessionId`. */
598
720
  calls(marketplaceId: number, sessionId?: number): Promise<MarketCall[]>;
721
+ /**
722
+ * A page of `calls()`: the newest `limit`, or of those whose id is below
723
+ * `before` -- a page's `next`. The server answers at most 5,000.
724
+ */
725
+ callsPage(marketplaceId: number, limit: number, before?: number): Promise<Page<MarketCall>>;
599
726
  /**
600
727
  * Every robot the marketplace's robot host offers, with whether it is
601
728
  * enabled here and how a manager has configured its parameters.
@@ -620,6 +747,8 @@ export declare class Flexemarkets {
620
747
  */
621
748
  configureRobotParameter(marketplaceId: number, robotId: string, paramName: string, value: string, control: RobotParameterControl | null): Promise<RobotParameterConfig>;
622
749
  private readonly _sharedViews;
750
+ /** The socket each marketplace's sendLimit orders go out on, opened by the first of them. */
751
+ private readonly _orderStreams;
623
752
  private readonly _sharedViewPromises;
624
753
  /**
625
754
  * Open a stateful Desk on this marketplace. Multiple calls