Fix searching symbols
This commit is contained in:
parent
bc1e429377
commit
5191a284d2
|
|
@ -90,6 +90,21 @@ pub struct SellOrderedCoinList {
|
||||||
pub is_long: u8,
|
pub is_long: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, FromRow, Clone)]
|
||||||
|
pub struct SellHistoryList {
|
||||||
|
pub id: u64,
|
||||||
|
pub symbol: String,
|
||||||
|
pub soldtime: i64,
|
||||||
|
pub used_usdt: Decimal,
|
||||||
|
pub get_usdt: Decimal,
|
||||||
|
pub buy_price: Decimal,
|
||||||
|
pub sell_price: Decimal,
|
||||||
|
pub base_qty: Decimal,
|
||||||
|
pub pure_profit_percent: f64,
|
||||||
|
pub pure_profit_usdt: Decimal,
|
||||||
|
pub registerer: u16,
|
||||||
|
}
|
||||||
|
|
||||||
pub trait DBlist {
|
pub trait DBlist {
|
||||||
fn new() -> Self;
|
fn new() -> Self;
|
||||||
}
|
}
|
||||||
|
|
@ -145,6 +160,25 @@ impl DBlist for BuyOrderedCoinList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DBlist for SellHistoryList {
|
||||||
|
fn new() -> SellHistoryList {
|
||||||
|
let a = SellHistoryList {
|
||||||
|
id: 0,
|
||||||
|
symbol: String::new(),
|
||||||
|
soldtime: 0,
|
||||||
|
used_usdt: Decimal::new(0, 8),
|
||||||
|
get_usdt: Decimal::new(0, 8),
|
||||||
|
buy_price: Decimal::new(0, 8),
|
||||||
|
sell_price: Decimal::new(0, 8),
|
||||||
|
base_qty: Decimal::new(0, 8),
|
||||||
|
pure_profit_percent: 0.0,
|
||||||
|
pure_profit_usdt: Decimal::new(0, 8),
|
||||||
|
registerer: 0,
|
||||||
|
};
|
||||||
|
a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, FromRow)]
|
#[derive(Debug, FromRow)]
|
||||||
pub struct SignalDecisionInfo {
|
pub struct SignalDecisionInfo {
|
||||||
pub decision: String,
|
pub decision: String,
|
||||||
|
|
@ -489,7 +523,7 @@ pub async fn monitoring_filled_buy_order(
|
||||||
exchange_info_vec: &Vec<ExchangeInfo>,
|
exchange_info_vec: &Vec<ExchangeInfo>,
|
||||||
trade_fee_vec: &Vec<TradeFee>,
|
trade_fee_vec: &Vec<TradeFee>,
|
||||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// let index_list = select_marketcap().await;
|
let index_list = select_marketcap().await;
|
||||||
// let scoreboard_list = select_scoreboard().await;
|
// let scoreboard_list = select_scoreboard().await;
|
||||||
// let signal_decision = select_signal_decision().await;
|
// let signal_decision = select_signal_decision().await;
|
||||||
|
|
||||||
|
|
@ -604,36 +638,27 @@ pub async fn monitoring_filled_buy_order(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if server_epoch - element.close_time >= (1_800_000 * 2) * 12 // (30min * 2) * 12
|
|
||||||
{
|
|
||||||
println!(
|
|
||||||
"selling {} due to time up {:.3}",
|
|
||||||
element.symbol,
|
|
||||||
element.pure_profit_percent
|
|
||||||
);
|
|
||||||
|
|
||||||
limit_order_sell(
|
if element.is_long == 0 || element.is_long == 1 {
|
||||||
&element,
|
|
||||||
element.current_price,
|
|
||||||
base_qty_to_be_ordered,
|
|
||||||
&client,
|
|
||||||
&exchange_info_vec,
|
|
||||||
&trade_fee_vec,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
} else {
|
|
||||||
if element.pure_profit_percent >= 0.0 {
|
if element.pure_profit_percent >= 0.0 {
|
||||||
let mut is_sell = false;
|
let mut is_sell = false;
|
||||||
if element.maximum_profit_percent >= target_profit_percent(2.0) + 0.2
|
if element.maximum_profit_percent >= target_profit_percent(5.0) + 0.2
|
||||||
&& element.pure_profit_percent >= target_profit_percent(2.0) + 0.2
|
&& element.pure_profit_percent >= target_profit_percent(5.0) + 0.2
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"Selling {} 200% target_profit_percent: {:.3}",
|
"Selling {} 500% target_profit_percent: {:.3}",
|
||||||
element.symbol,
|
element.symbol,
|
||||||
element.pure_profit_percent
|
element.pure_profit_percent
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
} else if server_epoch - element.close_time >= (1_800_000 * 2) * 6 // (30min * 2) * 6
|
} else if element.pure_profit_percent >= 7.0
|
||||||
|
{
|
||||||
|
println!(
|
||||||
|
"Selling {} 7% profit_percent",
|
||||||
|
element.symbol
|
||||||
|
);
|
||||||
|
is_sell = true;
|
||||||
|
} else if server_epoch - element.close_time >= (3_600_000 * 24) && element.pure_profit_percent >= 0.2 // (1hr * 24)
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"selling {} due to time up {:.3}",
|
"selling {} due to time up {:.3}",
|
||||||
|
|
@ -641,12 +666,6 @@ pub async fn monitoring_filled_buy_order(
|
||||||
element.pure_profit_percent
|
element.pure_profit_percent
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
} else if element.pure_profit_percent >= 1.5 {
|
|
||||||
println!(
|
|
||||||
"selling {} 1.5% profit",
|
|
||||||
element.symbol
|
|
||||||
);
|
|
||||||
is_sell = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_sell == true {
|
if is_sell == true {
|
||||||
|
|
@ -664,18 +683,18 @@ pub async fn monitoring_filled_buy_order(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut is_sell = false;
|
let mut is_sell = false;
|
||||||
if element.pure_profit_percent <= target_profit_percent(-1.5) - 0.2 // -0.2 means about total trade fees.
|
if element.pure_profit_percent <= target_profit_percent(-2.5) - 0.2 // -0.2 means about total trade fees.
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"Selling {} -150% target_profit_percent: {:.3}",
|
"Selling {} -250% target_profit_percent: {:.3}",
|
||||||
element.symbol,
|
element.symbol,
|
||||||
element.pure_profit_percent
|
element.pure_profit_percent
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
} else if element.pure_profit_percent <= -1.0 && server_epoch - element.close_time >= (1_800_000 * 2) * 2 // (30min * 2) * 2
|
} else if element.pure_profit_percent <= -5.0
|
||||||
{
|
{
|
||||||
println!(
|
println!(
|
||||||
"selling {} -1.0% profit",
|
"selling {} -5.0% profit",
|
||||||
element.symbol
|
element.symbol
|
||||||
);
|
);
|
||||||
is_sell = true;
|
is_sell = true;
|
||||||
|
|
@ -694,7 +713,6 @@ pub async fn monitoring_filled_buy_order(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -743,27 +761,31 @@ async fn update_repeat_task(
|
||||||
.position(|x| *x.symbol == element.symbol);
|
.position(|x| *x.symbol == element.symbol);
|
||||||
let lot_step_size_result = exchange_info_vec
|
let lot_step_size_result = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
.position(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||||
let quote_commission_precision_result = exchange_info_vec
|
let quote_commission_precision_result = exchange_info_vec
|
||||||
.iter()
|
.iter()
|
||||||
.find(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
.position(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||||
let trade_fee = trade_fee_vec
|
let trade_fee_result = trade_fee_vec
|
||||||
.iter()
|
.iter()
|
||||||
.find(|TradeFee| TradeFee.symbol == element.symbol)
|
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
||||||
.unwrap()
|
|
||||||
.takercommission;
|
|
||||||
if price_index_option.is_some()
|
if price_index_option.is_some()
|
||||||
&& lot_step_size_result.is_some()
|
&& lot_step_size_result.is_some()
|
||||||
&& quote_commission_precision_result.is_some()
|
&& quote_commission_precision_result.is_some()
|
||||||
|
&& trade_fee_result.is_some()
|
||||||
{
|
{
|
||||||
price = rust_decimal::prelude::FromPrimitive::from_f64(
|
let price_result: Option<Decimal> = rust_decimal::prelude::FromPrimitive::from_f64(
|
||||||
coin_price_vec[price_index_option.unwrap()].current_price,
|
coin_price_vec[price_index_option.unwrap()].current_price,
|
||||||
)
|
);
|
||||||
.unwrap();
|
|
||||||
|
if price_result.is_some() {
|
||||||
|
price = price_result.unwrap();
|
||||||
|
if !price.is_zero() {
|
||||||
// to get quote_commission_precision
|
// to get quote_commission_precision
|
||||||
let lot_step_size = lot_step_size_result.unwrap().stepsize;
|
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
||||||
let quote_commission_precision = quote_commission_precision_result
|
let lot_step_size = exchange_info_vec[lot_step_size_result.unwrap()].stepsize;
|
||||||
.unwrap()
|
let quote_commission_precision = exchange_info_vec[quote_commission_precision_result
|
||||||
|
.unwrap()]
|
||||||
.quote_commission_precision;
|
.quote_commission_precision;
|
||||||
let base_qty_to_be_ordered = element.base_qty_fee_adjusted.round_dp_with_strategy(
|
let base_qty_to_be_ordered = element.base_qty_fee_adjusted.round_dp_with_strategy(
|
||||||
lot_step_size.normalize().scale(),
|
lot_step_size.normalize().scale(),
|
||||||
|
|
@ -812,6 +834,9 @@ async fn update_repeat_task(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
update_records(&update_table_name, &update_record, &update_colums).await;
|
update_records(&update_table_name, &update_record, &update_colums).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user