Change find() with position()
This commit is contained in:
parent
689a3cd8a7
commit
f45d5da3c3
|
|
@ -439,11 +439,11 @@ pub async fn limit_order_buy(
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let base_asset_precision = exchange_info_vec
|
// let base_asset_precision = exchange_info_vec
|
||||||
.iter()
|
// .iter()
|
||||||
.find(|exchange_info| exchange_info.symbol == element.symbol)
|
// .find(|exchange_info| exchange_info.symbol == element.symbol)
|
||||||
.unwrap()
|
// .unwrap()
|
||||||
.base_asset_precision;
|
// .base_asset_precision;
|
||||||
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
||||||
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
||||||
|
|
||||||
|
|
@ -718,58 +718,57 @@ pub async fn limit_order_sell(
|
||||||
let mut insert_value_container: Vec<String> = Vec::new();
|
let mut insert_value_container: Vec<String> = Vec::new();
|
||||||
let server_epoch = server_epoch().await;
|
let server_epoch = server_epoch().await;
|
||||||
if RUNNING_MODE == SIMUL && buy_ordered_coin.status == "SIMUL" {
|
if RUNNING_MODE == SIMUL && buy_ordered_coin.status == "SIMUL" {
|
||||||
let quote_asset_precision = exchange_info_vec
|
let quote_asset_precision_option = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == buy_ordered_coin.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == buy_ordered_coin.symbol)
|
let trade_fee_option = trade_fee_vec
|
||||||
.unwrap()
|
|
||||||
.quote_asset_precision;
|
|
||||||
let trade_fee = trade_fee_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == buy_ordered_coin.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == buy_ordered_coin.symbol)
|
if quote_asset_precision_option.is_some() && trade_fee_option.is_some() {
|
||||||
.unwrap()
|
let quote_asset_precision = exchange_info_vec[quote_asset_precision_option.unwrap()].quote_asset_precision;
|
||||||
.takercommission;
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
let get_usdt = decimal_mul(sell_base_quantity, sell_base_price)
|
|
||||||
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
let get_usdt = decimal_mul(sell_base_quantity, sell_base_price)
|
||||||
let get_usdt_fee_adjusted = decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
|
||||||
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
||||||
|
let get_usdt_fee_adjusted = decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
||||||
|
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
||||||
|
|
||||||
insert_value_container.push(buy_ordered_coin.symbol.to_string()); // symbol
|
insert_value_container.push(buy_ordered_coin.symbol.to_string()); // symbol
|
||||||
insert_value_container.push(0.to_string()); // buy_order_id
|
insert_value_container.push(0.to_string()); // buy_order_id
|
||||||
insert_value_container.push(0.to_string()); // sell_order_id
|
insert_value_container.push(0.to_string()); // sell_order_id
|
||||||
insert_value_container.push(server_epoch.to_string()); // transact_time
|
insert_value_container.push(server_epoch.to_string()); // transact_time
|
||||||
insert_value_container.push(buy_ordered_coin.close_time.to_string()); // close_time
|
insert_value_container.push(buy_ordered_coin.close_time.to_string()); // close_time
|
||||||
insert_value_container.push(String::from("SIMUL")); // status
|
insert_value_container.push(String::from("SIMUL")); // status
|
||||||
insert_value_container.push(buy_ordered_coin.used_usdt.to_string()); // used_usdt
|
insert_value_container.push(buy_ordered_coin.used_usdt.to_string()); // used_usdt
|
||||||
insert_value_container.push(get_usdt.to_string()); // get_usdt
|
insert_value_container.push(get_usdt.to_string()); // get_usdt
|
||||||
insert_value_container.push(get_usdt_fee_adjusted.to_string()); // get_usdt_fee_adjusted
|
insert_value_container.push(get_usdt_fee_adjusted.to_string()); // get_usdt_fee_adjusted
|
||||||
insert_value_container.push(buy_ordered_coin.buy_price.to_string()); // buy_price
|
insert_value_container.push(buy_ordered_coin.buy_price.to_string()); // buy_price
|
||||||
insert_value_container.push(sell_base_price.to_string()); // sell_price
|
insert_value_container.push(sell_base_price.to_string()); // sell_price
|
||||||
insert_value_container.push(buy_ordered_coin.stoploss.to_string()); // stoploss
|
insert_value_container.push(buy_ordered_coin.stoploss.to_string()); // stoploss
|
||||||
insert_value_container.push(buy_ordered_coin.target_price.to_string()); // target_price
|
insert_value_container.push(buy_ordered_coin.target_price.to_string()); // target_price
|
||||||
insert_value_container.push(sell_base_quantity.to_string()); // base_qty_ordered
|
insert_value_container.push(sell_base_quantity.to_string()); // base_qty_ordered
|
||||||
|
|
||||||
let pure_profit_percent = decimal_mul(
|
let pure_profit_percent = decimal_mul(
|
||||||
decimal_sub(
|
decimal_sub(
|
||||||
decimal_div(get_usdt_fee_adjusted, buy_ordered_coin.used_usdt),
|
decimal_div(get_usdt_fee_adjusted, buy_ordered_coin.used_usdt),
|
||||||
dec!(1),
|
dec!(1),
|
||||||
),
|
),
|
||||||
dec!(100),
|
dec!(100),
|
||||||
);
|
);
|
||||||
insert_value_container.push(pure_profit_percent.to_string()); // pure_profit_percent
|
insert_value_container.push(pure_profit_percent.to_string()); // pure_profit_percent
|
||||||
insert_value_container.push(buy_ordered_coin.maximum_profit_percent.to_string()); // maximum_profit_percent
|
insert_value_container.push(buy_ordered_coin.maximum_profit_percent.to_string()); // maximum_profit_percent
|
||||||
insert_value_container.push(buy_ordered_coin.registerer.to_string()); // registerer
|
insert_value_container.push(buy_ordered_coin.registerer.to_string()); // registerer
|
||||||
insert_value_container.push(buy_ordered_coin.is_long.to_string()); // is_long
|
insert_value_container.push(buy_ordered_coin.is_long.to_string()); // is_long
|
||||||
|
|
||||||
insert_values.push(insert_value_container.clone());
|
insert_values.push(insert_value_container.clone());
|
||||||
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
||||||
|
|
||||||
// delete record in buy_ordered_coin_list
|
// delete record in buy_ordered_coin_list
|
||||||
let delete_table_name = String::from("buy_ordered_coin_list");
|
let delete_table_name = String::from("buy_ordered_coin_list");
|
||||||
let mut delete_condition = String::from("WHERE id = ");
|
let mut delete_condition = String::from("WHERE id = ");
|
||||||
delete_condition.push_str(buy_ordered_coin.id.to_string().as_str());
|
delete_condition.push_str(buy_ordered_coin.id.to_string().as_str());
|
||||||
delete_record(&delete_table_name, &delete_condition).await;
|
delete_record(&delete_table_name, &delete_condition).await;
|
||||||
|
}
|
||||||
} else if RUNNING_MODE == REAL || RUNNING_MODE == TEST {
|
} else if RUNNING_MODE == REAL || RUNNING_MODE == TEST {
|
||||||
// building URL and API-keys
|
// building URL and API-keys
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
|
|
@ -831,86 +830,84 @@ pub async fn limit_order_sell(
|
||||||
.push(T.get("status").unwrap().as_str().unwrap().to_string()); // status
|
.push(T.get("status").unwrap().as_str().unwrap().to_string()); // status
|
||||||
insert_value_container.push(buy_ordered_coin.used_usdt.to_string()); // used_usdt
|
insert_value_container.push(buy_ordered_coin.used_usdt.to_string()); // used_usdt
|
||||||
|
|
||||||
let quote_asset_precision = exchange_info_vec
|
let quote_asset_precision_option = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == buy_ordered_coin.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == buy_ordered_coin.symbol)
|
let trade_fee_option = trade_fee_vec
|
||||||
.unwrap()
|
|
||||||
.quote_asset_precision;
|
|
||||||
let trade_fee = trade_fee_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == buy_ordered_coin.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == buy_ordered_coin.symbol)
|
if quote_asset_precision_option.is_some() && trade_fee_option.is_some() {
|
||||||
.unwrap()
|
let quote_asset_precision = exchange_info_vec[quote_asset_precision_option.unwrap()].quote_asset_precision;
|
||||||
.takercommission;
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let get_usdt_fee_adjusted =
|
let get_usdt_fee_adjusted =
|
||||||
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
||||||
.round_dp_with_strategy(
|
.round_dp_with_strategy(
|
||||||
quote_asset_precision,
|
quote_asset_precision,
|
||||||
RoundingStrategy::ToZero,
|
RoundingStrategy::ToZero,
|
||||||
|
);
|
||||||
|
let ordered_base_qty = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
T.get("origQty").unwrap().as_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
||||||
|
insert_value_container.push(get_usdt.to_string()); // get_usdt
|
||||||
|
insert_value_container.push(get_usdt_fee_adjusted.to_string());
|
||||||
|
// get_usdt_fee_adjusted
|
||||||
|
} else {
|
||||||
|
insert_value_container.push(0.0.to_string()); // get_usdt
|
||||||
|
insert_value_container.push(0.0.to_string()); // get_usdt_fee_adjusted
|
||||||
|
}
|
||||||
|
|
||||||
|
insert_value_container.push(buy_ordered_coin.buy_price.to_string()); // buy_price
|
||||||
|
|
||||||
|
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
||||||
|
let sell_price = decimal_div(get_usdt, ordered_base_qty)
|
||||||
|
.round_dp_with_strategy(
|
||||||
|
quote_asset_precision,
|
||||||
|
RoundingStrategy::ToZero,
|
||||||
|
);
|
||||||
|
insert_value_container.push(sell_price.to_string()); // sell_price
|
||||||
|
} else {
|
||||||
|
insert_value_container.push(0.0.to_string()); // sell_price
|
||||||
|
}
|
||||||
|
|
||||||
|
insert_value_container.push(buy_ordered_coin.stoploss.to_string()); // stoploss
|
||||||
|
insert_value_container.push(buy_ordered_coin.target_price.to_string()); // target_price
|
||||||
|
insert_value_container.push(ordered_base_qty.to_string()); // base_qty_ordered
|
||||||
|
|
||||||
|
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
||||||
|
let pure_profit_percent = decimal_mul(
|
||||||
|
decimal_sub(
|
||||||
|
decimal_div(get_usdt_fee_adjusted, buy_ordered_coin.used_usdt),
|
||||||
|
dec!(1),
|
||||||
|
),
|
||||||
|
dec!(100),
|
||||||
);
|
);
|
||||||
let ordered_base_qty = rust_decimal::prelude::FromStr::from_str(
|
insert_value_container
|
||||||
T.get("origQty").unwrap().as_str().unwrap(),
|
.push(buy_ordered_coin.pure_profit_percent.to_string());
|
||||||
)
|
// pure_profit_percent
|
||||||
.unwrap();
|
} else {
|
||||||
|
insert_value_container.push(0.0.to_string()); // pure_profit_percent
|
||||||
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
}
|
||||||
insert_value_container.push(get_usdt.to_string()); // get_usdt
|
|
||||||
insert_value_container.push(get_usdt_fee_adjusted.to_string());
|
|
||||||
// get_usdt_fee_adjusted
|
|
||||||
} else {
|
|
||||||
insert_value_container.push(0.0.to_string()); // get_usdt
|
|
||||||
insert_value_container.push(0.0.to_string()); // get_usdt_fee_adjusted
|
|
||||||
}
|
|
||||||
|
|
||||||
insert_value_container.push(buy_ordered_coin.buy_price.to_string()); // buy_price
|
|
||||||
|
|
||||||
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
|
||||||
let sell_price = decimal_div(get_usdt, ordered_base_qty)
|
|
||||||
.round_dp_with_strategy(
|
|
||||||
quote_asset_precision,
|
|
||||||
RoundingStrategy::ToZero,
|
|
||||||
);
|
|
||||||
insert_value_container.push(sell_price.to_string()); // sell_price
|
|
||||||
} else {
|
|
||||||
insert_value_container.push(0.0.to_string()); // sell_price
|
|
||||||
}
|
|
||||||
|
|
||||||
insert_value_container.push(buy_ordered_coin.stoploss.to_string()); // stoploss
|
|
||||||
insert_value_container.push(buy_ordered_coin.target_price.to_string()); // target_price
|
|
||||||
insert_value_container.push(ordered_base_qty.to_string()); // base_qty_ordered
|
|
||||||
|
|
||||||
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
|
||||||
let pure_profit_percent = decimal_mul(
|
|
||||||
decimal_sub(
|
|
||||||
decimal_div(get_usdt_fee_adjusted, buy_ordered_coin.used_usdt),
|
|
||||||
dec!(1),
|
|
||||||
),
|
|
||||||
dec!(100),
|
|
||||||
);
|
|
||||||
insert_value_container
|
insert_value_container
|
||||||
.push(buy_ordered_coin.pure_profit_percent.to_string());
|
.push(buy_ordered_coin.maximum_profit_percent.to_string()); // maximum_profit_percent
|
||||||
// pure_profit_percent
|
insert_value_container.push(buy_ordered_coin.registerer.to_string()); // registerer
|
||||||
} else {
|
insert_value_container.push(buy_ordered_coin.is_long.to_string()); // is_long
|
||||||
insert_value_container.push(0.0.to_string()); // pure_profit_percent
|
|
||||||
|
insert_values.push(insert_value_container.clone());
|
||||||
|
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
||||||
|
|
||||||
|
// delete record in buy_ordered_coin_list
|
||||||
|
let delete_table_name = String::from("buy_ordered_coin_list");
|
||||||
|
let mut delete_condition = String::from("WHERE id = ");
|
||||||
|
delete_condition.push_str(buy_ordered_coin.id.to_string().as_str());
|
||||||
|
delete_record(&delete_table_name, &delete_condition).await;
|
||||||
}
|
}
|
||||||
insert_value_container
|
|
||||||
.push(buy_ordered_coin.maximum_profit_percent.to_string()); // maximum_profit_percent
|
|
||||||
insert_value_container.push(buy_ordered_coin.registerer.to_string()); // registerer
|
|
||||||
insert_value_container.push(buy_ordered_coin.is_long.to_string()); // is_long
|
|
||||||
|
|
||||||
insert_values.push(insert_value_container.clone());
|
|
||||||
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
|
||||||
|
|
||||||
// delete record in buy_ordered_coin_list
|
|
||||||
let delete_table_name = String::from("buy_ordered_coin_list");
|
|
||||||
let mut delete_condition = String::from("WHERE id = ");
|
|
||||||
delete_condition.push_str(buy_ordered_coin.id.to_string().as_str());
|
|
||||||
delete_record(&delete_table_name, &delete_condition).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -1188,57 +1185,58 @@ pub async fn cancel_buy_order(
|
||||||
status_value_build.push('\'');
|
status_value_build.push('\'');
|
||||||
|
|
||||||
// calculate values to be updated
|
// calculate values to be updated
|
||||||
let trade_fee = trade_fee_vec
|
let trade_fee_option = trade_fee_vec
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == order.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
|
|
||||||
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
let base_asset_precision_option = exchange_info_vec
|
||||||
T.get("executedQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let base_qty_fee_adjusted =
|
|
||||||
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee));
|
|
||||||
|
|
||||||
let base_asset_precision = exchange_info_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == order.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.base_asset_precision;
|
|
||||||
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
|
||||||
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
|
||||||
|
|
||||||
let update_values = vec![
|
if trade_fee_option.is_some() && base_asset_precision_option.is_some() {
|
||||||
(String::from("status"), status_value_build), // status
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
(String::from("used_usdt"), cummulative_quote_qty.to_string()), // used_usdt
|
|
||||||
(String::from("buy_price"), buy_price.to_string()), // buy_price
|
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
||||||
(
|
T.get("executedQty").unwrap().as_str().unwrap(),
|
||||||
String::from("base_qty_ordered"),
|
)
|
||||||
base_qty_ordered.to_string(),
|
|
||||||
), // base_qty_ordered
|
|
||||||
(
|
|
||||||
String::from("base_qty_fee_adjusted"),
|
|
||||||
base_qty_fee_adjusted.to_string(),
|
|
||||||
), // base_qty_fee_adjusted
|
|
||||||
];
|
|
||||||
let update_condition = vec![
|
|
||||||
(String::from("order_id"), order.order_id.to_string()),
|
|
||||||
(String::from("symbol"), order.symbol.clone()),
|
|
||||||
];
|
|
||||||
update_record3(&table_name, &update_values, &update_condition)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// update available_usdt
|
let base_qty_fee_adjusted =
|
||||||
if order.used_usdt > cummulative_quote_qty {
|
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee));
|
||||||
add_available_usdt(decimal_sub(order.used_usdt, cummulative_quote_qty));
|
|
||||||
} else {
|
let base_asset_precision = exchange_info_vec[base_asset_precision_option.unwrap()].base_asset_precision;
|
||||||
sub_available_usdt(decimal_sub(cummulative_quote_qty, order.used_usdt));
|
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
||||||
|
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
||||||
|
|
||||||
|
let update_values = vec![
|
||||||
|
(String::from("status"), status_value_build), // status
|
||||||
|
(String::from("used_usdt"), cummulative_quote_qty.to_string()), // used_usdt
|
||||||
|
(String::from("buy_price"), buy_price.to_string()), // buy_price
|
||||||
|
(
|
||||||
|
String::from("base_qty_ordered"),
|
||||||
|
base_qty_ordered.to_string(),
|
||||||
|
), // base_qty_ordered
|
||||||
|
(
|
||||||
|
String::from("base_qty_fee_adjusted"),
|
||||||
|
base_qty_fee_adjusted.to_string(),
|
||||||
|
), // base_qty_fee_adjusted
|
||||||
|
];
|
||||||
|
let update_condition = vec![
|
||||||
|
(String::from("order_id"), order.order_id.to_string()),
|
||||||
|
(String::from("symbol"), order.symbol.clone()),
|
||||||
|
];
|
||||||
|
update_record3(&table_name, &update_values, &update_condition)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// update available_usdt
|
||||||
|
if order.used_usdt > cummulative_quote_qty {
|
||||||
|
add_available_usdt(decimal_sub(order.used_usdt, cummulative_quote_qty));
|
||||||
|
} else {
|
||||||
|
sub_available_usdt(decimal_sub(cummulative_quote_qty, order.used_usdt));
|
||||||
|
}
|
||||||
|
println!("partially buy {}", order.symbol);
|
||||||
}
|
}
|
||||||
println!("partially buy {}", order.symbol);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if T.get("code").is_some() {
|
} else if T.get("code").is_some() {
|
||||||
|
|
@ -1371,162 +1369,148 @@ pub async fn cancel_sell_order(
|
||||||
insert_values.push(insert_value_container.clone());
|
insert_values.push(insert_value_container.clone());
|
||||||
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
insert_records(&insert_table_name, &insert_columns, &insert_values).await;
|
||||||
} else {
|
} else {
|
||||||
if base_qty_executed == base_qty_ordered {
|
let quote_asset_precision_option = exchange_info_vec
|
||||||
// FILLED case
|
|
||||||
// update status FILLED
|
|
||||||
let quote_asset_precision = exchange_info_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == order.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == order.symbol)
|
let trade_fee_option = trade_fee_vec
|
||||||
.unwrap()
|
|
||||||
.quote_asset_precision;
|
|
||||||
let trade_fee = trade_fee_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == order.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
|
|
||||||
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
if quote_asset_precision_option.is_some() && trade_fee_option.is_some() {
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
let quote_asset_precision = exchange_info_vec[quote_asset_precision_option.unwrap()].quote_asset_precision;
|
||||||
)
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
.unwrap();
|
if base_qty_executed == base_qty_ordered {
|
||||||
let get_usdt_fee_adjusted =
|
// FILLED case
|
||||||
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
// update status FILLED
|
||||||
|
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let get_usdt_fee_adjusted =
|
||||||
|
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
||||||
|
.round_dp_with_strategy(
|
||||||
|
quote_asset_precision,
|
||||||
|
RoundingStrategy::ToZero,
|
||||||
|
);
|
||||||
|
let sell_price = decimal_div(get_usdt, base_qty_executed)
|
||||||
.round_dp_with_strategy(
|
.round_dp_with_strategy(
|
||||||
quote_asset_precision,
|
quote_asset_precision,
|
||||||
RoundingStrategy::ToZero,
|
RoundingStrategy::ToZero,
|
||||||
);
|
);
|
||||||
let sell_price = decimal_div(get_usdt, base_qty_executed)
|
let pure_profit_percent = decimal_mul(
|
||||||
.round_dp_with_strategy(
|
decimal_sub(
|
||||||
quote_asset_precision,
|
decimal_div(get_usdt_fee_adjusted, order.used_usdt),
|
||||||
RoundingStrategy::ToZero,
|
dec!(1),
|
||||||
|
),
|
||||||
|
dec!(100),
|
||||||
);
|
);
|
||||||
let pure_profit_percent = decimal_mul(
|
|
||||||
decimal_sub(
|
|
||||||
decimal_div(get_usdt_fee_adjusted, order.used_usdt),
|
|
||||||
dec!(1),
|
|
||||||
),
|
|
||||||
dec!(100),
|
|
||||||
);
|
|
||||||
|
|
||||||
let table_name = String::from("sell_ordered_coin_list");
|
let table_name = String::from("sell_ordered_coin_list");
|
||||||
let mut value_build = String::from("\'");
|
let mut value_build = String::from("\'");
|
||||||
value_build.push_str("FILLED");
|
value_build.push_str("FILLED");
|
||||||
value_build.push('\'');
|
value_build.push('\'');
|
||||||
|
|
||||||
let update_values = vec![
|
let update_values = vec![
|
||||||
(String::from("status"), value_build),
|
(String::from("status"), value_build),
|
||||||
(String::from("get_usdt"), get_usdt.to_string()),
|
(String::from("get_usdt"), get_usdt.to_string()),
|
||||||
(
|
(
|
||||||
String::from("get_usdt_fee_adjusted"),
|
String::from("get_usdt_fee_adjusted"),
|
||||||
get_usdt_fee_adjusted.to_string(),
|
get_usdt_fee_adjusted.to_string(),
|
||||||
),
|
),
|
||||||
(String::from("sell_price"), sell_price.to_string()),
|
(String::from("sell_price"), sell_price.to_string()),
|
||||||
(
|
(
|
||||||
String::from("pure_profit_percent"),
|
String::from("pure_profit_percent"),
|
||||||
pure_profit_percent.to_string(),
|
pure_profit_percent.to_string(),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
||||||
update_record3(&table_name, &update_values, &update_condition)
|
update_record3(&table_name, &update_values, &update_condition)
|
||||||
.await
|
.await
|
||||||
|
.unwrap();
|
||||||
|
} else {
|
||||||
|
// PARTIALLY FILLED case
|
||||||
|
// reflect partially filled information and update status with FILLED
|
||||||
|
let used_usdt = decimal_mul(base_qty_executed, order.buy_price);
|
||||||
|
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
let get_usdt_fee_adjusted =
|
||||||
// PARTIALLY FILLED case
|
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
||||||
// reflect partially filled information and update status with FILLED
|
.round_dp_with_strategy(
|
||||||
let quote_asset_precision = exchange_info_vec
|
quote_asset_precision,
|
||||||
.iter()
|
RoundingStrategy::ToZero,
|
||||||
// FIXME: find() should be position()
|
);
|
||||||
.find(|exchange_info| exchange_info.symbol == order.symbol)
|
let rest_used_usdt = decimal_sub(order.used_usdt, used_usdt);
|
||||||
.unwrap()
|
let sell_price = decimal_div(get_usdt, base_qty_executed)
|
||||||
.quote_asset_precision;
|
|
||||||
let trade_fee = trade_fee_vec
|
|
||||||
.iter()
|
|
||||||
// FIXME: find() should be position()
|
|
||||||
.find(|trade_fee| trade_fee.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
let used_usdt = decimal_mul(base_qty_executed, order.buy_price);
|
|
||||||
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let get_usdt_fee_adjusted =
|
|
||||||
decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
|
||||||
.round_dp_with_strategy(
|
.round_dp_with_strategy(
|
||||||
quote_asset_precision,
|
quote_asset_precision,
|
||||||
RoundingStrategy::ToZero,
|
RoundingStrategy::ToZero,
|
||||||
);
|
);
|
||||||
let rest_used_usdt = decimal_sub(order.used_usdt, used_usdt);
|
let pure_profit_percent = decimal_mul(
|
||||||
let sell_price = decimal_div(get_usdt, base_qty_executed)
|
decimal_sub(decimal_div(get_usdt_fee_adjusted, get_usdt), dec!(1)),
|
||||||
.round_dp_with_strategy(
|
dec!(100),
|
||||||
quote_asset_precision,
|
|
||||||
RoundingStrategy::ToZero,
|
|
||||||
);
|
);
|
||||||
let pure_profit_percent = decimal_mul(
|
|
||||||
decimal_sub(decimal_div(get_usdt_fee_adjusted, get_usdt), dec!(1)),
|
|
||||||
dec!(100),
|
|
||||||
);
|
|
||||||
|
|
||||||
let table_name = String::from("sell_ordered_coin_list");
|
let table_name = String::from("sell_ordered_coin_list");
|
||||||
let mut value_build = String::from("\'");
|
let mut value_build = String::from("\'");
|
||||||
value_build.push_str("FILLED");
|
value_build.push_str("FILLED");
|
||||||
value_build.push('\'');
|
value_build.push('\'');
|
||||||
|
|
||||||
let update_values = vec![
|
let update_values = vec![
|
||||||
(String::from("status"), value_build),
|
(String::from("status"), value_build),
|
||||||
(String::from("used_usdt"), used_usdt.to_string()),
|
(String::from("used_usdt"), used_usdt.to_string()),
|
||||||
(String::from("get_usdt"), get_usdt.to_string()),
|
(String::from("get_usdt"), get_usdt.to_string()),
|
||||||
(
|
(
|
||||||
String::from("get_usdt_fee_adjusted"),
|
String::from("get_usdt_fee_adjusted"),
|
||||||
get_usdt_fee_adjusted.to_string(),
|
get_usdt_fee_adjusted.to_string(),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
String::from("base_qty_ordered"),
|
String::from("base_qty_ordered"),
|
||||||
base_qty_executed.to_string(),
|
base_qty_executed.to_string(),
|
||||||
),
|
),
|
||||||
(String::from("sell_price"), sell_price.to_string()),
|
(String::from("sell_price"), sell_price.to_string()),
|
||||||
(
|
(
|
||||||
String::from("pure_profit_percent"),
|
String::from("pure_profit_percent"),
|
||||||
pure_profit_percent.to_string(),
|
pure_profit_percent.to_string(),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
||||||
update_record3(&table_name, &update_values, &update_condition)
|
update_record3(&table_name, &update_values, &update_condition)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// insert record in [buy_ordered_coin_list]
|
// insert record in [buy_ordered_coin_list]
|
||||||
let rest_base_qty = decimal_sub(base_qty_ordered, base_qty_executed);
|
let rest_base_qty = decimal_sub(base_qty_ordered, base_qty_executed);
|
||||||
let rest_base_qty_fee_adjusted =
|
let rest_base_qty_fee_adjusted =
|
||||||
decimal_mul(rest_base_qty, decimal_sub(dec!(1), trade_fee));
|
decimal_mul(rest_base_qty, decimal_sub(dec!(1), trade_fee));
|
||||||
let mut insert_values: Vec<Vec<String>> = Vec::new();
|
let mut insert_values: Vec<Vec<String>> = Vec::new();
|
||||||
let mut insert_value_container: Vec<String> = Vec::new();
|
let mut insert_value_container: Vec<String> = Vec::new();
|
||||||
let server_epoch = server_epoch().await;
|
let server_epoch = server_epoch().await;
|
||||||
insert_value_container.push(order.symbol.clone()); // symbol
|
insert_value_container.push(order.symbol.clone()); // symbol
|
||||||
insert_value_container.push(order.buy_order_id.to_string()); // order_id
|
insert_value_container.push(order.buy_order_id.to_string()); // order_id
|
||||||
insert_value_container.push(server_epoch.to_string()); // transact_time
|
insert_value_container.push(server_epoch.to_string()); // transact_time
|
||||||
insert_value_container.push(order.close_time.to_string()); // close_time
|
insert_value_container.push(order.close_time.to_string()); // close_time
|
||||||
insert_value_container.push(String::from("FILLED")); // status
|
insert_value_container.push(String::from("FILLED")); // status
|
||||||
insert_value_container.push(rest_used_usdt.to_string()); // used_usdt
|
insert_value_container.push(rest_used_usdt.to_string()); // used_usdt
|
||||||
insert_value_container.push(0.0.to_string()); // expected_get_usdt
|
insert_value_container.push(0.0.to_string()); // expected_get_usdt
|
||||||
insert_value_container.push(0.0.to_string()); // expected_usdt_profit
|
insert_value_container.push(0.0.to_string()); // expected_usdt_profit
|
||||||
insert_value_container.push(order.buy_price.to_string()); // buy_price
|
insert_value_container.push(order.buy_price.to_string()); // buy_price
|
||||||
insert_value_container.push(0.0.to_string()); // current_price
|
insert_value_container.push(0.0.to_string()); // current_price
|
||||||
insert_value_container.push(order.stoploss.to_string()); // stoploss
|
insert_value_container.push(order.stoploss.to_string()); // stoploss
|
||||||
insert_value_container.push(order.target_price.to_string()); // target_price
|
insert_value_container.push(order.target_price.to_string()); // target_price
|
||||||
insert_value_container.push(rest_base_qty.to_string()); // base_qty_ordered
|
insert_value_container.push(rest_base_qty.to_string()); // base_qty_ordered
|
||||||
insert_value_container.push(rest_base_qty_fee_adjusted.to_string()); // base_qty_fee_adjusted
|
insert_value_container.push(rest_base_qty_fee_adjusted.to_string()); // base_qty_fee_adjusted
|
||||||
insert_value_container.push(0.0.to_string()); // pure_profit_percent
|
insert_value_container.push(0.0.to_string()); // pure_profit_percent
|
||||||
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
|
insert_value_container.push(0.0.to_string()); // minimum_profit_percent
|
||||||
insert_value_container.push(0.0.to_string()); // maximum_profit_percent
|
insert_value_container.push(0.0.to_string()); // maximum_profit_percent
|
||||||
insert_value_container.push(order.registerer.to_string()); // registerer
|
insert_value_container.push(order.registerer.to_string()); // registerer
|
||||||
insert_value_container.push(order.is_long.to_string()); // is_long
|
insert_value_container.push(order.is_long.to_string()); // is_long
|
||||||
|
|
||||||
insert_values.push(insert_value_container.clone());
|
insert_values.push(insert_value_container.clone());
|
||||||
insert_records(&insert_table_name, &insert_columns, &insert_values)
|
insert_records(&insert_table_name, &insert_columns, &insert_values)
|
||||||
.await;
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1675,63 +1659,63 @@ pub async fn query_buy_order(
|
||||||
value_build.push('\'');
|
value_build.push('\'');
|
||||||
|
|
||||||
// calculate values to be updated
|
// calculate values to be updated
|
||||||
let trade_fee = trade_fee_vec
|
let trade_fee_option = trade_fee_vec
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == order.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == order.symbol)
|
let base_asset_precision_option = exchange_info_vec
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
|
|
||||||
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("executedQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let base_qty_fee_adjusted =
|
|
||||||
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee));
|
|
||||||
|
|
||||||
let cummulative_quote_qty = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let base_asset_precision = exchange_info_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == order.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.base_asset_precision;
|
|
||||||
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
|
||||||
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
|
||||||
|
|
||||||
let update_values = vec![
|
if trade_fee_option.is_some() && base_asset_precision_option.is_some() {
|
||||||
(String::from("status"), value_build), // status
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
(String::from("used_usdt"), cummulative_quote_qty.to_string()), // used_usdt
|
let base_asset_precision = exchange_info_vec[base_asset_precision_option.unwrap()].base_asset_precision;
|
||||||
(String::from("buy_price"), buy_price.to_string()), // buy_price
|
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
||||||
(
|
T.get("executedQty").unwrap().as_str().unwrap(),
|
||||||
String::from("base_qty_ordered"),
|
)
|
||||||
base_qty_ordered.to_string(),
|
.unwrap();
|
||||||
), // base_qty_ordered
|
let base_qty_fee_adjusted =
|
||||||
(
|
decimal_mul(base_qty_ordered, decimal_sub(dec!(1), trade_fee));
|
||||||
String::from("base_qty_fee_adjusted"),
|
|
||||||
base_qty_fee_adjusted.to_string(),
|
let cummulative_quote_qty = rust_decimal::prelude::FromStr::from_str(
|
||||||
), // base_qty_fee_adjusted
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
];
|
)
|
||||||
let update_condition = vec![
|
|
||||||
(String::from("order_id"), order.order_id.to_string()),
|
|
||||||
(String::from("symbol"), order.symbol.clone()),
|
|
||||||
];
|
|
||||||
update_record3(&table_name, &update_values, &update_condition)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
let buy_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
||||||
println!("buy {}", order.symbol);
|
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
||||||
// update available_usdt
|
|
||||||
if order.used_usdt > cummulative_quote_qty {
|
let update_values = vec![
|
||||||
add_available_usdt(decimal_sub(order.used_usdt, cummulative_quote_qty));
|
(String::from("status"), value_build), // status
|
||||||
} else {
|
(String::from("used_usdt"), cummulative_quote_qty.to_string()), // used_usdt
|
||||||
sub_available_usdt(decimal_sub(cummulative_quote_qty, order.used_usdt));
|
(String::from("buy_price"), buy_price.to_string()), // buy_price
|
||||||
|
(
|
||||||
|
String::from("base_qty_ordered"),
|
||||||
|
base_qty_ordered.to_string(),
|
||||||
|
), // base_qty_ordered
|
||||||
|
(
|
||||||
|
String::from("base_qty_fee_adjusted"),
|
||||||
|
base_qty_fee_adjusted.to_string(),
|
||||||
|
), // base_qty_fee_adjusted
|
||||||
|
];
|
||||||
|
let update_condition = vec![
|
||||||
|
(String::from("order_id"), order.order_id.to_string()),
|
||||||
|
(String::from("symbol"), order.symbol.clone()),
|
||||||
|
];
|
||||||
|
update_record3(&table_name, &update_values, &update_condition)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
||||||
|
println!("buy {}", order.symbol);
|
||||||
|
// update available_usdt
|
||||||
|
if order.used_usdt > cummulative_quote_qty {
|
||||||
|
add_available_usdt(decimal_sub(order.used_usdt, cummulative_quote_qty));
|
||||||
|
} else {
|
||||||
|
sub_available_usdt(decimal_sub(cummulative_quote_qty, order.used_usdt));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if T.get("status").unwrap().as_str().unwrap() == "CANCELED" {
|
} else if T.get("status").unwrap().as_str().unwrap() == "CANCELED" {
|
||||||
let update_table_name = String::from("suggested_coin_list");
|
let update_table_name = String::from("suggested_coin_list");
|
||||||
let update_condition = vec![
|
let update_condition = vec![
|
||||||
|
|
@ -1798,57 +1782,56 @@ pub async fn query_sell_order(
|
||||||
if T.get("status").unwrap().as_str().unwrap() == "FILLED"
|
if T.get("status").unwrap().as_str().unwrap() == "FILLED"
|
||||||
|| T.get("status").unwrap().as_str().unwrap() == "PARTIALLY_FILLED"
|
|| T.get("status").unwrap().as_str().unwrap() == "PARTIALLY_FILLED"
|
||||||
{
|
{
|
||||||
let quote_asset_precision = exchange_info_vec
|
let quote_asset_precision_option = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|exchange_info| exchange_info.symbol == order.symbol);
|
||||||
.find(|exchange_info| exchange_info.symbol == order.symbol)
|
let trade_fee_option = trade_fee_vec
|
||||||
.unwrap()
|
|
||||||
.quote_asset_precision;
|
|
||||||
let trade_fee = trade_fee_vec
|
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME: find() should be position()
|
.position(|trade_fee| trade_fee.symbol == order.symbol);
|
||||||
.find(|trade_fee| trade_fee.symbol == order.symbol)
|
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let get_usdt_fee_adjusted = decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
|
||||||
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
|
||||||
let ordered_base_qty = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("executedQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let sell_price = decimal_div(get_usdt, ordered_base_qty)
|
|
||||||
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
|
||||||
let pure_profit_percent = decimal_mul(
|
|
||||||
decimal_sub(decimal_div(get_usdt_fee_adjusted, order.used_usdt), dec!(1)),
|
|
||||||
dec!(100),
|
|
||||||
);
|
|
||||||
|
|
||||||
let table_name = String::from("sell_ordered_coin_list");
|
if quote_asset_precision_option.is_some() && trade_fee_option.is_some() {
|
||||||
let mut value_build = String::from("\'");
|
let quote_asset_precision = exchange_info_vec[quote_asset_precision_option.unwrap()].quote_asset_precision;
|
||||||
value_build.push_str(T.get("status").unwrap().as_str().unwrap());
|
let trade_fee = trade_fee_vec[trade_fee_option.unwrap()].takercommission;
|
||||||
value_build.push('\'');
|
let get_usdt = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
T.get("cummulativeQuoteQty").unwrap().as_str().unwrap(),
|
||||||
let update_values = vec![
|
)
|
||||||
(String::from("status"), value_build),
|
|
||||||
(String::from("get_usdt"), get_usdt.to_string()),
|
|
||||||
(
|
|
||||||
String::from("get_usdt_fee_adjusted"),
|
|
||||||
get_usdt_fee_adjusted.to_string(),
|
|
||||||
),
|
|
||||||
(String::from("sell_price"), sell_price.to_string()),
|
|
||||||
(
|
|
||||||
String::from("pure_profit_percent"),
|
|
||||||
pure_profit_percent.to_string(),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
|
||||||
update_record3(&table_name, &update_values, &update_condition)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
let get_usdt_fee_adjusted = decimal_mul(get_usdt, decimal_sub(dec!(1), trade_fee))
|
||||||
|
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
||||||
|
let ordered_base_qty = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
T.get("executedQty").unwrap().as_str().unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let sell_price = decimal_div(get_usdt, ordered_base_qty)
|
||||||
|
.round_dp_with_strategy(quote_asset_precision, RoundingStrategy::ToZero);
|
||||||
|
let pure_profit_percent = decimal_mul(
|
||||||
|
decimal_sub(decimal_div(get_usdt_fee_adjusted, order.used_usdt), dec!(1)),
|
||||||
|
dec!(100),
|
||||||
|
);
|
||||||
|
|
||||||
|
let table_name = String::from("sell_ordered_coin_list");
|
||||||
|
let mut value_build = String::from("\'");
|
||||||
|
value_build.push_str(T.get("status").unwrap().as_str().unwrap());
|
||||||
|
value_build.push('\'');
|
||||||
|
|
||||||
|
let update_values = vec![
|
||||||
|
(String::from("status"), value_build),
|
||||||
|
(String::from("get_usdt"), get_usdt.to_string()),
|
||||||
|
(
|
||||||
|
String::from("get_usdt_fee_adjusted"),
|
||||||
|
get_usdt_fee_adjusted.to_string(),
|
||||||
|
),
|
||||||
|
(String::from("sell_price"), sell_price.to_string()),
|
||||||
|
(
|
||||||
|
String::from("pure_profit_percent"),
|
||||||
|
pure_profit_percent.to_string(),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
let update_condition = vec![(String::from("id"), order.id.to_string())];
|
||||||
|
update_record3(&table_name, &update_values, &update_condition)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
|
|
@ -252,10 +252,10 @@ pub async fn list_up_for_sell(
|
||||||
|
|
||||||
let lot_step_size_option = exchange_info_vec
|
let lot_step_size_option = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
.find(|exchange_info| exchange_info.symbol == element.symbol);
|
.position(|exchange_info| exchange_info.symbol == element.symbol);
|
||||||
let quote_commission_precision_option = exchange_info_vec
|
let quote_commission_precision_option = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
.find(|exchange_info| exchange_info.symbol == element.symbol);
|
.position(|exchange_info| exchange_info.symbol == element.symbol);
|
||||||
|
|
||||||
let opclo_30m_option = all_data
|
let opclo_30m_option = all_data
|
||||||
.rt_price_30m_vec
|
.rt_price_30m_vec
|
||||||
|
|
@ -266,9 +266,9 @@ pub async fn list_up_for_sell(
|
||||||
&& quote_commission_precision_option.is_some()
|
&& quote_commission_precision_option.is_some()
|
||||||
&& opclo_30m_option.is_some()
|
&& opclo_30m_option.is_some()
|
||||||
{
|
{
|
||||||
let lot_step_size = lot_step_size_option.unwrap().stepsize;
|
let lot_step_size = exchange_info_vec[lot_step_size_option.unwrap()].stepsize;
|
||||||
let quote_commission_precision = quote_commission_precision_option
|
let quote_commission_precision = exchange_info_vec[quote_commission_precision_option
|
||||||
.unwrap()
|
.unwrap()]
|
||||||
.quote_commission_precision;
|
.quote_commission_precision;
|
||||||
let base_qty_to_be_ordered =
|
let base_qty_to_be_ordered =
|
||||||
element.base_qty_fee_adjusted.round_dp_with_strategy(
|
element.base_qty_fee_adjusted.round_dp_with_strategy(
|
||||||
|
|
@ -277,8 +277,8 @@ pub async fn list_up_for_sell(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (element.is_long == 0 || element.is_long == 1) && !element.current_price.is_zero() {
|
if (element.is_long == 0 || element.is_long == 1) && !element.current_price.is_zero() {
|
||||||
if element.current_price >= element.target_price {
|
if element.current_price >= element.target_price && element.pure_profit_percent >= 0.1 {
|
||||||
println!("target selling {} {}", element.symbol, element.pure_profit_percent);
|
println!("target selling {} {:.2}", element.symbol, element.pure_profit_percent);
|
||||||
limit_order_sell(
|
limit_order_sell(
|
||||||
&element,
|
&element,
|
||||||
element.current_price,
|
element.current_price,
|
||||||
|
|
@ -289,7 +289,7 @@ pub async fn list_up_for_sell(
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
} else if element.current_price <= element.stoploss {
|
} else if element.current_price <= element.stoploss {
|
||||||
println!("stoploss selling {} {}", element.symbol, element.pure_profit_percent);
|
println!("stoploss selling {} {:.2}", element.symbol, element.pure_profit_percent);
|
||||||
limit_order_sell(
|
limit_order_sell(
|
||||||
&element,
|
&element,
|
||||||
element.current_price,
|
element.current_price,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user