|
52 | 52 | tokio::sync::{ |
53 | 53 | broadcast, |
54 | 54 | mpsc, |
55 | | - oneshot, |
56 | 55 | }, |
57 | 56 | warp::{ |
58 | 57 | ws::{ |
@@ -327,119 +326,20 @@ async fn dispatch_and_catch_error( |
327 | 326 | } |
328 | 327 | } |
329 | 328 |
|
330 | | -async fn get_product_list( |
331 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
332 | | -) -> Result<serde_json::Value> { |
333 | | - let (result_tx, result_rx) = oneshot::channel(); |
334 | | - adapter_tx |
335 | | - .send(adapter::Message::GetProductList { result_tx }) |
336 | | - .await?; |
337 | | - Ok(serde_json::to_value(result_rx.await??)?) |
338 | | -} |
339 | | - |
340 | | -async fn get_product( |
341 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
342 | | - request: &Request<Method, Value>, |
343 | | -) -> Result<serde_json::Value> { |
344 | | - let params: GetProductParams = { |
345 | | - let value = request.params.clone(); |
346 | | - serde_json::from_value(value.ok_or_else(|| anyhow!("Missing request parameters"))?) |
347 | | - }?; |
348 | | - |
349 | | - let (result_tx, result_rx) = oneshot::channel(); |
350 | | - adapter_tx |
351 | | - .send(adapter::Message::GetProduct { |
352 | | - account: params.account, |
353 | | - result_tx, |
354 | | - }) |
355 | | - .await?; |
356 | | - Ok(serde_json::to_value(result_rx.await??)?) |
357 | | -} |
358 | | - |
359 | | -async fn get_all_products( |
360 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
361 | | -) -> Result<serde_json::Value> { |
362 | | - let (result_tx, result_rx) = oneshot::channel(); |
363 | | - adapter_tx |
364 | | - .send(adapter::Message::GetAllProducts { result_tx }) |
365 | | - .await?; |
366 | | - Ok(serde_json::to_value(result_rx.await??)?) |
367 | | -} |
368 | | - |
369 | | -async fn subscribe_price( |
370 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
371 | | - notify_price_tx: &mpsc::Sender<NotifyPrice>, |
372 | | - request: &Request<Method, Value>, |
373 | | -) -> Result<serde_json::Value> { |
374 | | - let params: SubscribePriceParams = serde_json::from_value( |
375 | | - request |
376 | | - .params |
377 | | - .clone() |
378 | | - .ok_or_else(|| anyhow!("Missing request parameters"))?, |
379 | | - )?; |
380 | | - |
381 | | - let (result_tx, result_rx) = oneshot::channel(); |
382 | | - adapter_tx |
383 | | - .send(adapter::Message::SubscribePrice { |
384 | | - result_tx, |
385 | | - account: params.account, |
386 | | - notify_price_tx: notify_price_tx.clone(), |
387 | | - }) |
388 | | - .await?; |
389 | | - |
390 | | - Ok(serde_json::to_value(SubscribeResult { |
391 | | - subscription: result_rx.await??, |
392 | | - })?) |
393 | | -} |
394 | | - |
395 | | -async fn subscribe_price_sched( |
396 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
397 | | - notify_price_sched_tx: &mpsc::Sender<NotifyPriceSched>, |
398 | | - request: &Request<Method, Value>, |
399 | | -) -> Result<serde_json::Value> { |
400 | | - let params: SubscribePriceSchedParams = serde_json::from_value( |
401 | | - request |
402 | | - .params |
403 | | - .clone() |
404 | | - .ok_or_else(|| anyhow!("Missing request parameters"))?, |
405 | | - )?; |
406 | | - |
407 | | - let (result_tx, result_rx) = oneshot::channel(); |
408 | | - adapter_tx |
409 | | - .send(adapter::Message::SubscribePriceSched { |
410 | | - result_tx, |
411 | | - account: params.account, |
412 | | - notify_price_sched_tx: notify_price_sched_tx.clone(), |
413 | | - }) |
414 | | - .await?; |
415 | | - |
416 | | - Ok(serde_json::to_value(SubscribeResult { |
417 | | - subscription: result_rx.await??, |
418 | | - })?) |
419 | | -} |
420 | | - |
421 | | -async fn update_price( |
422 | | - adapter_tx: &mpsc::Sender<adapter::Message>, |
423 | | - request: &Request<Method, Value>, |
424 | | -) -> Result<serde_json::Value> { |
425 | | - let params: UpdatePriceParams = serde_json::from_value( |
426 | | - request |
427 | | - .params |
428 | | - .clone() |
429 | | - .ok_or_else(|| anyhow!("Missing request parameters"))?, |
430 | | - )?; |
431 | | - |
432 | | - adapter_tx |
433 | | - .send(adapter::Message::UpdatePrice { |
434 | | - account: params.account, |
435 | | - price: params.price, |
436 | | - conf: params.conf, |
437 | | - status: params.status, |
438 | | - }) |
439 | | - .await?; |
440 | | - |
441 | | - Ok(serde_json::to_value(0)?) |
442 | | -} |
| 329 | +mod get_all_products; |
| 330 | +mod get_product; |
| 331 | +mod get_product_list; |
| 332 | +mod subscribe_price; |
| 333 | +mod subscribe_price_sched; |
| 334 | +mod update_price; |
| 335 | +use { |
| 336 | + get_all_products::*, |
| 337 | + get_product::*, |
| 338 | + get_product_list::*, |
| 339 | + subscribe_price::*, |
| 340 | + subscribe_price_sched::*, |
| 341 | + update_price::*, |
| 342 | +}; |
443 | 343 |
|
444 | 344 | async fn send_error( |
445 | 345 | ws_tx: &mut SplitSink<WebSocket, Message>, |
|
0 commit comments