From 85935e553be55935251b158f1089de61d289df02 Mon Sep 17 00:00:00 2001 From: Sik Yoon Date: Sun, 26 May 2024 16:30:47 +0900 Subject: [PATCH] Seperate quantity of close position --- src/future/order.rs | 11 +++++++++-- src/main.rs | 4 +++- src/strategy_team/future_strategy_long.rs | 3 ++- src/strategy_team/future_strategy_short.rs | 3 ++- src/strategy_team/strategy_manager.rs | 5 +++-- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/future/order.rs b/src/future/order.rs index 5c06cc9..5125b2c 100644 --- a/src/future/order.rs +++ b/src/future/order.rs @@ -254,6 +254,7 @@ pub async fn limit_order_close( tif: TimeInForce, order_price: Decimal, order_quantity: Decimal, + futures_exchange_info_map: &HashMap, client: &Client, ) -> Result<(), Box> { let update_table_name = String::from("future_ordered_coin_list"); @@ -297,8 +298,14 @@ pub async fn limit_order_close( url_build.push_str("&side=BUY"); } url_build.push_str("&type=MARKET"); - url_build.push_str("&quantity="); - url_build.push_str(order_quantity.to_string().as_str()); + + if let Some(exchange_info) = futures_exchange_info_map.get(&entry_coin_info.symbol) { + if exchange_info.notional <= entry_coin_info.used_usdt { + url_build.push_str("&quantity="); + url_build.push_str(order_quantity.to_string().as_str()); + } + } + // url_build.push_str("&price="); // url_build.push_str(order_price.to_string().as_str()); // match tif { diff --git a/src/main.rs b/src/main.rs index d5733d2..d86c956 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,7 @@ async fn main() -> Result<(), Box> { let (tx_futures_exchange_info, mut rx_futures_exchange_info) = watch::channel(futures_exchange_info_map); let mut rx2_futures_exchange_info = rx_futures_exchange_info.clone(); let mut rx3_futures_exchange_info = rx_futures_exchange_info.clone(); + let mut rx4_futures_exchange_info = rx_futures_exchange_info.clone(); let mut futures_trade_fee = FuturesTradeFee::new(); let (tx_futures_trade_fee, mut rx_futures_trade_fee) = watch::channel(futures_trade_fee); @@ -1021,10 +1022,11 @@ async fn main() -> Result<(), Box> { all_data.rt_price_1d_vec = rx4_rt_price_1d_map.borrow().clone(); all_data.rt_price_1w_vec = rx4_rt_price_1w_map.borrow().clone(); all_data.rt_price_1mon_vec = rx4_rt_price_1mon_map.borrow().clone(); - + let futures_exchange_info = rx4_futures_exchange_info.borrow().clone(); let result = strategy_team::strategy_manager::execute_list_up_for_sell( &all_data, &exchange_info_map, + &futures_exchange_info, &trade_fee_map, ) .await; diff --git a/src/strategy_team/future_strategy_long.rs b/src/strategy_team/future_strategy_long.rs index 463291e..8c92966 100644 --- a/src/strategy_team/future_strategy_long.rs +++ b/src/strategy_team/future_strategy_long.rs @@ -249,7 +249,7 @@ pub async fn list_up_for_buy( Ok(()) } -pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box> { +pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &HashMap,) -> Result<(), Box> { let filled_positions = select_long_filled_positions().await?; let client = ClientBuilder::new() @@ -347,6 +347,7 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box Result<(), Box> { +pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &HashMap) -> Result<(), Box> { let filled_positions = select_short_filled_positions().await?; let client = ClientBuilder::new() @@ -345,6 +345,7 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box, + futures_exchange_info_map: &HashMap, trade_fee_map: &HashMap, ) -> Result<(), Box> { // crate::strategy_team::strategy_001::list_up_for_sell(&all_data, &exchange_info_map, &trade_fee_map).await; @@ -84,8 +85,8 @@ pub async fn execute_list_up_for_sell( // &trade_fee_map, // ) // .await; - crate::strategy_team::future_strategy_long::list_up_for_sell(&all_data).await; - crate::strategy_team::future_strategy_short::list_up_for_sell(&all_data).await; + crate::strategy_team::future_strategy_long::list_up_for_sell(&all_data, futures_exchange_info_map).await; + crate::strategy_team::future_strategy_short::list_up_for_sell(&all_data, futures_exchange_info_map).await; Ok(()) }