Seperate quantity of close position

This commit is contained in:
Sik Yoon 2024-05-26 16:30:47 +09:00
parent 1c8f0d1eec
commit 85935e553b
5 changed files with 19 additions and 7 deletions

View File

@ -254,6 +254,7 @@ pub async fn limit_order_close(
tif: TimeInForce, tif: TimeInForce,
order_price: Decimal, order_price: Decimal,
order_quantity: Decimal, order_quantity: Decimal,
futures_exchange_info_map: &HashMap<String, FuturesExchangeInfo>,
client: &Client, client: &Client,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let update_table_name = String::from("future_ordered_coin_list"); 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("&side=BUY");
} }
url_build.push_str("&type=MARKET"); 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("&price=");
// url_build.push_str(order_price.to_string().as_str()); // url_build.push_str(order_price.to_string().as_str());
// match tif { // match tif {

View File

@ -35,6 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (tx_futures_exchange_info, mut rx_futures_exchange_info) = watch::channel(futures_exchange_info_map); 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 rx2_futures_exchange_info = rx_futures_exchange_info.clone();
let mut rx3_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 mut futures_trade_fee = FuturesTradeFee::new();
let (tx_futures_trade_fee, mut rx_futures_trade_fee) = watch::channel(futures_trade_fee); let (tx_futures_trade_fee, mut rx_futures_trade_fee) = watch::channel(futures_trade_fee);
@ -1021,10 +1022,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
all_data.rt_price_1d_vec = rx4_rt_price_1d_map.borrow().clone(); 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_1w_vec = rx4_rt_price_1w_map.borrow().clone();
all_data.rt_price_1mon_vec = rx4_rt_price_1mon_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( let result = strategy_team::strategy_manager::execute_list_up_for_sell(
&all_data, &all_data,
&exchange_info_map, &exchange_info_map,
&futures_exchange_info,
&trade_fee_map, &trade_fee_map,
) )
.await; .await;

View File

@ -249,7 +249,7 @@ pub async fn list_up_for_buy(
Ok(()) Ok(())
} }
pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &HashMap<String, FuturesExchangeInfo>,) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_positions = select_long_filled_positions().await?; let filled_positions = select_long_filled_positions().await?;
let client = ClientBuilder::new() let client = ClientBuilder::new()
@ -347,6 +347,7 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
TimeInForce::Gtc, TimeInForce::Gtc,
element.current_price, element.current_price,
element.base_qty_ordered, element.base_qty_ordered,
&futures_exchange_info_map,
&client &client
) )
.await; .await;

View File

@ -249,7 +249,7 @@ pub async fn list_up_for_buy(
Ok(()) Ok(())
} }
pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { pub async fn list_up_for_sell(all_data: &AllData, futures_exchange_info_map: &HashMap<String, FuturesExchangeInfo>) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filled_positions = select_short_filled_positions().await?; let filled_positions = select_short_filled_positions().await?;
let client = ClientBuilder::new() let client = ClientBuilder::new()
@ -345,6 +345,7 @@ pub async fn list_up_for_sell(all_data: &AllData) -> Result<(), Box<dyn std::err
TimeInForce::Gtc, TimeInForce::Gtc,
element.current_price, element.current_price,
element.base_qty_ordered, element.base_qty_ordered,
&futures_exchange_info_map,
&client &client
) )
.await; .await;

View File

@ -52,6 +52,7 @@ pub async fn execute_list_up_for_buy(
pub async fn execute_list_up_for_sell( pub async fn execute_list_up_for_sell(
all_data: &AllData, all_data: &AllData,
exchange_info_map: &HashMap<String, ExchangeInfo>, exchange_info_map: &HashMap<String, ExchangeInfo>,
futures_exchange_info_map: &HashMap<String, FuturesExchangeInfo>,
trade_fee_map: &HashMap<String, TradeFee>, trade_fee_map: &HashMap<String, TradeFee>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// crate::strategy_team::strategy_001::list_up_for_sell(&all_data, &exchange_info_map, &trade_fee_map).await; // 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, // &trade_fee_map,
// ) // )
// .await; // .await;
crate::strategy_team::future_strategy_long::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).await; crate::strategy_team::future_strategy_short::list_up_for_sell(&all_data, futures_exchange_info_map).await;
Ok(()) Ok(())
} }