Refactor, and added strategy with risk
This commit is contained in:
Generated
+1
@@ -3907,6 +3907,7 @@ name = "pulse-wire"
|
|||||||
version = "0.1.0-alpha.0"
|
version = "0.1.0-alpha.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pulse-macros",
|
"pulse-macros",
|
||||||
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ edition = "2024"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pulse-macros = { workspace = true }
|
pulse-macros = { workspace = true }
|
||||||
|
serde = { version = "1.0.229", features = ["serde_derive"] }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use pulse_macros::pwp;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
PulseWire,
|
PulseWire,
|
||||||
units::{Symbol, USD},
|
units::{Direction, Symbol, USD},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[pwp]
|
#[pwp]
|
||||||
@@ -20,9 +20,11 @@ pub enum Volatility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[pwp]
|
#[pwp]
|
||||||
pub enum Direction {
|
pub enum LogKind {
|
||||||
Buy,
|
Info,
|
||||||
Sell,
|
Warn,
|
||||||
|
Err,
|
||||||
|
Debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pwp]
|
#[pwp]
|
||||||
@@ -36,14 +38,6 @@ pub struct Signal {
|
|||||||
pub stop_loss: USD,
|
pub stop_loss: USD,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pwp]
|
|
||||||
pub enum LogKind {
|
|
||||||
Info,
|
|
||||||
Warn,
|
|
||||||
Err,
|
|
||||||
Debug,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[pwp]
|
#[pwp]
|
||||||
pub struct EventLog {
|
pub struct EventLog {
|
||||||
pub kind: LogKind,
|
pub kind: LogKind,
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub mod general;
|
pub mod general;
|
||||||
|
pub mod strategy;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
pub mod units;
|
pub mod units;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
pub use crate::PulseWire;
|
||||||
pub use crate::general::*;
|
pub use crate::general::*;
|
||||||
|
pub use crate::server_path;
|
||||||
|
pub use crate::strategy::*;
|
||||||
pub use crate::terminal::*;
|
pub use crate::terminal::*;
|
||||||
pub use crate::units::*;
|
pub use crate::units::*;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
use crate::{PulseWire, units::TimeFrame};
|
||||||
|
use pulse_macros::pwp;
|
||||||
|
|
||||||
|
#[pwp]
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Strategy {
|
||||||
|
name: String,
|
||||||
|
timeframes: Vec<TimeFrame>,
|
||||||
|
description: String,
|
||||||
|
author: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pwp]
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Risk {
|
||||||
|
name: String,
|
||||||
|
max_loss: u8,
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
PulseWire,
|
PulseWire,
|
||||||
general::{EventLog, MarketTrend, Position, Signal, Volatility},
|
general::{EventLog, MarketTrend, Position, Signal, Volatility},
|
||||||
|
strategy::{Risk, Strategy},
|
||||||
units::{Symbol, USD},
|
units::{Symbol, USD},
|
||||||
};
|
};
|
||||||
use pulse_macros::pwp;
|
use pulse_macros::pwp;
|
||||||
@@ -100,6 +101,12 @@ pub enum Feed {
|
|||||||
Failed,
|
Failed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[pwp]
|
||||||
|
pub struct StrategyView {
|
||||||
|
strategy: Strategy,
|
||||||
|
risk: Risk,
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for AlertLevel {
|
impl std::fmt::Display for AlertLevel {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use pulse_macros::pwp;
|
||||||
|
|
||||||
use crate::PulseWire;
|
use crate::PulseWire;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -6,6 +8,34 @@ pub struct Symbol(pub String);
|
|||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct USD(pub f64);
|
pub struct USD(pub f64);
|
||||||
|
|
||||||
|
#[pwp]
|
||||||
|
#[derive(Copy, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub enum TimeFrame {
|
||||||
|
M1,
|
||||||
|
M3,
|
||||||
|
M5,
|
||||||
|
M15,
|
||||||
|
M30,
|
||||||
|
|
||||||
|
H1,
|
||||||
|
H2,
|
||||||
|
H4,
|
||||||
|
H8,
|
||||||
|
H12,
|
||||||
|
|
||||||
|
D1,
|
||||||
|
D3,
|
||||||
|
|
||||||
|
W1,
|
||||||
|
Month1,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[pwp]
|
||||||
|
pub enum Direction {
|
||||||
|
Buy,
|
||||||
|
Sell,
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Symbol {
|
impl std::fmt::Display for Symbol {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "\x1b[35m{}\x1b[0m", self.0)
|
write!(f, "\x1b[35m{}\x1b[0m", self.0)
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use pulse_wire::{
|
|
||||||
general::Position,
|
|
||||||
units::{Symbol, USD},
|
|
||||||
};
|
|
||||||
use tokio::{sync::Mutex, task::JoinHandle};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
store::{accounts::AccountList, config::Config},
|
store::{accounts::AccountList, config::Config},
|
||||||
terminal::TerminalServer,
|
terminal::TerminalServer,
|
||||||
};
|
};
|
||||||
|
use pulse_wire::prelude::*;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::{sync::Mutex, task::JoinHandle};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Engine {
|
pub struct Engine {
|
||||||
|
|||||||
+2
-6
@@ -1,10 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use pulse_wire::prelude::*;
|
||||||
|
|
||||||
use pulse_wire::{
|
|
||||||
terminal::MarketItem,
|
|
||||||
units::{Symbol, USD},
|
|
||||||
};
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn number(value: &Value, field: &str) -> Result<f64, String> {
|
fn number(value: &Value, field: &str) -> Result<f64, String> {
|
||||||
let raw = value[field]
|
let raw = value[field]
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
use crate::engine::Engine;
|
||||||
|
use pulse_wire::prelude::*;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
use pulse_wire::{PulseWire, general::{EventLog, LogKind}, terminal::TerminalClientMessage};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{
|
net::{
|
||||||
@@ -13,8 +13,6 @@ use tokio::{
|
|||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::engine::Engine;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TerminalServer {
|
pub struct TerminalServer {
|
||||||
clients: Mutex<HashMap<usize, OwnedWriteHalf>>,
|
clients: Mutex<HashMap<usize, OwnedWriteHalf>>,
|
||||||
|
|||||||
@@ -1,9 +1,4 @@
|
|||||||
use pulse_wire::terminal::{
|
use pulse_wire::prelude::*;
|
||||||
Alert, AlertLevel, InspectItem, InspectTarget, MarketItem, MarketOverview, Status,
|
|
||||||
};
|
|
||||||
|
|
||||||
use pulse_wire::general::{Direction, EventLog, LogKind, Position, Signal};
|
|
||||||
use pulse_wire::units::format_f64;
|
|
||||||
|
|
||||||
pub trait Formatted {
|
pub trait Formatted {
|
||||||
fn get_formatted(&self) -> Vec<String>;
|
fn get_formatted(&self) -> Vec<String>;
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ use pulse_ui::{
|
|||||||
|
|
||||||
use crate::formatting::{Formatted, apply_padding};
|
use crate::formatting::{Formatted, apply_padding};
|
||||||
|
|
||||||
use pulse_wire::{
|
use pulse_wire::prelude::*;
|
||||||
general::{EventLog, Position, Signal},
|
|
||||||
terminal::{InspectTarget, MarketItem, MarketOverview, Status},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct PulseTradeApp {
|
pub struct PulseTradeApp {
|
||||||
sock: Option<terminal::TerminalClient>,
|
sock: Option<terminal::TerminalClient>,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use pulse_wire::{PulseWire, server_path, terminal::TerminalServerMessage};
|
use pulse_wire::prelude::*;
|
||||||
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
io::{AsyncReadExt, AsyncWriteExt},
|
io::{AsyncReadExt, AsyncWriteExt},
|
||||||
net::{
|
net::{
|
||||||
|
|||||||
Reference in New Issue
Block a user