Fix update record
This commit is contained in:
parent
1e06080ce6
commit
80252e235b
|
|
@ -349,30 +349,6 @@ pub async fn limit_order_close(
|
||||||
println!("Closing {} {} (Partially filled)", entry_coin_info.position, entry_coin_info.symbol);
|
println!("Closing {} {} (Partially filled)", entry_coin_info.position, entry_coin_info.symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("origQty").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let cummulative_quote_qty = rust_decimal::prelude::FromStr::from_str(
|
|
||||||
T.get("cumQuote").unwrap().as_str().unwrap(),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
// let base_asset_precision = exchange_info_vec
|
|
||||||
// .iter()
|
|
||||||
// .find(|exchange_info| exchange_info.symbol == element.symbol)
|
|
||||||
// .unwrap()
|
|
||||||
// .base_asset_precision;
|
|
||||||
let entry_price = decimal_div(cummulative_quote_qty, base_qty_ordered)
|
|
||||||
.round_dp_with_strategy(8, RoundingStrategy::ToZero);
|
|
||||||
|
|
||||||
update_values.push((String::from("used_usdt"), cummulative_quote_qty.to_string()));
|
|
||||||
update_values.push((String::from("entry_price"), entry_price.to_string()));
|
|
||||||
update_values.push((String::from("base_qty_ordered"), base_qty_ordered.to_string()));
|
|
||||||
|
|
||||||
// reflect available_usdt in [asset_manage_announcement]
|
|
||||||
// sub_available_usdt(cummulative_quote_qty).await;
|
|
||||||
sub_future_available_usdt(cummulative_quote_qty).await;
|
|
||||||
|
|
||||||
let update_condition = vec![(String::from("id"), entry_coin_info.id.to_string())];
|
let update_condition = vec![(String::from("id"), entry_coin_info.id.to_string())];
|
||||||
update_record2(&update_table_name, &update_values, &update_condition)
|
update_record2(&update_table_name, &update_values, &update_condition)
|
||||||
|
|
@ -723,76 +699,60 @@ pub async fn query_open_closing_order(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let body = res.text_with_charset("utf-8").await.unwrap();
|
let body = res.text_with_charset("utf-8").await.unwrap();
|
||||||
println!("body: {}", body);
|
|
||||||
// deserialize JSON and then update record in table
|
// deserialize JSON and then update record in table
|
||||||
let v = serde_json::from_str::<Value>(body.as_str());
|
let v = serde_json::from_str::<Value>(body.as_str());
|
||||||
|
|
||||||
// match v {
|
match v {
|
||||||
// Ok(T) => {
|
Ok(T) => {
|
||||||
// if T.get("status")
|
if T.get("status")
|
||||||
// .is_some_and(|a| a.as_str().unwrap() == "FILLED")
|
.is_some_and(|a| a.as_str().unwrap() == "FILLED")
|
||||||
// || T.get("status")
|
// || T.get("status")
|
||||||
// .is_some_and(|a| a.as_str().unwrap() == "PARTIALLY_FILLED")
|
// .is_some_and(|a| a.as_str().unwrap() == "PARTIALLY_FILLED")
|
||||||
// {
|
{
|
||||||
// if exchange_info_map.contains_key(&order.symbol)
|
// update values in [future_ordered_coin_list]
|
||||||
// && trade_fee_map.contains_key(&order.symbol)
|
let table_name = String::from("future_ordered_coin_list");
|
||||||
// {
|
let mut value_build = String::new();
|
||||||
// let quote_asset_precision = exchange_info_map
|
value_build.push_str(T.get("status").unwrap().as_str().unwrap());
|
||||||
// .get(&order.symbol)
|
|
||||||
// .unwrap()
|
|
||||||
// .quote_asset_precision;
|
|
||||||
// let trade_fee = trade_fee_map.get(&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),
|
|
||||||
// )
|
|
||||||
// .round_dp(2);
|
|
||||||
|
|
||||||
// let table_name = String::from("sell_ordered_coin_list");
|
// calculate values to be updated
|
||||||
// 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),
|
let usdt_size = rust_decimal::prelude::FromStr::from_str(
|
||||||
// (String::from("get_usdt"), get_usdt.to_string()),
|
T.get("cumQuote").unwrap().as_str().unwrap(),
|
||||||
// (
|
)
|
||||||
// String::from("get_usdt_fee_adjusted"),
|
.unwrap();
|
||||||
// get_usdt_fee_adjusted.to_string(),
|
|
||||||
// ),
|
let mut pnl = Decimal::new(0, 8);
|
||||||
// (String::from("sell_price"), sell_price.to_string()),
|
if order.position.contains("Long") {
|
||||||
// (
|
pnl = decimal_sub(usdt_size, order.used_usdt);
|
||||||
// String::from("pure_profit_percent"),
|
} else {
|
||||||
// pure_profit_percent.to_string(),
|
pnl = decimal_sub(order.used_usdt, usdt_size);
|
||||||
// ),
|
}
|
||||||
// ];
|
let expected_get_usdt = decimal_add(order.used_usdt, pnl);
|
||||||
// let update_condition = vec![(String::from("id"), order.id.to_string())];
|
|
||||||
// update_record3(&table_name, &update_values, &update_condition)
|
let update_values = vec![
|
||||||
// .await
|
(String::from("status"), value_build), // status
|
||||||
// .unwrap();
|
(String::from("pnl"), pnl.to_string()), // pnl
|
||||||
// }
|
(String::from("expected_get_usdt"), expected_get_usdt.to_string()), // base_qty_ordered
|
||||||
// }
|
];
|
||||||
// }
|
let update_condition = vec![
|
||||||
// Err(e) => {
|
(String::from("order_id"), order.order_id.to_string()),
|
||||||
// log::warn!("query sell order failed!: {}", body);
|
(String::from("symbol"), order.symbol.clone()),
|
||||||
// }
|
];
|
||||||
// }
|
update_record2(&table_name, &update_values, &update_condition)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
println!("closed {} {}", order.position, order.symbol);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::warn!("query sell order failed!: {}", body);
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user