From 7764cf8f7ab59e02931ea98bca28066206077baa Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Tue, 28 Jul 2026 16:53:15 +0200 Subject: [PATCH] Working protocol --- src/__init__.py | 15 ++++++++++-- src/general.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++- src/plugin.py | 4 ++-- src/pwp.py | 4 ++-- src/units.py | 10 ++++---- 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index c2d43b9..8c2f2a1 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -36,7 +36,7 @@ class PulseWire: class Strategy(PulseWire): def on_request(self, req: plugin.StrategyEngineMessage): - pass + ... def send(self, req: plugin.StrategyMessageType): self.send_raw(req.to_com()) @@ -69,7 +69,7 @@ class Strategy(PulseWire): class Risk(PulseWire): def on_request(self, req: plugin.RiskEngineMessage): - pass + ... def send(self, req: plugin.RiskMessageType): self.send_raw(req.to_com()) @@ -94,3 +94,14 @@ class Risk(PulseWire): def on_raw_engine_request(self, data: bytes): com = plugin.RiskEngineMessage.from_com(data=data) + +class Bro(Strategy): + def __init__(self): + self.log(general.EventLog.info("bro", "Hello, World")) + super().__init__() + + def on_request(self, req: plugin.StrategyEngineMessage): + # self.log(general.EventLog.info("bro", "Hello, World")) + pass + +Bro().start() \ No newline at end of file diff --git a/src/general.py b/src/general.py index 137955a..e9a773d 100644 --- a/src/general.py +++ b/src/general.py @@ -1,6 +1,7 @@ from pwp import pwp, pwp_enum, PulseWire from adv_types import * import units +from typing import TypeAlias @pwp_enum class MarketTrend(PulseWire): @@ -42,12 +43,73 @@ class Signal(PulseWire): take_profit: units.USD stop_loss: units.USD +MarketTrendType: TypeAlias = ( + MarketTrend.Bullish + | MarketTrend.Bearish + | MarketTrend.Neutral +) + +LogKindType: TypeAlias = ( + LogKind.Info + | LogKind.Warn + | LogKind.Err + | LogKind.Debug +) + +CandleIntervalType: TypeAlias = ( + CandleInterval.OneMinute + | CandleInterval.ThreeMinutes + | CandleInterval.FiveMinutes + | CandleInterval.FifteenMinutes + | CandleInterval.ThirtyMinutes + | CandleInterval.OneHour + | CandleInterval.TwoHours + | CandleInterval.FourHours + | CandleInterval.EightHours + | CandleInterval.TwelveHours + | CandleInterval.OneDay + | CandleInterval.ThreeDays + | CandleInterval.OneWeek + | CandleInterval.OneMonth +) + @pwp class EventLog(PulseWire): - kind: LogKind + kind: LogKindType name: str message: str + @classmethod + def info(cls, name: str, message: str): + log = cls() + log.kind = LogKind.Info() + log.name = name + log.message = message + return log + + @classmethod + def warn(cls, name: str, message: str): + log = cls() + log.kind = LogKind.Warn() + log.name = name + log.message = message + return log + + @classmethod + def error(cls, name: str, message: str): + log = cls() + log.kind = LogKind.Err() + log.name = name + log.message = message + return log + + @classmethod + def debug(cls, name: str, message: str): + log = cls() + log.kind = LogKind.Debug() + log.name = name + log.message = message + return log @pwp class Position(PulseWire): symbol: units.Symbol diff --git a/src/plugin.py b/src/plugin.py index fa3716b..707f353 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -63,7 +63,7 @@ class StrategyEngineMessage(PulseWire): interval: general.CandleInterval candle: general.Candle - class CandleStick(PulseWire): + class Candlestick(PulseWire): symbol: str interval: general.CandleInterval candles: list[general.Candle] @@ -105,7 +105,7 @@ StrategyEngineMessageType: TypeAlias = ( | StrategyEngineMessage.WatchList | StrategyEngineMessage.Command | StrategyEngineMessage.CandleUpdate - | StrategyEngineMessage.CandleStick + | StrategyEngineMessage.Candlestick ) RiskEngineMessageType: TypeAlias = ( diff --git a/src/pwp.py b/src/pwp.py index dcbecbf..939f56d 100644 --- a/src/pwp.py +++ b/src/pwp.py @@ -461,7 +461,7 @@ def pwp_enum(cls: T) -> T: return ( idx.to_bytes(1, "little") - + PulseWire.to_com(self) + + self.to_com() ) raise PWPError( @@ -484,7 +484,7 @@ def pwp_enum(cls: T) -> T: ) enum_id = data[offset] - offset += 1 + # offset += 1 if enum_id not in variants: diff --git a/src/units.py b/src/units.py index bc60577..0f49203 100644 --- a/src/units.py +++ b/src/units.py @@ -1,21 +1,21 @@ -from pwp import pwp, pwp_enum +from pwp import pwp, pwp_enum, PulseWire from adv_types import * @pwp -class Symbol: +class Symbol(PulseWire): unit: str @pwp -class USD: +class USD(PulseWire): unit: f64 @pwp_enum -class Direction: +class Direction(PulseWire): class Buy: pass class Sell: pass @pwp_enum -class Volatility: +class Volatility(PulseWire): class Low: pass class Medium: pass class High: pass