Change variable type
This commit is contained in:
parent
d2efd67c4f
commit
30bc530f21
|
|
@ -13,9 +13,7 @@ use crate::future::table_mgmt::select_listuped_positions;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, sqlx::Type)]
|
#[derive(Debug, PartialEq, Clone, sqlx::Type)]
|
||||||
pub enum Position {
|
pub enum Position {
|
||||||
#[sqlx(rename = "long")]
|
|
||||||
Long,
|
Long,
|
||||||
#[sqlx(rename = "short")]
|
|
||||||
Short
|
Short
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +122,7 @@ pub struct PositionCoinList {
|
||||||
pub status: String,
|
pub status: String,
|
||||||
pub symbol: String,
|
pub symbol: String,
|
||||||
pub order_id: u64,
|
pub order_id: u64,
|
||||||
pub position: Position,
|
pub position: String,
|
||||||
pub registered_server_epoch: i64,
|
pub registered_server_epoch: i64,
|
||||||
pub transact_time: i64,
|
pub transact_time: i64,
|
||||||
pub close_time: i64,
|
pub close_time: i64,
|
||||||
|
|
@ -148,7 +146,7 @@ impl PositionCoinList {
|
||||||
status: String::new(),
|
status: String::new(),
|
||||||
symbol: String::new(),
|
symbol: String::new(),
|
||||||
order_id: 0,
|
order_id: 0,
|
||||||
position: Position::Short,
|
position: String::new(),
|
||||||
registered_server_epoch: 0,
|
registered_server_epoch: 0,
|
||||||
transact_time: 0,
|
transact_time: 0,
|
||||||
close_time: 0,
|
close_time: 0,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use serde_json::Value;
|
||||||
use sqlx::FromRow;
|
use sqlx::FromRow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use tokio::time::*;
|
use tokio::time::*;
|
||||||
use super::{hmac_signature, REAL, SIMUL, TEST, RUNNING_MODE, FUTURES_URL, FUTURES_URL_TEST, API_KEY, API_KEY_TESTNET, Position, FuturesExchangeInfo, PositionCoinList, FuturesTradeFee, EntryCoinInfo, select_listuped_positions};
|
use super::{hmac_signature, REAL, SIMUL, TEST, RUNNING_MODE, FUTURES_URL, FUTURES_URL_TEST, API_KEY, API_KEY_TESTNET, FuturesExchangeInfo, PositionCoinList, FuturesTradeFee, EntryCoinInfo, select_listuped_positions};
|
||||||
use crate::strategy_team::future_strategy;
|
use crate::strategy_team::future_strategy;
|
||||||
|
|
||||||
pub enum TimeInForce {
|
pub enum TimeInForce {
|
||||||
|
|
@ -108,7 +108,6 @@ pub async fn entry_position(
|
||||||
|
|
||||||
// order the symbol based on base_qty_ordered and current_price
|
// order the symbol based on base_qty_ordered and current_price
|
||||||
limit_order_entry(
|
limit_order_entry(
|
||||||
&element.position,
|
|
||||||
&element,
|
&element,
|
||||||
futures_exchange_info_map,
|
futures_exchange_info_map,
|
||||||
trade_fee,
|
trade_fee,
|
||||||
|
|
@ -130,7 +129,6 @@ pub async fn entry_position(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn limit_order_entry(
|
pub async fn limit_order_entry(
|
||||||
position: &Position,
|
|
||||||
entry_coin_info: &PositionCoinList,
|
entry_coin_info: &PositionCoinList,
|
||||||
exchange_info_map: &HashMap<String, FuturesExchangeInfo>,
|
exchange_info_map: &HashMap<String, FuturesExchangeInfo>,
|
||||||
trade_fee: Decimal,
|
trade_fee: Decimal,
|
||||||
|
|
@ -157,11 +155,7 @@ pub async fn limit_order_entry(
|
||||||
(String::from("base_qty_fee_adjusted"), simul_base_qty_fee_adjusted.to_string())
|
(String::from("base_qty_fee_adjusted"), simul_base_qty_fee_adjusted.to_string())
|
||||||
];
|
];
|
||||||
|
|
||||||
if *position == Position::Long {
|
update_values.push((String::from("position"), entry_coin_info.position.clone()));
|
||||||
update_values.push((String::from("position"), String::from("Long")));
|
|
||||||
} else if *position == Position::Short {
|
|
||||||
update_values.push((String::from("position"), String::from("Short")));
|
|
||||||
}
|
|
||||||
|
|
||||||
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_record3(&update_table_name, &update_values, &update_condition)
|
update_record3(&update_table_name, &update_values, &update_condition)
|
||||||
|
|
@ -170,7 +164,7 @@ pub async fn limit_order_entry(
|
||||||
|
|
||||||
sub_future_available_usdt(used_usdt).await;
|
sub_future_available_usdt(used_usdt).await;
|
||||||
|
|
||||||
println!("SIMUL {} {}", position.to_string(), entry_coin_info.symbol);
|
println!("SIMUL {} {}", entry_coin_info.position, entry_coin_info.symbol);
|
||||||
} else {
|
} else {
|
||||||
// building URL and API-keys
|
// building URL and API-keys
|
||||||
let mut url = String::new();
|
let mut url = String::new();
|
||||||
|
|
@ -191,7 +185,7 @@ pub async fn limit_order_entry(
|
||||||
// add parameters into URL
|
// add parameters into URL
|
||||||
url_build.push_str("&symbol=");
|
url_build.push_str("&symbol=");
|
||||||
url_build.push_str(&entry_coin_info.symbol);
|
url_build.push_str(&entry_coin_info.symbol);
|
||||||
if *position == Position::Long {
|
if entry_coin_info.position.contains("Long") {
|
||||||
url_build.push_str("&side=BUY");
|
url_build.push_str("&side=BUY");
|
||||||
} else {
|
} else {
|
||||||
url_build.push_str("&side=SELL");
|
url_build.push_str("&side=SELL");
|
||||||
|
|
@ -243,10 +237,10 @@ pub async fn limit_order_entry(
|
||||||
update_values.push((String::from("status"), String::from("NEW")));
|
update_values.push((String::from("status"), String::from("NEW")));
|
||||||
} else if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
} else if T.get("status").unwrap().as_str().unwrap() == "FILLED" {
|
||||||
update_values.push((String::from("status"), String::from("FILLED")));
|
update_values.push((String::from("status"), String::from("FILLED")));
|
||||||
println!("{} {}", position.to_string(), entry_coin_info.symbol);
|
println!("{} {}", entry_coin_info.position, entry_coin_info.symbol);
|
||||||
} else if T.get("status").unwrap().as_str().unwrap() == "PARTIALLY_FILLED" {
|
} else if T.get("status").unwrap().as_str().unwrap() == "PARTIALLY_FILLED" {
|
||||||
update_values.push((String::from("status"), String::from("PARTIALLY_FILLED")));
|
update_values.push((String::from("status"), String::from("PARTIALLY_FILLED")));
|
||||||
println!("Partially filled {} {}", position.to_string(), entry_coin_info.symbol);
|
println!("Partially filled {} {}", entry_coin_info.position, entry_coin_info.symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
let base_qty_ordered = rust_decimal::prelude::FromStr::from_str(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{hmac_signature, REAL, SIMUL, TEST, RUNNING_MODE, FUTURES_URL, FUTURES_URL_TEST, API_KEY, API_KEY_TESTNET, Position, FuturesExchangeInfo, PositionCoinList, FuturesTradeFee};
|
use super::{hmac_signature, REAL, SIMUL, TEST, RUNNING_MODE, FUTURES_URL, FUTURES_URL_TEST, API_KEY, API_KEY_TESTNET, FuturesExchangeInfo, PositionCoinList, FuturesTradeFee};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use rust_decimal::{Decimal, RoundingStrategy};
|
use rust_decimal::{Decimal, RoundingStrategy};
|
||||||
use crate::database_control::*;
|
use crate::database_control::*;
|
||||||
|
|
@ -213,7 +213,7 @@ async fn update_repeat_task(
|
||||||
// RoundingStrategy::ToZero,
|
// RoundingStrategy::ToZero,
|
||||||
// );
|
// );
|
||||||
let mut pure_profit_percent;
|
let mut pure_profit_percent;
|
||||||
if element.position == Position::Long {
|
if element.position.contains("Long") {
|
||||||
pure_profit_percent = ((expected_get_usdt.to_f64().unwrap()
|
pure_profit_percent = ((expected_get_usdt.to_f64().unwrap()
|
||||||
/ element.used_usdt.to_f64().unwrap())
|
/ element.used_usdt.to_f64().unwrap())
|
||||||
- 1.0)
|
- 1.0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user