Fix searching symbols
This commit is contained in:
parent
7e45793d54
commit
abd03aaeab
|
|
@ -27,6 +27,7 @@ struct PreSuggestedCoin {
|
|||
minimum_profit_percent: f64,
|
||||
maximum_profit_percent: f64,
|
||||
registerer: u16,
|
||||
is_long: u8,
|
||||
}
|
||||
|
||||
impl DBlist for PreSuggestedCoin {
|
||||
|
|
@ -42,6 +43,7 @@ impl DBlist for PreSuggestedCoin {
|
|||
minimum_profit_percent: 0.0,
|
||||
maximum_profit_percent: 0.0,
|
||||
registerer: 0,
|
||||
is_long: 0,
|
||||
};
|
||||
a
|
||||
}
|
||||
|
|
@ -214,14 +216,6 @@ pub async fn buy_coin(
|
|||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut suggested_coin = get_suggested_coin_list().await;
|
||||
|
||||
if exchange_info_vec.len() == 0 {
|
||||
println!("exchange_info_vec length is zero in buy coin");
|
||||
}
|
||||
|
||||
if trade_fee_vec.len() == 0 {
|
||||
println!("trade_fee_vec length is zero in buy coin");
|
||||
}
|
||||
|
||||
if !suggested_coin.is_empty() && exchange_info_vec.len() != 0 && trade_fee_vec.len() != 0 {
|
||||
let server_epoch = server_epoch().await;
|
||||
let mut filtered_suggested_coin_vec: Vec<&SuggestedCoin> = Vec::new();
|
||||
|
|
@ -231,8 +225,8 @@ pub async fn buy_coin(
|
|||
// filtering symbols to buy
|
||||
for element in &suggested_coin {
|
||||
if element.already_buy == 0
|
||||
&& server_epoch - element.registered_server_epoch <= 600_000
|
||||
// 600_000 (600 secs = 10 mins)
|
||||
&& server_epoch - element.registered_server_epoch <= 300_000
|
||||
// 300_000 (300 secs = 5 mins)
|
||||
{
|
||||
filtered_suggested_coin_vec.push(element);
|
||||
} else if server_epoch - element.registered_server_epoch >= 5_400_000 { // 30mins * 3
|
||||
|
|
@ -242,7 +236,6 @@ pub async fn buy_coin(
|
|||
is_exist_delete_symbol = true;
|
||||
}
|
||||
}
|
||||
|
||||
set_is_tradable().await;
|
||||
let mut is_tradable = get_is_tradable().await;
|
||||
|
||||
|
|
@ -254,30 +247,23 @@ pub async fn buy_coin(
|
|||
.unwrap();
|
||||
for element in &filtered_suggested_coin_vec {
|
||||
if is_tradable == true {
|
||||
let lot_step_size_result = exchange_info_vec
|
||||
let exchange_info_result = exchange_info_vec
|
||||
.iter()
|
||||
.find(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||
let tick_size_result = exchange_info_vec
|
||||
.iter()
|
||||
.find(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||
let base_commission_precision_result = exchange_info_vec
|
||||
.iter()
|
||||
.find(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||
.position(|ExchangeInfo| ExchangeInfo.symbol == element.symbol);
|
||||
|
||||
let trade_fee_result = trade_fee_vec
|
||||
.iter()
|
||||
.find(|TradeFee| TradeFee.symbol == element.symbol);
|
||||
.position(|TradeFee| TradeFee.symbol == element.symbol);
|
||||
|
||||
if lot_step_size_result.is_some()
|
||||
&& tick_size_result.is_some()
|
||||
&& base_commission_precision_result.is_some()
|
||||
if exchange_info_result.is_some()
|
||||
&& trade_fee_result.is_some()
|
||||
{
|
||||
let lot_step_size = lot_step_size_result.unwrap().stepsize;
|
||||
let tick_size = tick_size_result.unwrap().ticksize;
|
||||
let base_commission_precision = base_commission_precision_result
|
||||
.unwrap()
|
||||
let lot_step_size = exchange_info_vec[exchange_info_result.unwrap()].stepsize;
|
||||
let tick_size = exchange_info_vec[exchange_info_result.unwrap()].ticksize;
|
||||
let base_commission_precision = exchange_info_vec[exchange_info_result
|
||||
.unwrap()]
|
||||
.base_commission_precision;
|
||||
let trade_fee = trade_fee_result.unwrap().takercommission;
|
||||
let trade_fee = trade_fee_vec[trade_fee_result.unwrap()].takercommission;
|
||||
|
||||
// buy the suggested coin and transfer it into [buy_ordered_coin_list]
|
||||
let mut base_qty_ordered = Decimal::new(0, 8);
|
||||
|
|
@ -301,7 +287,7 @@ pub async fn buy_coin(
|
|||
tick_size.normalize().scale(),
|
||||
RoundingStrategy::ToZero,
|
||||
);
|
||||
let expected_pure_profit_percen: f64 = decimal_sub(
|
||||
let expected_pure_profit_percent: f64 = decimal_sub(
|
||||
decimal_div(
|
||||
decimal_mul(base_qty_fee_adjusted, element.suggested_price)
|
||||
.round_dp_with_strategy(
|
||||
|
|
@ -344,7 +330,6 @@ pub async fn buy_coin(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete the coin record in [suggested_coin_list]
|
||||
if is_exist_delete_symbol == true {
|
||||
delete_condition.pop();
|
||||
|
|
@ -353,11 +338,10 @@ pub async fn buy_coin(
|
|||
delete_condition.pop();
|
||||
delete_condition.push(';');
|
||||
let suggested_coin_list_table_name = String::from("suggested_coin_list");
|
||||
println!("delete suggested coin list");
|
||||
delete_record(&suggested_coin_list_table_name, &delete_condition)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("deletion done");
|
||||
println!("Delete suggested coin list");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -568,7 +552,7 @@ pub async fn monitoring_pre_suggested_coins(
|
|||
insert_values.push(element.close_time.to_string()); // close_time
|
||||
insert_values.push(server_epoch().await.to_string()); // registered_server_epoch
|
||||
insert_values.push(element.registerer.to_string()); // registerer
|
||||
insert_values.push(0.to_string()); // is_long
|
||||
insert_values.push(element.is_long.to_string()); // is_long
|
||||
insert_values.push(0.to_string()); // already_buy
|
||||
|
||||
insert_one_record(&insert_table_name, &insert_columns, &insert_values).await;
|
||||
|
|
@ -946,7 +930,8 @@ async fn get_suggested_coin_list() -> Vec<SuggestedCoin> {
|
|||
let condition = None;
|
||||
let mut suggested_coin = SuggestedCoin::new();
|
||||
|
||||
let select_result = try_select_record(&table_name, &columns, &condition, &suggested_coin)
|
||||
// let select_result = try_select_record(&table_name, &columns, &condition, &suggested_coin)
|
||||
let select_result = select_record(&table_name, &columns, &condition, &suggested_coin)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user