@@ -151,6 +151,8 @@ enum ClientMessage {
151
151
binary : bool ,
152
152
#[ serde( default ) ]
153
153
allow_out_of_order : bool ,
154
+ #[ serde( default ) ]
155
+ ignore_invalid_price_ids : bool ,
154
156
} ,
155
157
#[ serde( rename = "unsubscribe" ) ]
156
158
Unsubscribe { ids : Vec < PriceIdInput > } ,
@@ -530,18 +532,22 @@ where
530
532
verbose,
531
533
binary,
532
534
allow_out_of_order,
535
+ ignore_invalid_price_ids,
533
536
} ) => {
534
537
let price_ids: Vec < PriceIdentifier > = ids. into_iter ( ) . map ( |id| id. into ( ) ) . collect ( ) ;
535
538
let available_price_ids = Aggregates :: get_price_feed_ids ( & * self . state ) . await ;
536
539
537
- let not_found_price_ids: Vec < & PriceIdentifier > = price_ids
540
+ let ( found_price_ids, not_found_price_ids) : (
541
+ Vec < & PriceIdentifier > ,
542
+ Vec < & PriceIdentifier > ,
543
+ ) = price_ids
538
544
. iter ( )
539
- . filter ( |price_id| !available_price_ids. contains ( price_id) )
540
- . collect ( ) ;
545
+ . partition ( |price_id| available_price_ids. contains ( price_id) ) ;
541
546
542
547
// If there is a single price id that is not found, we don't subscribe to any of the
543
- // asked correct price feed ids and return an error to be more explicit and clear.
544
- if !not_found_price_ids. is_empty ( ) {
548
+ // asked correct price feed ids and return an error to be more explicit and clear,
549
+ // unless the client explicitly asked to ignore invalid ids
550
+ if !not_found_price_ids. is_empty ( ) && !ignore_invalid_price_ids {
545
551
self . sender
546
552
. send (
547
553
serde_json:: to_string ( & ServerMessage :: Response (
@@ -556,10 +562,22 @@ where
556
562
)
557
563
. await ?;
558
564
return Ok ( ( ) ) ;
565
+ } else if found_price_ids. is_empty ( ) {
566
+ self . sender
567
+ . send (
568
+ serde_json:: to_string ( & ServerMessage :: Response (
569
+ ServerResponseMessage :: Err {
570
+ error : "No price feeds available" . to_string ( ) ,
571
+ } ,
572
+ ) ) ?
573
+ . into ( ) ,
574
+ )
575
+ . await ?;
576
+ return Ok ( ( ) ) ;
559
577
} else {
560
- for price_id in price_ids {
578
+ for price_id in found_price_ids {
561
579
self . price_feeds_with_config . insert (
562
- price_id,
580
+ * price_id,
563
581
PriceFeedClientConfig {
564
582
verbose,
565
583
binary,
0 commit comments