1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//! London Strategic Edge market data (behind the `lse` feature) — ⚠️ the retrieved data is **not
//! redistributable**.
//!
//! A free, no-account market-data provider covering FX, equities, ETFs, crypto, commodities,
//! indices, futures and options, plus reference and macroeconomic series.
//!
//! # ⚠️ Licensing — the data is NOT redistributable
//! This integration's **code** is MIT-licensed like the rest of this repository. **The data it
//! retrieves is not.** London Strategic Edge permits use for your own research, trading and model
//! training — including commercially — but **prohibits redistributing, reselling, or otherwise
//! making the data available to third parties**, in bulk or through any competing feed, download
//! service or interface. Their own client library being MIT-licensed covers *that client only* and
//! confers no rights in the data; the same split applies here.
//!
//! In practice: do not commit retrieved data to a public repository, do not publish it as fixtures
//! or example datasets, and do not re-serve it. Terms: <https://londonstrategicedge.com/terms>
//!
//! # Data characteristics
//! Properties that will silently mislead if assumed away:
//!
//! - **FX candles are BID candles — not mid, and not last.** Reconciling a day of `EUR/USD`
//! one-minute bars against the tick tape for the same day, open/high/low/close matched the
//! **bid** series on 1421 of 1421 minutes and matched the mid or the ask on none. So a backtest
//! that fills at the candle close is filling at the bid — systematically favourable by a full
//! spread on every buy, in the provider's deepest dataset. This cannot be corrected here without
//! inventing a spread. Equity candles, by contrast, track the trade tape; the asymmetry is real
//! and per-dataset.
//! - **Candle volume is not a dependable figure.** For FX the vault omits the field entirely, which
//! is modelled as `None` rather than a zero — a zero would aggregate into a legitimate-looking
//! total at every derived resolution. (The provider's other host reports a volume for the same
//! bar; this integration uses the vault, which does not.) Where the field *is* published it is
//! still unreliable: a majority of sampled one-minute equity bars reported `0` in minutes the
//! tick tape shows real trades, and one daily series carried a contiguous band roughly 2,000×
//! too large. A literal `0` is passed through as `Some(0)`; rewriting it to `None` would be this
//! library inventing a fact, and `None` is reserved for a column the provider does not publish.
//! Validate before trading on it.
//! - **⚠️ Candle volume has additionally been reported wrong by three to four orders of magnitude
//! since 2026-04-27, in opposite directions on ETFs and on equities.** Unlike the rest of this
//! list, which is measured here, this is a third-party report on the provider's public issue
//! tracker — repeated across symbols and dates, and unanswered. **ETFs over-report**: a `QQQ`
//! one-minute bar was published at 189,272,655,373 against a consolidated **daily** figure of
//! 33,118,600 for the same session — roughly 5,700× the whole day inside one minute — on
//! `QQQ`, `SPY`, `IWM`, `SMH`, `XLE`, `XLF`, `TLT`, every trading day sampled over two months.
//! **Equities under-report**: `AAPL`, `MSFT` and `NVDA` daily totals ran at 24–45% of the
//! consolidated tape, against 65–80% before the same date, which is the ordinary
//! primary-venue-versus-consolidated gap. Splits and liquidity stress were both ruled out by
//! the reporter. This integration decodes those figures faithfully, and a shape check passes on
//! them: the bars are structurally valid and semantically wrong, so nothing in band distinguishes
//! them from correct ones. **Reconcile volume against a second source before sizing anything on
//! it**, and treat a volume-derived signal — VWAP, a liquidity filter, a participation-rate
//! model — as unusable on this feed until you have.
//! - **⚠️ History depth varies per dataset and is far shallower than the headline suggests on
//! some of them.** `QQQ` in the `etf` dataset was reported carrying a first tick of 2026-04-27
//! and 0.2 years of coverage — roughly three months of spot — while options on the same ticker
//! reach back to 2014 and equities are stated to reach 2004. Depth is a per-symbol,
//! per-dataset property, discoverable from the `first_tick` and `years` fields the provider's
//! catalog publishes for each entry. **That catalog is on the discovery host and is not wrapped
//! by this integration**, so nothing here can check a requested range against it: a backtest
//! asking for years that a symbol does not have receives the bars that exist and no indication
//! that the rest were never published. Check depth per symbol before choosing a range.
//! - **Non-trading days are emitted as FLAT bars, not omitted — daily series are not sparse.**
//! Every sampled Saturday and the US Independence Day observance returned a bar with
//! `open == high == low == close`; Sundays are absent. A backtest therefore sees a tradeable
//! price on a closed market, and the only signal is the flat OHLC. Intraday bars *are* sparse
//! (no-trade minutes are absent rather than zero-filled), so the two resolutions differ.
//! - **These are CFD and aggregated-spot series, not exchange instruments.** `XAU/USD` is spot
//! gold rather than a COMEX contract, `SPX500/USD` is a CFD rather than an index or its future,
//! and `ES.F` is a continuous front-month proxy with **no contract chain, expiry or roll**.
//! There is no venue attribution anywhere in the feed.
//! - **Crypto is an aggregated tape**: no funding rates, no liquidations, no venue. It is not a
//! substitute for a native exchange connector.
//! - **The live tick is a QUOTE, not a print.** Its `price` equals its `bid` on every sample taken
//! — 3,966 of 3,966 ticks across every dataset family. Both [`PublicTrades`] and [`OrderBooksL1`]
//! are served from it, but a trade decoded this way is a bid-side quote wearing a trade's shape
//! and is not evidence that a transaction occurred. See [`trade`] for the mapping and its
//! reasoning.
//! - **Live tick `volume` is real on two venues and FABRICATED on two others**, with no in-band
//! signal separating them. [`LseCrypto`] and [`LseEquities`] carry a genuine per-tick size, which
//! reconciles exactly against the provider's own one-minute candles (ratio `1.000`).
//! **[`LseFx`] and [`LseCfd`] carry a hard-coded `1.0`** on every tick of every symbol sampled —
//! a placeholder that will aggregate into a legitimate-looking total at any resolution, so
//! volume-weighted prices and size filters on those two venues are meaningless rather than merely
//! imprecise. Note this differs from the REST vault, which *omits* FX volume entirely; the
//! WebSocket invents a value instead.
//! - **Identical consecutive live ticks are genuine and are never de-duplicated.** Barely a third
//! of a sampled run was unique on `(ts, price, bid, ask, volume)`, yet removing the repeats
//! destroyed 3–10% of volume that otherwise reconciles exactly. Do not add a de-duplication
//! filter; a test pins that both are emitted.
//! - **London (`.L`) listings are quoted in PENCE**, and the catalog reports no unit. They are
//! quoted in GBX, an asset distinct from GBP; see
//! [`market::quote_asset`].
//! - **Option greeks are print-triggered, not continuous**: they arrive only with a trade, so a
//! contract's greeks are as stale as its last print and an unheld, untraded contract is never
//! marked. See [`options`].
//! - **Dataset slugs are not instrument identities** and do not uniquely identify a series; see
//! [`market::slug`].
// A module carries an outer `///` here only when its own file has no `//!` documentation.
// Supplying both makes rustdoc resolve the file's inner links in THIS module's scope rather than
// the child's, so every `[`SomeType`]` written inside the child silently renders as dead text.
/// Replay historical candles for N instruments as one time-ordered market stream.
/// The WebSocket channel a subscription maps to.
/// Errors produced by the London Strategic Edge integration.
/// London Strategic Edge symbology: datasets, underlying assets, quote currencies and slugs.
/// The shared streaming + export allowance, as the provider reports it.
// HTTP plumbing shared by the provider's two hosts; documented in its own file.
pub
use ;
use crateosi;
use crate::;
use ExchangeId;
use WsMessage;
use ;
use SmolStr;
use ;
use Url;
/// The WebSocket endpoint.
///
/// One host serves every dataset. The per-dataset connector split below is about provenance in
/// `MarketEvent.exchange` and per-dataset support declarations, not about distinct endpoints.
///
/// # ⚠️ One connection per key, shared by every stream a subscriber and its clones open
/// A free key — the `registered` tier, the only one measured — holds exactly one concurrent
/// connection: its handshake reports `max_connections: 1`, and a second is refused with
/// `TOO_MANY_CONNECTIONS`. That one connection serves every dataset, both subscription kinds and
/// option underlyings, so every stream opened by one [`LseSubscriber`] and its clones shares it —
/// across any number of `subscribe` calls. A subscriber built separately for the same key opens a
/// connection of its own and is refused. See [`connection`] for how the connection is shared.
///
/// That one connection holds 100 subscriptions when last measured (the handshake reports the live
/// figure), shared by every stream on it: a symbol per slot, or on [`LseOptions`] an underlying per
/// slot. A symbol held by several streams — [`OrderBooksL1`] alongside [`PublicTrades`], say —
/// costs one.
pub const WEBSOCKET_URL: &str = "wss://data-ws.londonstrategicedge.com";
/// Format of every naive timestamp the provider serves over REST.
///
/// Used by the candle rows' `ts` and by the catalog's `first_tick` / `last_tick`, which share one
/// spelling (`2024-01-02 09:09:00.000000`). `%.f` makes the fractional part optional, so a response
/// that drops the microseconds still parses. The value carries no timezone and is UTC.
pub const PROVIDER_TIMESTAMP_FORMAT: &str = "%Y-%m-%d %H:%M:%S%.f";
/// The London Strategic Edge live market data connector.
///
/// Use the per-dataset aliases — [`LseFx`], [`LseCrypto`], [`LseEquities`], [`LseFutures`],
/// [`LseCfd`], [`LseOptions`] — rather than naming the server type directly.
;
/// Spot FX: `EUR/USD`, `GBP/USD`, …
pub type LseFx = ;
/// Aggregated spot crypto: `BTC/USD`, `ETH/USD`, …
pub type LseCrypto = ;
/// Equities and ETFs: `AAPL`, `SPY`, `BP.L`, …
pub type LseEquities = ;
/// Continuous front-month futures proxies: `ES.F`, `FDAX`, …
pub type LseFutures = ;
/// Indices, commodities, interest rates, currency indices and volatility, all as CFDs:
/// `SPX500/USD`, `XAU/USD`, `USB10Y/USD`, `DXY/USD`, `VIX/USD`.
pub type LseCfd = ;
/// US equity and ETF option contracts, one [`Subscription`](crate::subscription::Subscription)
/// per contract: `SPY260930C00700000`.
///
/// Serves [`PublicTrades`] only — every option tick is a genuine print, and none carries a quote.
///
/// # How a batch is subscribed
/// The provider streams options **per underlying**, not per contract: one subscribe covers an
/// underlying's whole chain, thousands of contracts, on a single one of the connection's
/// subscription slots. Contracts sharing an underlying therefore collapse into one subscribe, and
/// the connection holds as many underlyings as it has slots — 100 when last measured — however
/// many contracts are registered.
///
/// # ⚠️ Only registered contracts are delivered; the rest of the chain is counted and dropped
/// Every contract on a subscribed underlying ticks, whether registered or not. Prints for contracts
/// nobody registered are dropped without an error each, and reported instead as a periodic
/// per-underlying `info` count. The set of contracts that trade does not level off over a session —
/// it was still growing after five minutes with no plateau in sight — so a contract that starts
/// trading mid-session is missed unless it was registered up front. The provider's REST print tape
/// in [`options`] carries every contract, greeks included.
///
/// # ⚠️ A contract the provider does not list is silent, not rejected
/// The provider confirms an underlying without listing its contracts, so a registered contract that
/// does not exist — a wrong expiry, a strike off the chain — is accepted and never ticks. An
/// underlying with no options at all *is* rejected, by name.
///
/// # One connection per key, shared
/// Option chains stream over the same connection as every other London Strategic Edge dataset, and
/// draw on its one subscription cap: each underlying takes a slot, as each plain symbol does. See
/// [`WEBSOCKET_URL`].
///
/// # No resumption
/// A reconnect does not replay the gap: the provider has no replay window on this channel. An
/// options subscribe that names a `start` is confirmed as usual and draws no error, yet no replay
/// opens and nothing older than the subscribe is served — measured in session, beside a plain
/// subscribe on the same connection that did replay. None is therefore requested, and a subscriber configured with [`LseSubscriber::with_resume`] resumes its other
/// datasets but not this one.
///
/// Expiry and strike conventions are those of [`LseSymbolShape::OptionContract`].
pub type LseOptions = ;
/// Spot FX server.
;
/// Aggregated spot crypto server.
;
/// Equities and ETFs server.
;
/// Continuous futures-proxy server.
;
/// CFD server — indices, commodities, interest rates, currency indices and volatility.
;
/// Option contract server.
;
// The two traits are declared together per server because they answer one question each about the
// same dataset -- which venue its events are stamped with, and how it spells a symbol -- and a
// server that implements one without the other is not usable.
impl_lse_server!;
impl_lse_server!;
impl_lse_server!;
impl_lse_server!;
impl_lse_server!;
impl_lse_server!;
// Every server but options: the options channel publishes no quote. See `LseQuoteServer`.
// Both subscription kinds decode the SAME frame -- the provider publishes one data frame and it
// carries a price, a bid, an ask and a size -- so the two selectors differ only in which decoder
// the transformer is instantiated with. Neither needs an initial snapshot: the feed is a tick
// stream with no book to synchronise against.
//
// One blanket impl per kind covers every server, rather than an impl per server each. The servers
// differ in venue and symbol shape, never in framing -- save that the options channel carries no
// quote, which is why the L1 impl is bounded on `LseQuoteServer`.
// Test code: panics on bad input are acceptable