Name refactor
This commit is contained in:
+2
-2
@@ -27,5 +27,5 @@ name = "pulse-trader"
|
|||||||
path = "src/terminal/main.rs"
|
path = "src/terminal/main.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "pulse-trader-daemon"
|
name = "pulse-trader-engine"
|
||||||
path = "src/daemon/main.rs"
|
path = "src/engine/main.rs"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use quote::quote;
|
|||||||
use syn::{Fields, ItemEnum, ItemStruct, parse_macro_input};
|
use syn::{Fields, ItemEnum, ItemStruct, parse_macro_input};
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn p_com(_: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn pwp(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let input = parse_macro_input!(item as syn::Item);
|
let input = parse_macro_input!(item as syn::Item);
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
@@ -49,7 +49,7 @@ fn expand_struct(mut input: ItemStruct) -> TokenStream {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#input
|
#input
|
||||||
|
|
||||||
impl PulseCom for #name {
|
impl PulseWire for #name {
|
||||||
fn to_com(&self) -> Vec<u8> {
|
fn to_com(&self) -> Vec<u8> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ fn expand_struct(mut input: ItemStruct) -> TokenStream {
|
|||||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
#(
|
#(
|
||||||
#field_names2: PulseCom::from_com(com),
|
#field_names2: PulseWire::from_com(com),
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ fn expand_enum(input: ItemEnum) -> TokenStream {
|
|||||||
|
|
||||||
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => {
|
Fields::Unnamed(fields) if fields.unnamed.len() == 1 => {
|
||||||
quote! {
|
quote! {
|
||||||
#tag => Self::#ident(PulseCom::from_com(com)),
|
#tag => Self::#ident(PulseWire::from_com(com)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ fn expand_enum(input: ItemEnum) -> TokenStream {
|
|||||||
quote! {
|
quote! {
|
||||||
#tag => Self::#ident {
|
#tag => Self::#ident {
|
||||||
#(
|
#(
|
||||||
#names: PulseCom::from_com(com),
|
#names: PulseWire::from_com(com),
|
||||||
)*
|
)*
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ fn expand_enum(input: ItemEnum) -> TokenStream {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#input
|
#input
|
||||||
|
|
||||||
impl PulseCom for #name {
|
impl PulseWire for #name {
|
||||||
fn to_com(&self) -> Vec<u8> {
|
fn to_com(&self) -> Vec<u8> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
|
|
||||||
pub trait PulseCom {
|
pub trait PulseWire {
|
||||||
fn to_com(&self) -> Vec<u8>;
|
fn to_com(&self) -> Vec<u8>;
|
||||||
fn from_com(_com: &mut Vec<u8>) -> Self;
|
fn from_com(_com: &mut Vec<u8>) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: PulseCom> PulseCom for Vec<T> {
|
impl<T: PulseWire> PulseWire for Vec<T> {
|
||||||
fn to_com(&self) -> Vec<u8> {
|
fn to_com(&self) -> Vec<u8> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ impl<T: PulseCom> PulseCom for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PulseCom for String {
|
impl PulseWire for String {
|
||||||
fn to_com(&self) -> Vec<u8> {
|
fn to_com(&self) -> Vec<u8> {
|
||||||
let bytes = self.as_bytes();
|
let bytes = self.as_bytes();
|
||||||
let mut out = Vec::with_capacity(4 + bytes.len());
|
let mut out = Vec::with_capacity(4 + bytes.len());
|
||||||
@@ -55,7 +55,7 @@ impl PulseCom for String {
|
|||||||
|
|
||||||
macro_rules! int_com {
|
macro_rules! int_com {
|
||||||
($t:ty) => {
|
($t:ty) => {
|
||||||
impl PulseCom for $t {
|
impl $crate::PulseWire for $t {
|
||||||
fn to_com(&self) -> Vec<u8> {
|
fn to_com(&self) -> Vec<u8> {
|
||||||
self.to_le_bytes().to_vec()
|
self.to_le_bytes().to_vec()
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -1,35 +1,35 @@
|
|||||||
use crate::PulseCom;
|
use crate::PulseWire;
|
||||||
use pulse_macros::p_com;
|
use pulse_macros::pwp;
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct WatchListItem {
|
pub struct WatchListItem {
|
||||||
symbol: String,
|
symbol: String,
|
||||||
price: f64,
|
price: f64,
|
||||||
trend: f64,
|
trend: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct ActivePosition {
|
pub struct ActivePosition {
|
||||||
symbol: String,
|
symbol: String,
|
||||||
profit: f64,
|
profit: f64,
|
||||||
amount: f64,
|
amount: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum MarketTrend {
|
pub enum MarketTrend {
|
||||||
Bullish,
|
Bullish,
|
||||||
Bearish,
|
Bearish,
|
||||||
Neutral,
|
Neutral,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum Volatility {
|
pub enum Volatility {
|
||||||
Low,
|
Low,
|
||||||
Medium,
|
Medium,
|
||||||
High,
|
High,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct MarketOverview {
|
pub struct MarketOverview {
|
||||||
trend: MarketTrend,
|
trend: MarketTrend,
|
||||||
volatility: Volatility,
|
volatility: Volatility,
|
||||||
@@ -38,7 +38,7 @@ pub struct MarketOverview {
|
|||||||
alerts: Vec<Alert>,
|
alerts: Vec<Alert>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum Feed {
|
pub enum Feed {
|
||||||
Connected,
|
Connected,
|
||||||
Disconnected,
|
Disconnected,
|
||||||
@@ -46,7 +46,7 @@ pub enum Feed {
|
|||||||
Failed,
|
Failed,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct Status {
|
pub struct Status {
|
||||||
feed: Feed,
|
feed: Feed,
|
||||||
exchange: String,
|
exchange: String,
|
||||||
@@ -54,13 +54,13 @@ pub struct Status {
|
|||||||
latency: u16,
|
latency: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum SignalKind {
|
pub enum SignalKind {
|
||||||
Buy,
|
Buy,
|
||||||
Sell,
|
Sell,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum SignalParameter {
|
pub enum SignalParameter {
|
||||||
Lim,
|
Lim,
|
||||||
Stl,
|
Stl,
|
||||||
@@ -68,7 +68,7 @@ pub enum SignalParameter {
|
|||||||
Chk,
|
Chk,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct Signal {
|
pub struct Signal {
|
||||||
kind: SignalKind,
|
kind: SignalKind,
|
||||||
symbol: String,
|
symbol: String,
|
||||||
@@ -76,7 +76,7 @@ pub struct Signal {
|
|||||||
price: f64,
|
price: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum LogKind {
|
pub enum LogKind {
|
||||||
Info,
|
Info,
|
||||||
Warn,
|
Warn,
|
||||||
@@ -84,27 +84,27 @@ pub enum LogKind {
|
|||||||
Debug,
|
Debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct EventLog {
|
pub struct EventLog {
|
||||||
kind: LogKind,
|
kind: LogKind,
|
||||||
name: String,
|
name: String,
|
||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum AlertLevel {
|
pub enum AlertLevel {
|
||||||
High,
|
High,
|
||||||
Medium,
|
Medium,
|
||||||
Low,
|
Low,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub struct Alert {
|
pub struct Alert {
|
||||||
level: AlertLevel,
|
level: AlertLevel,
|
||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[p_com]
|
#[pwp]
|
||||||
pub enum InspectTarget {
|
pub enum InspectTarget {
|
||||||
None,
|
None,
|
||||||
Symbol(WatchListItem),
|
Symbol(WatchListItem),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use pulse_wire::PulseCom;
|
use pulse_wire::PulseWire;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input = pulse_wire::terminal::EventLog {
|
let input = pulse_wire::terminal::EventLog {
|
||||||
Reference in New Issue
Block a user