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"
|
||||
dependencies = [
|
||||
"pulse-macros",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -5,3 +5,4 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
pulse-macros = { workspace = true }
|
||||
serde = { version = "1.0.229", features = ["serde_derive"] }
|
||||
|
||||
@@ -2,7 +2,7 @@ use pulse_macros::pwp;
|
||||
|
||||
use crate::{
|
||||
PulseWire,
|
||||
units::{Symbol, USD},
|
||||
units::{Direction, Symbol, USD},
|
||||
};
|
||||
|
||||
#[pwp]
|
||||
@@ -20,9 +20,11 @@ pub enum Volatility {
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum Direction {
|
||||
Buy,
|
||||
Sell,
|
||||
pub enum LogKind {
|
||||
Info,
|
||||
Warn,
|
||||
Err,
|
||||
Debug,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
@@ -36,14 +38,6 @@ pub struct Signal {
|
||||
pub stop_loss: USD,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub enum LogKind {
|
||||
Info,
|
||||
Warn,
|
||||
Err,
|
||||
Debug,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct EventLog {
|
||||
pub kind: LogKind,
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod general;
|
||||
pub mod strategy;
|
||||
pub mod terminal;
|
||||
pub mod units;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::PulseWire;
|
||||
pub use crate::general::*;
|
||||
pub use crate::server_path;
|
||||
pub use crate::strategy::*;
|
||||
pub use crate::terminal::*;
|
||||
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::{
|
||||
PulseWire,
|
||||
general::{EventLog, MarketTrend, Position, Signal, Volatility},
|
||||
strategy::{Risk, Strategy},
|
||||
units::{Symbol, USD},
|
||||
};
|
||||
use pulse_macros::pwp;
|
||||
@@ -100,6 +101,12 @@ pub enum Feed {
|
||||
Failed,
|
||||
}
|
||||
|
||||
#[pwp]
|
||||
pub struct StrategyView {
|
||||
strategy: Strategy,
|
||||
risk: Risk,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AlertLevel {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use pulse_macros::pwp;
|
||||
|
||||
use crate::PulseWire;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -6,6 +8,34 @@ pub struct Symbol(pub String);
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
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 {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
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::{
|
||||
store::{accounts::AccountList, config::Config},
|
||||
terminal::TerminalServer,
|
||||
};
|
||||
use pulse_wire::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use tokio::{sync::Mutex, task::JoinHandle};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Engine {
|
||||
|
||||
+2
-6
@@ -1,10 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use pulse_wire::{
|
||||
terminal::MarketItem,
|
||||
units::{Symbol, USD},
|
||||
};
|
||||
use pulse_wire::prelude::*;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn number(value: &Value, field: &str) -> Result<f64, String> {
|
||||
let raw = value[field]
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::engine::Engine;
|
||||
use pulse_wire::prelude::*;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Weak},
|
||||
};
|
||||
|
||||
use pulse_wire::{PulseWire, general::{EventLog, LogKind}, terminal::TerminalClientMessage};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::{
|
||||
@@ -13,8 +13,6 @@ use tokio::{
|
||||
sync::Mutex,
|
||||
};
|
||||
|
||||
use crate::engine::Engine;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TerminalServer {
|
||||
clients: Mutex<HashMap<usize, OwnedWriteHalf>>,
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
use pulse_wire::terminal::{
|
||||
Alert, AlertLevel, InspectItem, InspectTarget, MarketItem, MarketOverview, Status,
|
||||
};
|
||||
|
||||
use pulse_wire::general::{Direction, EventLog, LogKind, Position, Signal};
|
||||
use pulse_wire::units::format_f64;
|
||||
use pulse_wire::prelude::*;
|
||||
|
||||
pub trait Formatted {
|
||||
fn get_formatted(&self) -> Vec<String>;
|
||||
|
||||
@@ -21,10 +21,7 @@ use pulse_ui::{
|
||||
|
||||
use crate::formatting::{Formatted, apply_padding};
|
||||
|
||||
use pulse_wire::{
|
||||
general::{EventLog, Position, Signal},
|
||||
terminal::{InspectTarget, MarketItem, MarketOverview, Status},
|
||||
};
|
||||
use pulse_wire::prelude::*;
|
||||
|
||||
pub struct PulseTradeApp {
|
||||
sock: Option<terminal::TerminalClient>,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use pulse_wire::{PulseWire, server_path, terminal::TerminalServerMessage};
|
||||
use pulse_wire::prelude::*;
|
||||
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::{
|
||||
|
||||
Reference in New Issue
Block a user