Removed PWP bc it hurt my brain
This commit is contained in:
@@ -4,6 +4,5 @@ version = "0.1.0-alpha.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
pulse-macros = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
hypersdk = { workspace = true }
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
use pulse_macros::pwp;
|
||||
|
||||
use crate::{
|
||||
PulseWire,
|
||||
units::{Direction, Symbol, USD},
|
||||
};
|
||||
use crate::units::{Direction, Symbol, USD};
|
||||
|
||||
#[pwp]
|
||||
pub enum MarketTrend {
|
||||
|
||||
@@ -1,313 +0,0 @@
|
||||
use hypersdk::{
|
||||
Address, Decimal,
|
||||
hypercore::{Candle, CandleInterval, Subscription},
|
||||
};
|
||||
|
||||
use crate::PulseWire;
|
||||
|
||||
impl PulseWire for Subscription {
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
match u8::from_com(com) {
|
||||
0 => Self::Bbo {
|
||||
coin: PulseWire::from_com(com),
|
||||
},
|
||||
1 => Self::Trades {
|
||||
coin: PulseWire::from_com(com),
|
||||
},
|
||||
2 => Self::L2Book {
|
||||
coin: PulseWire::from_com(com),
|
||||
n_sig_figs: PulseWire::from_com(com),
|
||||
mantissa: PulseWire::from_com(com),
|
||||
fast: PulseWire::from_com(com),
|
||||
},
|
||||
3 => Self::Candle {
|
||||
coin: PulseWire::from_com(com),
|
||||
interval: PulseWire::from_com(com),
|
||||
},
|
||||
4 => Self::AllMids {
|
||||
dex: PulseWire::from_com(com),
|
||||
},
|
||||
5 => Self::OrderUpdates {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
6 => Self::UserFills {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
7 => Self::UserEvents {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
8 => Self::UserTwapSliceFills {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
9 => Self::UserTwapHistory {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
10 => Self::ActiveAssetCtx {
|
||||
coin: PulseWire::from_com(com),
|
||||
},
|
||||
11 => Self::ActiveAssetData {
|
||||
user: PulseWire::from_com(com),
|
||||
coin: PulseWire::from_com(com),
|
||||
},
|
||||
12 => Self::WebData2 {
|
||||
user: PulseWire::from_com(com),
|
||||
dex: PulseWire::from_com(com),
|
||||
},
|
||||
13 => Self::ClearinghouseState {
|
||||
user: PulseWire::from_com(com),
|
||||
dex: PulseWire::from_com(com),
|
||||
},
|
||||
14 => Self::AllDexsClearinghouseState {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
15 => Self::OpenOrders {
|
||||
user: PulseWire::from_com(com),
|
||||
dex: PulseWire::from_com(com),
|
||||
},
|
||||
16 => Self::SpotState {
|
||||
user: PulseWire::from_com(com),
|
||||
is_portfolio_margin: PulseWire::from_com(com),
|
||||
},
|
||||
17 => Self::Notification {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
18 => Self::WebData3 {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
19 => Self::TwapStates {
|
||||
user: PulseWire::from_com(com),
|
||||
dex: Option::from_com(com),
|
||||
},
|
||||
20 => Self::UserFundings {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
21 => Self::UserNonFundingLedgerUpdates {
|
||||
user: PulseWire::from_com(com),
|
||||
},
|
||||
22 => Self::AllDexsAssetCtxs,
|
||||
23 => Self::FastAssetCtxs,
|
||||
24 => Self::OutcomeMetaUpdates,
|
||||
x => panic!("Invalid Subscription discriminant: {}", x),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
let mut com = Vec::new();
|
||||
|
||||
match self {
|
||||
Self::Bbo { coin } => {
|
||||
com.push(0);
|
||||
com.extend(coin.to_com());
|
||||
}
|
||||
Self::Trades { coin } => {
|
||||
com.push(1);
|
||||
com.extend(coin.to_com());
|
||||
}
|
||||
Self::L2Book {
|
||||
coin,
|
||||
n_sig_figs,
|
||||
mantissa,
|
||||
fast,
|
||||
} => {
|
||||
com.push(2);
|
||||
com.extend(coin.to_com());
|
||||
com.extend(n_sig_figs.to_com());
|
||||
com.extend(mantissa.to_com());
|
||||
com.extend(fast.to_com());
|
||||
}
|
||||
Self::Candle { coin, interval } => {
|
||||
com.push(3);
|
||||
com.extend(coin.to_com());
|
||||
com.extend(interval.to_com());
|
||||
}
|
||||
Self::AllMids { dex } => {
|
||||
com.push(4);
|
||||
com.extend(dex.to_com());
|
||||
}
|
||||
Self::OrderUpdates { user } => {
|
||||
com.push(5);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::UserFills { user } => {
|
||||
com.push(6);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::UserEvents { user } => {
|
||||
com.push(7);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::UserTwapSliceFills { user } => {
|
||||
com.push(8);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::UserTwapHistory { user } => {
|
||||
com.push(9);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::ActiveAssetCtx { coin } => {
|
||||
com.push(10);
|
||||
com.extend(coin.to_com());
|
||||
}
|
||||
Self::ActiveAssetData { user, coin } => {
|
||||
com.push(11);
|
||||
com.extend(user.to_com());
|
||||
com.extend(coin.to_com());
|
||||
}
|
||||
Self::WebData2 { user, dex } => {
|
||||
com.push(12);
|
||||
com.extend(user.to_com());
|
||||
com.extend(dex.to_com());
|
||||
}
|
||||
Self::ClearinghouseState { user, dex } => {
|
||||
com.push(13);
|
||||
com.extend(user.to_com());
|
||||
com.extend(dex.to_com());
|
||||
}
|
||||
Self::AllDexsClearinghouseState { user } => {
|
||||
com.push(14);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::OpenOrders { user, dex } => {
|
||||
com.push(15);
|
||||
com.extend(user.to_com());
|
||||
com.extend(dex.to_com());
|
||||
}
|
||||
Self::SpotState {
|
||||
user,
|
||||
is_portfolio_margin,
|
||||
} => {
|
||||
com.push(16);
|
||||
com.extend(user.to_com());
|
||||
com.extend(is_portfolio_margin.to_com());
|
||||
}
|
||||
Self::Notification { user } => {
|
||||
com.push(17);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::WebData3 { user } => {
|
||||
com.push(18);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::TwapStates { user, dex } => {
|
||||
com.push(19);
|
||||
com.extend(user.to_com());
|
||||
com.extend(dex.to_com());
|
||||
}
|
||||
Self::UserFundings { user } => {
|
||||
com.push(20);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::UserNonFundingLedgerUpdates { user } => {
|
||||
com.push(21);
|
||||
com.extend(user.to_com());
|
||||
}
|
||||
Self::AllDexsAssetCtxs => {
|
||||
com.push(22);
|
||||
}
|
||||
Self::FastAssetCtxs => {
|
||||
com.push(23);
|
||||
}
|
||||
Self::OutcomeMetaUpdates => {
|
||||
com.push(24);
|
||||
}
|
||||
}
|
||||
|
||||
com
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for Address {
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
let bytes: [u8; 20] = com.drain(..20).collect::<Vec<_>>().try_into().unwrap();
|
||||
Self::from_slice(&bytes)
|
||||
}
|
||||
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
self.as_slice().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for CandleInterval {
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
match u8::from_com(com) {
|
||||
0 => Self::OneMinute,
|
||||
1 => Self::ThreeMinutes,
|
||||
2 => Self::FiveMinutes,
|
||||
3 => Self::FifteenMinutes,
|
||||
4 => Self::ThirtyMinutes,
|
||||
5 => Self::OneHour,
|
||||
6 => Self::TwoHours,
|
||||
7 => Self::FourHours,
|
||||
8 => Self::EightHours,
|
||||
9 => Self::TwelveHours,
|
||||
10 => Self::OneDay,
|
||||
11 => Self::ThreeDays,
|
||||
12 => Self::OneWeek,
|
||||
13 => Self::OneMonth,
|
||||
x => panic!("Invalid CandleInterval discriminant: {}", x),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
vec![match self {
|
||||
Self::OneMinute => 0,
|
||||
Self::ThreeMinutes => 1,
|
||||
Self::FiveMinutes => 2,
|
||||
Self::FifteenMinutes => 3,
|
||||
Self::ThirtyMinutes => 4,
|
||||
Self::OneHour => 5,
|
||||
Self::TwoHours => 6,
|
||||
Self::FourHours => 7,
|
||||
Self::EightHours => 8,
|
||||
Self::TwelveHours => 9,
|
||||
Self::OneDay => 10,
|
||||
Self::ThreeDays => 11,
|
||||
Self::OneWeek => 12,
|
||||
Self::OneMonth => 13,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for Candle {
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
Self {
|
||||
open_time: u64::from_com(com),
|
||||
close_time: u64::from_com(com),
|
||||
coin: String::from_com(com),
|
||||
interval: String::from_com(com),
|
||||
open: Decimal::from_com(com),
|
||||
high: Decimal::from_com(com),
|
||||
low: Decimal::from_com(com),
|
||||
close: Decimal::from_com(com),
|
||||
volume: Decimal::from_com(com),
|
||||
num_trades: u64::from_com(com),
|
||||
}
|
||||
}
|
||||
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
let mut com = Vec::new();
|
||||
|
||||
com.extend(self.open_time.to_com());
|
||||
com.extend(self.close_time.to_com());
|
||||
com.extend(self.coin.to_com());
|
||||
com.extend(self.interval.to_com());
|
||||
com.extend(self.open.to_com());
|
||||
com.extend(self.high.to_com());
|
||||
com.extend(self.low.to_com());
|
||||
com.extend(self.close.to_com());
|
||||
com.extend(self.volume.to_com());
|
||||
com.extend(self.num_trades.to_com());
|
||||
|
||||
com
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for Decimal {
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
Self::deserialize(com[..16].try_into().unwrap())
|
||||
}
|
||||
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
self.serialize().to_vec()
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod general;
|
||||
mod hyper_types;
|
||||
pub mod plugin;
|
||||
pub mod terminal;
|
||||
pub mod units;
|
||||
pub use hypersdk;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::PulseWire;
|
||||
pub use crate::general::*;
|
||||
pub use crate::plugin::*;
|
||||
pub use crate::server_path;
|
||||
@@ -21,115 +19,3 @@ pub mod prelude {
|
||||
pub fn server_path() -> PathBuf {
|
||||
PathBuf::from("/tmp/pulse-engine.sock")
|
||||
}
|
||||
|
||||
pub trait PulseWire {
|
||||
fn to_com(&self) -> Vec<u8>;
|
||||
fn from_com(_com: &mut Vec<u8>) -> Self;
|
||||
}
|
||||
|
||||
impl<T: PulseWire> PulseWire for Vec<T> {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
let mut vec = Vec::new();
|
||||
|
||||
vec.extend_from_slice(&(self.len() as u32).to_le_bytes());
|
||||
|
||||
for item in self {
|
||||
vec.extend(item.to_com());
|
||||
}
|
||||
|
||||
vec
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
let len_bytes: [u8; 4] = com.drain(..4).collect::<Vec<_>>().try_into().unwrap();
|
||||
|
||||
let len = u32::from_le_bytes(len_bytes) as usize;
|
||||
|
||||
let mut result = Vec::with_capacity(len);
|
||||
|
||||
for _ in 0..len {
|
||||
result.push(T::from_com(com));
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PulseWire> PulseWire for Option<T> {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
if let Some(v) = self {
|
||||
vec![1].into_iter().chain(v.to_com()).collect()
|
||||
} else {
|
||||
vec![0]
|
||||
}
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
if com[0] > 0 {
|
||||
Some(T::from_com(com))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for String {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
let bytes = self.as_bytes();
|
||||
let mut out = Vec::with_capacity(4 + bytes.len());
|
||||
|
||||
out.extend_from_slice(&(bytes.len() as u32).to_le_bytes());
|
||||
out.extend_from_slice(bytes);
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
let len = u32::from_le_bytes(com[..4].try_into().unwrap()) as usize;
|
||||
com.drain(..4);
|
||||
|
||||
let bytes: Vec<u8> = com.drain(..len).collect();
|
||||
String::from_utf8(bytes).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl PulseWire for bool {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
if *self { vec![1] } else { vec![0] }
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
com[0] > 0
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! int_com {
|
||||
($t:ty) => {
|
||||
impl $crate::PulseWire for $t {
|
||||
fn to_com(&self) -> Vec<u8> {
|
||||
self.to_le_bytes().to_vec()
|
||||
}
|
||||
|
||||
fn from_com(com: &mut Vec<u8>) -> Self {
|
||||
const N: usize = std::mem::size_of::<$t>();
|
||||
let bytes: [u8; N] = com.drain(..N).collect::<Vec<_>>().try_into().unwrap();
|
||||
<$t>::from_le_bytes(bytes)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
int_com!(i8);
|
||||
int_com!(i16);
|
||||
int_com!(i32);
|
||||
int_com!(i64);
|
||||
int_com!(isize);
|
||||
|
||||
int_com!(u8);
|
||||
int_com!(u16);
|
||||
int_com!(u32);
|
||||
int_com!(u64);
|
||||
int_com!(usize);
|
||||
|
||||
int_com!(f64);
|
||||
int_com!(f32);
|
||||
|
||||
Reference in New Issue
Block a user