@@ -32,11 +32,11 @@ pub enum UpdateParams {
32
32
#[ serde( rename = "price" ) ]
33
33
PriceUpdate {
34
34
price : Price ,
35
- best_bid_price : Price ,
36
- best_ask_price : Price ,
35
+ best_bid_price : Option < Price > ,
36
+ best_ask_price : Option < Price > ,
37
37
} ,
38
38
#[ serde( rename = "funding_rate" ) ]
39
- FundingRateUpdate { price : Price , rate : Rate } ,
39
+ FundingRateUpdate { price : Option < Price > , rate : Rate } ,
40
40
}
41
41
42
42
#[ derive( Serialize , Deserialize , Debug , Eq , PartialEq ) ]
@@ -160,8 +160,47 @@ mod tests {
160
160
source_timestamp : TimestampUs ( 124214124124 ) ,
161
161
update : UpdateParams :: PriceUpdate {
162
162
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 ,
165
204
} ,
166
205
} ) ,
167
206
id : 1 ,
@@ -199,7 +238,7 @@ mod tests {
199
238
feed_id : PriceFeedId ( 1 ) ,
200
239
source_timestamp : TimestampUs ( 124214124124 ) ,
201
240
update : UpdateParams :: FundingRateUpdate {
202
- price : Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ,
241
+ price : Some ( Price :: from_integer ( 1234567890 , 0 ) . unwrap ( ) ) ,
203
242
rate : Rate :: from_integer ( 1234567891 , 0 ) . unwrap ( ) ,
204
243
} ,
205
244
} ) ,
@@ -211,6 +250,44 @@ mod tests {
211
250
expected
212
251
) ;
213
252
}
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
+
214
291
#[ test]
215
292
fn test_send_get_metadata ( ) {
216
293
let json = r#"
0 commit comments