@@ -32,11 +32,11 @@ pub enum UpdateParams {
3232 #[ serde( rename = "price" ) ]
3333 PriceUpdate {
3434 price : Price ,
35- best_bid_price : Price ,
36- best_ask_price : Price ,
35+ best_bid_price : Option < Price > ,
36+ best_ask_price : Option < Price > ,
3737 } ,
3838 #[ serde( rename = "funding_rate" ) ]
39- FundingRateUpdate { price : Price , rate : Rate } ,
39+ FundingRateUpdate { price : Option < Price > , rate : Rate } ,
4040}
4141
4242#[ derive( Serialize , Deserialize , Debug , Eq , PartialEq ) ]
@@ -160,8 +160,47 @@ mod tests {
160160 source_timestamp : TimestampUs ( 124214124124 ) ,
161161 update : UpdateParams :: PriceUpdate {
162162 price : Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ,
163- best_bid_price : Price :: from_integer ( 1234567891 , 0 ) . unwrap ( ) ,
164- best_ask_price : Price :: from_integer ( 1234567892 , 0 ) . unwrap ( ) ,
163+ best_bid_price : Some ( Price :: from_integer ( 1234567891 , 0 ) . unwrap ( ) ) ,
164+ best_ask_price : Some ( Price :: from_integer ( 1234567892 , 0 ) . unwrap ( ) ) ,
165+ } ,
166+ } ) ,
167+ id : 1 ,
168+ } ;
169+
170+ assert_eq ! (
171+ serde_json:: from_str:: <PythLazerAgentJrpcV1 >( json) . unwrap( ) ,
172+ expected
173+ ) ;
174+ }
175+
176+ #[ test]
177+ fn test_push_update_price_without_bid_ask ( ) {
178+ let json = r#"
179+ {
180+ "jsonrpc": "2.0",
181+ "method": "push_update",
182+ "params": {
183+ "feed_id": 1,
184+ "source_timestamp": 124214124124,
185+
186+ "update": {
187+ "type": "price",
188+ "price": 1234567890
189+ }
190+ },
191+ "id": 1
192+ }
193+ "# ;
194+
195+ let expected = PythLazerAgentJrpcV1 {
196+ jsonrpc : JsonRpcVersion :: V2 ,
197+ params : PushUpdate ( FeedUpdateParams {
198+ feed_id : PriceFeedId ( 1 ) ,
199+ source_timestamp : TimestampUs ( 124214124124 ) ,
200+ update : UpdateParams :: PriceUpdate {
201+ price : Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ,
202+ best_bid_price : None ,
203+ best_ask_price : None ,
165204 } ,
166205 } ) ,
167206 id : 1 ,
@@ -199,7 +238,7 @@ mod tests {
199238 feed_id : PriceFeedId ( 1 ) ,
200239 source_timestamp : TimestampUs ( 124214124124 ) ,
201240 update : UpdateParams :: FundingRateUpdate {
202- price : Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ,
241+ price : Some ( Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ) ,
203242 rate : Rate :: from_integer ( 1234567891 , 0 ) . unwrap ( ) ,
204243 } ,
205244 } ) ,
@@ -211,6 +250,44 @@ mod tests {
211250 expected
212251 ) ;
213252 }
253+ #[ test]
254+ fn test_push_update_funding_rate_without_price ( ) {
255+ let json = r#"
256+ {
257+ "jsonrpc": "2.0",
258+ "method": "push_update",
259+ "params": {
260+ "feed_id": 1,
261+ "source_timestamp": 124214124124,
262+
263+ "update": {
264+ "type": "funding_rate",
265+ "rate": 1234567891
266+ }
267+ },
268+ "id": 1
269+ }
270+ "# ;
271+
272+ let expected = PythLazerAgentJrpcV1 {
273+ jsonrpc : JsonRpcVersion :: V2 ,
274+ params : PushUpdate ( FeedUpdateParams {
275+ feed_id : PriceFeedId ( 1 ) ,
276+ source_timestamp : TimestampUs ( 124214124124 ) ,
277+ update : UpdateParams :: FundingRateUpdate {
278+ price : None ,
279+ rate : Rate :: from_integer ( 1234567891 , 0 ) . unwrap ( ) ,
280+ } ,
281+ } ) ,
282+ id : 1 ,
283+ } ;
284+
285+ assert_eq ! (
286+ serde_json:: from_str:: <PythLazerAgentJrpcV1 >( json) . unwrap( ) ,
287+ expected
288+ ) ;
289+ }
290+
214291 #[ test]
215292 fn test_send_get_metadata ( ) {
216293 let json = r#"
0 commit comments