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
//! 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.
//! - **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`].
//! - **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.
use ;
use crate::;
use ExchangeId;
use WsMessage;
use ;
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 — so
/// subscribing across datasets opens several connections to this one host. The provider served at
/// least eight concurrent authenticated connections on one key when measured; the binding
/// constraint is the per-connection subscription cap, not the connection count.
pub const WEBSOCKET_URL: &str = "wss://data-ws.londonstrategicedge.com";
/// The London Strategic Edge live market data connector.
///
/// Use the per-dataset aliases — [`LseFx`], [`LseCrypto`], [`LseEquities`], [`LseFutures`],
/// [`LseCfd`] — 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 = ;
/// 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.
;
// 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!;
// 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 all five servers, rather than five impls each. The servers
// differ in venue and symbol shape, never in framing.
// Test code: panics on bad input are acceptable