pyth-lazer-agent 0.11.2

Pyth Lazer Agent
Documentation
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
use crate::config::Config;
use crate::lazer_publisher::LazerPublisher;
use crate::metadata::fetch_metadata;
use crate::websocket_utils::{handle_websocket_error, send_text};
use futures::{AsyncRead, AsyncWrite};
use futures_util::io::{BufReader, BufWriter};
use hyper_util::rt::TokioIo;
use protobuf::{EnumOrUnknown, MessageField};
use pyth_lazer_protocol::PriceFeedId;
use pyth_lazer_protocol::jrpc::{JrpcId, JsonRpcVersion, SymbolMetadata};
use pyth_lazer_publisher_sdk::publisher_update::feed_update::Update;
use pyth_lazer_publisher_sdk::publisher_update::{FeedUpdate, PriceUpdate};
use pyth_lazer_publisher_sdk::state::TradingStatus;
use serde::{Deserialize, Serialize};
use soketto::Sender;
use soketto::handshake::http::Server;
use std::collections::{HashMap, HashSet};
use tokio::time::MissedTickBehavior;
use tokio::{pin, select};
use tokio_util::compat::TokioAsyncReadCompatExt;
use tracing::{debug, error, instrument};
use url::Url;

#[derive(Deserialize, Debug)]
struct LegacyJrpcRequest {
    #[allow(dead_code, reason = "validated by serde during deserialization")]
    jsonrpc: JsonRpcVersion,
    #[serde(flatten)]
    method: LegacyMethod,
    #[serde(default)]
    id: JrpcId,
}

#[derive(Deserialize, Debug)]
#[serde(tag = "method", content = "params", rename_all = "snake_case")]
enum LegacyMethod {
    GetProductList(
        #[allow(dead_code, reason = "validated by serde during deserialization")]
        Option<EmptyParams>,
    ),
    GetProduct(AccountParams),
    GetAllProducts,
    SubscribePriceSched(AccountParams),
    SubscribePrice(AccountParams),
    UpdatePrice(UpdatePriceParams),
}

#[derive(Deserialize, Debug)]
#[serde(deny_unknown_fields)]
struct EmptyParams {}

#[derive(Deserialize, Debug)]
struct AccountParams {
    account: String,
}

#[derive(Deserialize, Debug)]
struct UpdatePriceParams {
    account: String,
    #[serde(deserialize_with = "serde_this_or_that::as_i64")]
    price: i64,
    #[serde(deserialize_with = "serde_this_or_that::as_u64")]
    conf: u64,
    status: LegacyPriceStatus,
}

#[derive(Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "lowercase")]
enum LegacyPriceStatus {
    Unknown,
    Trading,
    Halted,
    Auction,
    Ignored,
}

impl LegacyPriceStatus {
    fn to_trading_status(self) -> Option<EnumOrUnknown<TradingStatus>> {
        match self {
            Self::Trading => Some(EnumOrUnknown::new(TradingStatus::TRADING_STATUS_OPEN)),
            Self::Halted => Some(EnumOrUnknown::new(TradingStatus::TRADING_STATUS_HALTED)),
            Self::Unknown | Self::Auction | Self::Ignored => None,
        }
    }
}

#[derive(Serialize)]
struct LegacySuccessResponse<'a, T: Serialize> {
    jsonrpc: &'a str,
    result: T,
    id: &'a JrpcId,
}

#[derive(Serialize)]
struct LegacyErrorResponse<'a> {
    jsonrpc: &'a str,
    error: LegacyErrorObject<'a>,
    id: &'a JrpcId,
}

#[derive(Serialize)]
struct LegacyErrorObject<'a> {
    code: i32,
    message: &'a str,
}

#[derive(Serialize)]
struct LegacyNotification<T: Serialize> {
    jsonrpc: &'static str,
    method: &'static str,
    params: T,
}

#[derive(Serialize)]
struct SubscriptionResult {
    subscription: u64,
}

#[derive(Serialize)]
struct SchedNotificationParams {
    subscription: u64,
}

const JSONRPC_V2: &str = "2.0";
const INTERNAL_ERROR_CODE: i32 = -32603;

fn make_success_value<T: Serialize>(
    id: &JrpcId,
    result: T,
) -> serde_json::Result<serde_json::Value> {
    serde_json::to_value(LegacySuccessResponse {
        jsonrpc: JSONRPC_V2,
        result,
        id,
    })
}

fn make_error_value(id: &JrpcId, message: &str) -> serde_json::Result<serde_json::Value> {
    serde_json::to_value(LegacyErrorResponse {
        jsonrpc: JSONRPC_V2,
        error: LegacyErrorObject {
            code: INTERNAL_ERROR_CODE,
            message,
        },
        id,
    })
}

#[derive(Serialize, Clone, Debug)]
struct ProductAccountDetail {
    account: String,
    attr_dict: HashMap<String, String>,
    price: Vec<PriceAccountDetail>,
}

#[derive(Serialize, Clone, Debug)]
struct PriceAccountDetail {
    account: String,
    price_exponent: i16,
    price_type: &'static str,
}

fn product_detail_from_metadata(sym: &SymbolMetadata) -> ProductAccountDetail {
    let feed_id_str = sym.pyth_lazer_id.0.to_string();

    let mut attr_dict = HashMap::new();
    attr_dict.insert("symbol".to_string(), sym.symbol.clone());
    attr_dict.insert("asset_type".to_string(), sym.asset_type.clone());
    attr_dict.insert("description".to_string(), sym.description.clone());
    if let Some(ref qc) = sym.quote_currency {
        attr_dict.insert("quote_currency".to_string(), qc.clone());
    }

    ProductAccountDetail {
        account: feed_id_str.clone(),
        attr_dict,
        price: vec![PriceAccountDetail {
            account: feed_id_str,
            price_exponent: sym.exponent,
            price_type: "price",
        }],
    }
}

#[instrument(
    skip(server, request, lazer_publisher, config),
    fields(component = "legacy_ws")
)]
pub async fn handle_legacy(
    config: Config,
    server: Server,
    request: hyper::Request<hyper::body::Incoming>,
    lazer_publisher: LazerPublisher,
) {
    if let Err(err) = try_handle_legacy(config, server, request, lazer_publisher).await {
        handle_websocket_error(err);
    }
}

#[instrument(
    skip(server, request, lazer_publisher, config),
    fields(component = "legacy_ws")
)]
async fn try_handle_legacy(
    config: Config,
    server: Server,
    request: hyper::Request<hyper::body::Incoming>,
    lazer_publisher: LazerPublisher,
) -> anyhow::Result<()> {
    let stream = hyper::upgrade::on(request).await?;
    let io = TokioIo::new(stream);
    let stream = BufReader::new(BufWriter::new(io.compat()));
    let (mut ws_sender, mut ws_receiver) = server.into_builder(stream).finish();

    let mut receive_buf = Vec::new();
    let mut next_subscription_id: u64 = 1;
    let mut sched_subscriptions: HashSet<u64> = HashSet::new();

    let mut sched_interval = tokio::time::interval(config.legacy_sched_interval_duration);
    sched_interval.set_missed_tick_behavior(MissedTickBehavior::Skip);

    loop {
        receive_buf.clear();
        {
            let receive = async { ws_receiver.receive(&mut receive_buf).await };
            pin!(receive);
            loop {
                select! {
                    result = &mut receive => {
                        result?;
                        break;
                    }
                    _ = sched_interval.tick() => {
                        send_sched_notifications(&mut ws_sender, &sched_subscriptions).await;
                    }
                }
            }
        }

        let request_text = match std::str::from_utf8(&receive_buf) {
            Ok(s) => s.to_string(),
            Err(_) => {
                debug!("received non-utf8 data, ignoring");
                continue;
            }
        };

        let parsed: serde_json::Value = match serde_json::from_str(&request_text) {
            Ok(v) => v,
            Err(err) => {
                let id = JrpcId::Int(0);
                let response = make_error_value(&id, &err.to_string())?;
                send_text(&mut ws_sender, &serde_json::to_string(&response)?).await?;
                continue;
            }
        };

        match parsed {
            serde_json::Value::Array(items) => {
                let mut responses = Vec::with_capacity(items.len());
                for raw in items {
                    responses.push(
                        dispatch_request(
                            &raw,
                            &lazer_publisher,
                            &config.history_service_url,
                            &mut next_subscription_id,
                            &mut sched_subscriptions,
                        )
                        .await?,
                    );
                }
                send_text(&mut ws_sender, &serde_json::to_string(&responses)?).await?;
            }
            raw @ serde_json::Value::Object(_) => {
                let response = dispatch_request(
                    &raw,
                    &lazer_publisher,
                    &config.history_service_url,
                    &mut next_subscription_id,
                    &mut sched_subscriptions,
                )
                .await?;
                send_text(&mut ws_sender, &serde_json::to_string(&response)?).await?;
            }
            _ => {
                let id = JrpcId::Int(0);
                let response = make_error_value(&id, "expected JSON object or array")?;
                send_text(&mut ws_sender, &serde_json::to_string(&response)?).await?;
            }
        }
    }
}

async fn send_sched_notifications<T: AsyncRead + AsyncWrite + Unpin>(
    sender: &mut Sender<T>,
    sched_subscriptions: &HashSet<u64>,
) {
    for &sub_id in sched_subscriptions {
        let notification = LegacyNotification {
            jsonrpc: JSONRPC_V2,
            method: "notify_price_sched",
            params: SchedNotificationParams {
                subscription: sub_id,
            },
        };
        if let Ok(json) = serde_json::to_string(&notification) {
            if let Err(err) = send_text(sender, &json).await {
                debug!("failed to send notify_price_sched: {err}");
                return;
            }
        }
    }
}

async fn dispatch_request(
    raw: &serde_json::Value,
    lazer_publisher: &LazerPublisher,
    metadata_url: &Url,
    next_subscription_id: &mut u64,
    sched_subscriptions: &mut HashSet<u64>,
) -> serde_json::Result<serde_json::Value> {
    let fallback_id = JrpcId::Int(0);

    let request: LegacyJrpcRequest = match serde_json::from_value(raw.clone()) {
        Ok(r) => r,
        Err(err) => {
            return make_error_value(&fallback_id, &err.to_string());
        }
    };

    let id = &request.id;
    match request.method {
        LegacyMethod::GetProductList(_) => handle_get_product_list(metadata_url, id).await,
        LegacyMethod::GetProduct(params) => {
            handle_get_product(metadata_url, &params.account, id).await
        }
        LegacyMethod::GetAllProducts => handle_get_all_products(metadata_url, id).await,
        LegacyMethod::SubscribePriceSched(_params) => {
            handle_subscribe_price_sched(id, next_subscription_id, sched_subscriptions).await
        }
        LegacyMethod::SubscribePrice(_params) => handle_subscribe_price(id).await,
        LegacyMethod::UpdatePrice(params) => handle_update_price(params, id, lazer_publisher).await,
    }
}

async fn handle_get_product_list(
    metadata_url: &Url,
    id: &JrpcId,
) -> serde_json::Result<serde_json::Value> {
    match fetch_metadata(metadata_url).await {
        Ok(metadata) => {
            let products: Vec<_> = metadata.iter().map(product_detail_from_metadata).collect();
            make_success_value(id, &products)
        }
        Err(err) => {
            error!("error while retrieving metadata: {err:?}");
            make_error_value(id, &err.to_string())
        }
    }
}

async fn handle_get_product(
    metadata_url: &Url,
    account: &str,
    id: &JrpcId,
) -> serde_json::Result<serde_json::Value> {
    match fetch_metadata(metadata_url).await {
        Ok(metadata) => {
            let detail = metadata
                .iter()
                .map(product_detail_from_metadata)
                .find(|d| d.account == account);
            match detail {
                Some(d) => make_success_value(id, &d),
                None => make_error_value(id, "product account not found"),
            }
        }
        Err(err) => {
            error!("error while retrieving metadata: {err:?}");
            make_error_value(id, &err.to_string())
        }
    }
}

async fn handle_get_all_products(
    metadata_url: &Url,
    id: &JrpcId,
) -> serde_json::Result<serde_json::Value> {
    match fetch_metadata(metadata_url).await {
        Ok(metadata) => {
            let products: Vec<_> = metadata.iter().map(product_detail_from_metadata).collect();
            make_success_value(id, &products)
        }
        Err(err) => {
            error!("error while retrieving metadata: {err:?}");
            make_error_value(id, &err.to_string())
        }
    }
}

async fn handle_subscribe_price_sched(
    id: &JrpcId,
    next_subscription_id: &mut u64,
    sched_subscriptions: &mut HashSet<u64>,
) -> serde_json::Result<serde_json::Value> {
    let sub_id = *next_subscription_id;
    *next_subscription_id += 1;
    sched_subscriptions.insert(sub_id);
    make_success_value(
        id,
        SubscriptionResult {
            subscription: sub_id,
        },
    )
}

async fn handle_subscribe_price(id: &JrpcId) -> serde_json::Result<serde_json::Value> {
    make_error_value(id, "this method is not supported in the legacy adapter")
}

async fn handle_update_price(
    params: UpdatePriceParams,
    id: &JrpcId,
    lazer_publisher: &LazerPublisher,
) -> serde_json::Result<serde_json::Value> {
    let feed_id = match params.account.parse::<u32>().ok().map(PriceFeedId) {
        Some(fid) => fid,
        None => return make_error_value(id, "invalid price account"),
    };

    let trading_status = params.status.to_trading_status();

    let conf_i64 = match i64::try_from(params.conf) {
        Ok(conf_i64) => conf_i64,
        Err(_) => i64::MAX,
    };

    let feed_update = FeedUpdate {
        feed_id: Some(feed_id.0),
        source_timestamp: MessageField::some(
            protobuf::well_known_types::timestamp::Timestamp::now(),
        ),
        update: Some(Update::PriceUpdate(PriceUpdate {
            price: Some(params.price),
            best_bid_price: Some(params.price.saturating_sub(conf_i64)),
            best_ask_price: Some(params.price.saturating_add(conf_i64)),
            trading_status,
            market_session: None,
            special_fields: Default::default(),
        })),
        special_fields: Default::default(),
    };

    match lazer_publisher.push_feed_update(feed_update).await {
        Ok(()) => make_success_value(id, 0),
        Err(err) => {
            error!("error while sending update: {err:?}");
            make_error_value(id, &err.to_string())
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_deserialize_update_price_with_numbers() {
        let json = r#"{
            "jsonrpc": "2.0",
            "method": "update_price",
            "params": {
                "account": "abc123",
                "price": 42002,
                "conf": 3,
                "status": "trading"
            },
            "id": 1
        }"#;
        let req: LegacyJrpcRequest = serde_json::from_str(json).unwrap();
        match req.method {
            LegacyMethod::UpdatePrice(params) => {
                assert_eq!(params.account, "abc123");
                assert_eq!(params.price, 42002);
                assert_eq!(params.conf, 3);
                assert!(matches!(params.status, LegacyPriceStatus::Trading));
            }
            other => panic!("expected UpdatePrice, got: {other:?}"),
        }
    }

    #[test]
    fn test_deserialize_update_price_with_string_numbers() {
        let json = r#"{
            "jsonrpc": "2.0",
            "method": "update_price",
            "params": {
                "account": "abc123",
                "price": "42002",
                "conf": "3",
                "status": "halted"
            },
            "id": 1
        }"#;
        let req: LegacyJrpcRequest = serde_json::from_str(json).unwrap();
        match req.method {
            LegacyMethod::UpdatePrice(params) => {
                assert_eq!(params.price, 42002);
                assert_eq!(params.conf, 3);
                assert!(matches!(params.status, LegacyPriceStatus::Halted));
            }
            other => panic!("expected UpdatePrice, got: {other:?}"),
        }
    }

    #[test]
    fn test_deserialize_get_product_list() {
        let json = r#"{"jsonrpc": "2.0", "method": "get_product_list", "id": 1}"#;
        let req: LegacyJrpcRequest = serde_json::from_str(json).unwrap();
        assert!(matches!(req.method, LegacyMethod::GetProductList(_)));
        assert_eq!(req.id, JrpcId::Int(1));
    }

    #[test]
    fn test_deserialize_get_product_list_with_empty_params() {
        let json = r#"{"jsonrpc": "2.0", "method": "get_product_list", "params": {}, "id": 1}"#;
        let req: LegacyJrpcRequest = serde_json::from_str(json).unwrap();
        assert!(matches!(req.method, LegacyMethod::GetProductList(_)));
        assert_eq!(req.id, JrpcId::Int(1));
    }

    #[test]
    fn test_deserialize_subscribe_price_sched() {
        let json = r#"{
            "jsonrpc": "2.0",
            "method": "subscribe_price_sched",
            "params": {"account": "some_key"},
            "id": 5
        }"#;
        let req: LegacyJrpcRequest = serde_json::from_str(json).unwrap();
        match req.method {
            LegacyMethod::SubscribePriceSched(params) => {
                assert_eq!(params.account, "some_key");
            }
            other => panic!("expected SubscribePriceSched, got: {other:?}"),
        }
    }

    #[test]
    fn test_parse_batch_request() {
        let json = r#"[
            {"jsonrpc": "2.0", "method": "get_product_list", "id": 1},
            {"jsonrpc": "2.0", "method": "get_all_products", "id": 2}
        ]"#;
        let requests: Vec<LegacyJrpcRequest> = serde_json::from_str(json).unwrap();
        assert_eq!(requests.len(), 2);
        assert!(matches!(
            requests[0].method,
            LegacyMethod::GetProductList(_)
        ));
        assert!(matches!(requests[1].method, LegacyMethod::GetAllProducts));
    }

    #[test]
    fn test_error_response_format() {
        let id = JrpcId::Int(0);
        let err = make_error_value(&id, "product account not found").unwrap();
        assert_eq!(err["jsonrpc"], "2.0");
        assert_eq!(err["error"]["code"], -32603);
        assert_eq!(err["error"]["message"], "product account not found");
        assert_eq!(err["id"], 0);
    }

    #[test]
    fn test_success_response_format() {
        let id = JrpcId::Int(7);
        let resp = make_success_value(&id, SubscriptionResult { subscription: 42 }).unwrap();
        assert_eq!(resp["jsonrpc"], "2.0");
        assert_eq!(resp["result"]["subscription"], 42);
        assert_eq!(resp["id"], 7);
    }

    #[test]
    fn test_product_detail_from_metadata() {
        use pyth_lazer_protocol::SymbolState;
        use pyth_lazer_protocol::api::Channel;
        use pyth_lazer_protocol::time::FixedRate;

        let sym = SymbolMetadata {
            pyth_lazer_id: PriceFeedId(1),
            name: "BTC".to_string(),
            symbol: "Crypto.BTC/USD".to_string(),
            description: "BTC/USD".to_string(),
            asset_type: "Crypto".to_string(),
            exponent: -8,
            cmc_id: None,
            funding_rate_interval: None,
            min_publishers: 1,
            min_channel: Channel::FixedRate(FixedRate::MIN),
            state: SymbolState::Stable,
            hermes_id: None,
            quote_currency: Some("USD".to_string()),
            nasdaq_symbol: None,
        };

        let detail = product_detail_from_metadata(&sym);

        assert_eq!(detail.account, "1");
        assert_eq!(detail.attr_dict.len(), 4);
        assert_eq!(detail.attr_dict["symbol"], "Crypto.BTC/USD");
        assert_eq!(detail.attr_dict["asset_type"], "Crypto");
        assert_eq!(detail.attr_dict["description"], "BTC/USD");
        assert_eq!(detail.attr_dict["quote_currency"], "USD");

        assert_eq!(detail.price.len(), 1);
        let pa = &detail.price[0];
        assert_eq!(pa.account, "1");
        assert_eq!(pa.price_exponent, -8);
        assert_eq!(pa.price_type, "price");
    }

    #[test]
    fn test_product_detail_without_quote_currency() {
        use pyth_lazer_protocol::SymbolState;
        use pyth_lazer_protocol::api::Channel;
        use pyth_lazer_protocol::time::FixedRate;

        let sym = SymbolMetadata {
            pyth_lazer_id: PriceFeedId(42),
            name: "AAPL".to_string(),
            symbol: "Equity.AAPL/USD".to_string(),
            description: "AAPL/USD".to_string(),
            asset_type: "Equity".to_string(),
            exponent: -4,
            cmc_id: None,
            funding_rate_interval: None,
            min_publishers: 1,
            min_channel: Channel::FixedRate(FixedRate::MIN),
            state: SymbolState::Stable,
            hermes_id: None,
            quote_currency: None,
            nasdaq_symbol: None,
        };

        let detail = product_detail_from_metadata(&sym);

        assert_eq!(detail.attr_dict.len(), 3);
        assert_eq!(detail.attr_dict["symbol"], "Equity.AAPL/USD");
        assert_eq!(detail.attr_dict["asset_type"], "Equity");
        assert_eq!(detail.attr_dict["description"], "AAPL/USD");
        assert!(!detail.attr_dict.contains_key("quote_currency"));
        assert_eq!(detail.price[0].price_exponent, -4);
    }

    #[test]
    fn test_legacy_price_status_to_trading_status() {
        assert_eq!(
            LegacyPriceStatus::Trading
                .to_trading_status()
                .unwrap()
                .enum_value()
                .unwrap(),
            TradingStatus::TRADING_STATUS_OPEN
        );
        assert_eq!(
            LegacyPriceStatus::Halted
                .to_trading_status()
                .unwrap()
                .enum_value()
                .unwrap(),
            TradingStatus::TRADING_STATUS_HALTED
        );
        assert!(LegacyPriceStatus::Unknown.to_trading_status().is_none());
        assert!(LegacyPriceStatus::Ignored.to_trading_status().is_none());
        assert!(LegacyPriceStatus::Auction.to_trading_status().is_none());
    }
}