Add stoploss

This commit is contained in:
Sik Yoon 2023-11-19 23:29:29 +09:00
parent efd0bd5b10
commit 420173a361
3 changed files with 29 additions and 1 deletions

View File

@ -22,6 +22,7 @@ struct PreSuggestedCoin {
close_time: i64,
suggested_price: Decimal,
current_price: Decimal,
stoploss: Decimal,
target_price: Decimal,
registered_server_epoch: i64,
profit_percent: f64,
@ -39,6 +40,7 @@ impl DBlist for PreSuggestedCoin {
close_time: 0,
suggested_price: Decimal::new(0, 8),
current_price: Decimal::new(0, 8),
stoploss: Decimal::new(0, 8),
target_price: Decimal::new(0, 8),
registered_server_epoch: 0,
profit_percent: 0.0,
@ -56,6 +58,7 @@ pub struct SuggestedCoin {
pub id: u64,
pub symbol: String,
pub suggested_price: Decimal,
pub stoploss: Decimal,
pub target_price: Decimal,
pub close_time: i64,
pub registered_server_epoch: i64,
@ -70,6 +73,7 @@ impl DBlist for SuggestedCoin {
id: 0,
symbol: String::new(),
suggested_price: Decimal::new(0, 8),
stoploss: Decimal::new(0, 8),
target_price: Decimal::new(0, 8),
close_time: 0,
registered_server_epoch: 0,
@ -521,6 +525,7 @@ pub async fn monitoring_pre_suggested_coins(
let mut insert_columns = vec![
"symbol",
"suggested_price",
"stoploss",
"target_price",
"close_time",
"registered_server_epoch",
@ -553,6 +558,7 @@ pub async fn monitoring_pre_suggested_coins(
insert_values.clear();
insert_values.push(element.symbol.clone()); // symbol
insert_values.push(element.current_price.to_string()); // suggested_price
insert_values.push(element.stoploss.to_string()); // stoploss
insert_values.push(element.target_price.to_string()); // target_price
insert_values.push(element.close_time.to_string()); // close_time
insert_values.push(server_epoch().await.to_string()); // registered_server_epoch

View File

@ -59,6 +59,7 @@ pub struct BuyOrderedCoinList {
pub expected_usdt_profit: f64,
pub buy_price: Decimal,
pub current_price: Decimal,
pub stoploss: Decimal,
pub target_price: Decimal,
pub base_qty_ordered: Decimal,
pub base_qty_fee_adjusted: Decimal,
@ -83,6 +84,7 @@ pub struct SellOrderedCoinList {
pub get_usdt_fee_adjusted: Decimal,
pub buy_price: Decimal,
pub sell_price: Decimal,
pub stoploss: Decimal,
pub target_price: Decimal,
pub base_qty_ordered: Decimal,
pub pure_profit_percent: Decimal,
@ -125,6 +127,7 @@ impl DBlist for SellOrderedCoinList {
get_usdt_fee_adjusted: Decimal::new(0, 8),
buy_price: Decimal::new(0, 8),
sell_price: Decimal::new(0, 8),
stoploss: Decimal::new(0, 8),
target_price: Decimal::new(0, 8),
base_qty_ordered: Decimal::new(0, 8),
pure_profit_percent: Decimal::new(0, 8),
@ -150,6 +153,7 @@ impl DBlist for BuyOrderedCoinList {
expected_usdt_profit: 0.0,
buy_price: Decimal::new(0, 8),
current_price: Decimal::new(0, 8),
stoploss: Decimal::new(0, 8),
target_price: Decimal::new(0, 8),
base_qty_ordered: Decimal::new(0, 8),
base_qty_fee_adjusted: Decimal::new(0, 8),
@ -315,6 +319,7 @@ pub async fn limit_order_buy(
"expected_usdt_profit",
"buy_price",
"current_price",
"stoploss",
"target_price",
"base_qty_ordered",
"base_qty_fee_adjusted",
@ -338,6 +343,7 @@ pub async fn limit_order_buy(
insert_value_container.push(0.0.to_string()); // expected_usdt_profit
insert_value_container.push(order_price.to_string()); // buy_price
insert_value_container.push(0.0.to_string()); // current_price
insert_value_container.push(element.stoploss.to_string()); // stoploss
insert_value_container.push(element.target_price.to_string()); // target_price
insert_value_container.push(order_quantity.to_string()); // base_qty_ordered
insert_value_container.push(simul_base_qty_fee_adjusted.to_string()); // base_qty_fee_adjusted
@ -446,6 +452,7 @@ pub async fn limit_order_buy(
insert_value_container.push(0.0.to_string()); // expected_usdt_profit
insert_value_container.push(buy_price.to_string()); // buy_price
insert_value_container.push(0.0.to_string()); // current_price
insert_value_container.push(element.stoploss.to_string()); // stoploss
insert_value_container.push(element.target_price.to_string()); // target_price
insert_value_container.push(base_qty_ordered.to_string()); // base_qty_ordered
insert_value_container.push(base_qty_fee_adjusted.to_string()); // base_qty_fee_adjusted
@ -460,6 +467,7 @@ pub async fn limit_order_buy(
insert_value_container.push(0.0.to_string()); // expected_usdt_profit
insert_value_container.push(0.0.to_string()); // buy_price
insert_value_container.push(0.0.to_string()); // current_price
insert_value_container.push(element.stoploss.to_string()); // stoploss
insert_value_container.push(element.target_price.to_string()); // target_price
insert_value_container
.push(T.get("origQty").unwrap().as_str().unwrap().to_string()); // base_qty_ordered
@ -698,6 +706,8 @@ pub async fn limit_order_sell(
"get_usdt_fee_adjusted",
"buy_price",
"sell_price",
"stoploss",
"target_price",
"base_qty_ordered",
"pure_profit_percent",
"maximum_profit_percent",
@ -736,6 +746,8 @@ pub async fn limit_order_sell(
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(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.target_price.to_string()); // target_price
insert_value_container.push(sell_base_quantity.to_string()); // base_qty_ordered
let pure_profit_percent = decimal_mul(
@ -868,6 +880,8 @@ pub async fn limit_order_sell(
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" {
@ -1300,6 +1314,7 @@ pub async fn cancel_sell_order(
"expected_usdt_profit",
"buy_price",
"current_price",
"stoploss",
"target_price",
"base_qty_ordered",
"base_qty_fee_adjusted",
@ -1343,6 +1358,7 @@ pub async fn cancel_sell_order(
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(0.0.to_string()); // current_price
insert_value_container.push(order.stoploss.to_string()); // stoploss
insert_value_container.push(order.target_price.to_string()); // current_price
insert_value_container.push(order.base_qty_ordered.to_string()); // base_qty_ordered
insert_value_container.push(order.base_qty_ordered.to_string()); // base_qty_fee_adjusted
@ -1498,6 +1514,7 @@ pub async fn cancel_sell_order(
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(0.0.to_string()); // current_price
insert_value_container.push(order.stoploss.to_string()); // stoploss
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_fee_adjusted.to_string()); // base_qty_fee_adjusted

View File

@ -722,6 +722,7 @@ async fn initialize_database() {
("id", "integer", Some("PK, AI, UN")),
("symbol", "char(20)", None),
("suggested_price", "decimal(16,8)", None),
("stoploss", "decimal(16,8)", None),
("target_price", "decimal(16,8)", None),
("close_time", "bigint", None),
("registered_server_epoch", "bigint", None),
@ -960,7 +961,7 @@ async fn initialize_database() {
// }
println!("Ok");
}
{
// asset_manage_announcement
print!("table 'asset_manage_announcement'...");
@ -1135,6 +1136,7 @@ async fn initialize_database() {
("close_time", "bigint", None),
("suggested_price", "decimal(16,8)", None),
("current_price", "decimal(16,8)", None),
("stoploss", "decimal(16,8)", None),
("target_price", "decimal(16,8)", None),
("registered_server_epoch", "bigint", None),
("profit_percent", "double", None),
@ -1184,6 +1186,7 @@ async fn initialize_database() {
("expected_usdt_profit", "double", None),
("buy_price", "decimal(16,8)", None),
("current_price", "decimal(16,8)", None),
("stoploss", "decimal(16,8)", None),
("target_price", "decimal(16,8)", None),
("base_qty_ordered", "decimal(16,8)", None),
("base_qty_fee_adjusted", "decimal(16,8)", None),
@ -1266,6 +1269,7 @@ async fn initialize_database() {
("get_usdt_fee_adjusted", "decimal(16,8)", None),
("buy_price", "decimal(16,8)", None),
("sell_price", "decimal(16,8)", None),
("stoploss", "decimal(16,8)", None),
("target_price", "decimal(16,8)", None),
("base_qty_ordered", "decimal(16,8)", None),
("pure_profit_percent", "decimal(16,8)", None),
@ -1306,6 +1310,7 @@ async fn initialize_database() {
get_usdt_fee_adjusted: Decimal::new(0, 8),
buy_price: Decimal::new(0, 8),
sell_price: Decimal::new(0, 8),
stoploss: Decimal::new(0, 8),
target_price: Decimal::new(0, 8),
base_qty_ordered: Decimal::new(0, 8),
pure_profit_percent: Decimal::new(0, 8),