Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Sep 17, 2024
1 parent 1cf7823 commit 9e6d85c
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 231 deletions.
8 changes: 5 additions & 3 deletions copilot/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

from ._prompt import (
signal_contrarian_risk_prompt,
signal_risk_pattern,
signal_trend_risk_prompt,
system_prompt,
signal_risk_pattern,
)

CopilotEvent = Union[EvaluateSignal, EvaluateSession]
Expand Down Expand Up @@ -171,7 +171,8 @@ async def _evaluate_signal(self, msg: EvaluateSignal) -> SignalRisk:
type=risk_type,
)

bar = sorted(prev_bar + [curr_bar], key=lambda x: x.timestamp)
bar = [f"{b}" for b in sorted(prev_bar + [curr_bar], key=lambda x: x.timestamp)]

strategy_type = (
StrategyType.CONTRARIAN
if "SUP" not in str(signal.strategy)
Expand Down Expand Up @@ -258,6 +259,7 @@ async def _evaluate_session(self, msg: EvaluateSession) -> SessionRiskType:
mfi = np.array(ta.volume.mfi[-LOOKBACK:])
vwap = np.array(ta.volume.vwap[-LOOKBACK:])
nvol = np.array(ta.volume.nvol[-LOOKBACK:])
vo = np.array(ta.volume.vo[-LOOKBACK:])
yz = np.array(ta.volatility.yz[-LOOKBACK:])
tr = np.array(ta.volatility.tr[-LOOKBACK:])

Expand All @@ -279,7 +281,7 @@ async def _evaluate_session(self, msg: EvaluateSession) -> SessionRiskType:
vwap,
tr,
nvol,
hlcc4,
vo,
)
)

Expand Down
2 changes: 1 addition & 1 deletion core/events/ohlcv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field

from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.symbol import Symbol
from core.models.timeframe import Timeframe

Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/abstract_market_repository.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import abstractmethod

from core.interfaces.abstract_event_manager import AbstractEventManager
from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.symbol import Symbol
from core.models.timeframe import Timeframe

Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/abstract_position_risk_strategy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import List, Tuple

from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.signal import SignalSide


Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/abstract_timeseries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from typing import Optional

from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.symbol import Symbol
from core.models.timeframe import Timeframe

Expand Down
9 changes: 0 additions & 9 deletions core/models/bar.py

This file was deleted.

10 changes: 10 additions & 0 deletions core/models/candle_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum, auto


class CandleType(Enum):
BULLISH = auto()
BEARISH = auto()
NEUTRAL = auto()

def __str__(self):
return self.name.upper()
3 changes: 1 addition & 2 deletions core/models/indicator.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from abc import ABC
from dataclasses import asdict, dataclass, fields
from enum import Enum
from typing import Any


@dataclass(frozen=True)
class Indicator(ABC):
class Indicator:
type: Any

def to_dict(self) -> dict:
Expand Down
178 changes: 0 additions & 178 deletions core/models/ohlcv.py

This file was deleted.

24 changes: 8 additions & 16 deletions core/models/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from .ohlcv import OHLCV
from .entity.ohlcv import OHLCV
from .order import Order, OrderStatus
from .position_risk import PositionRisk
from .profit_target import ProfitTarget
Expand Down Expand Up @@ -356,29 +356,21 @@ def target_filter(target, tp):
dist_ratio = dist / entry_price
is_exit = session_risk == SessionRiskType.EXIT

trail_threshold = 0.0008
trail_threshold = 0.0011

if dist > trl_dist and trl_ratio > trail_threshold:
logger.info("Activating trailing stop mechanism")
next_position = next_position.trail(ta)

if is_exit:
exit_ratio = exit_dist / entry_price
dist_ratio = dist / entry_price

if exit_ratio > 0.005:
next_position = next_position.trail(ta)

logger.info(
f"TRAIL NEXT SL: {next_position.stop_loss:.6f}, "
f"CURR PRICE: {next_position.risk_bar.close:.6f}"
)
else:
logger.info(
f"Exit condition not met: "
f"CURR_DIST: {dist:.6f} ({dist_ratio:.2%}), "
f"EXIT_DIST: {exit_dist:.6f} ({exit_ratio:.2%})"
)
next_position = next_position.trail(ta)

logger.info(
f"TRAIL NEXT SL: {next_position.stop_loss:.6f}, "
f"CURR PRICE: {next_position.risk_bar.close:.6f}"
)

next_sl = next_position.stop_loss
next_risk = next_position.position_risk
Expand Down
2 changes: 1 addition & 1 deletion core/models/position_risk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from sklearn.preprocessing import MinMaxScaler, StandardScaler

from .ohlcv import OHLCV
from .entity.ohlcv import OHLCV
from .risk_type import PositionRiskType
from .side import PositionSide
from .ta import TechAnalysis
Expand Down
2 changes: 1 addition & 1 deletion core/models/signal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field

from .ohlcv import OHLCV
from .entity.ohlcv import OHLCV
from .side import SignalSide
from .strategy import Strategy
from .symbol import Symbol
Expand Down
2 changes: 1 addition & 1 deletion core/models/strategy_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
GoShortSignalReceived,
)
from core.models.action import Action
from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.side import SignalSide
from core.models.signal import Signal
from core.models.strategy import Strategy
Expand Down
3 changes: 2 additions & 1 deletion core/models/timeseries_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
if typing.TYPE_CHECKING:
from wasmtime import Instance, Store

from .ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV

from .ta import TechAnalysis


Expand Down
2 changes: 1 addition & 1 deletion core/queries/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from core.events.base import EventMeta
from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.risk_type import SessionRiskType
from core.models.side import PositionSide
from core.models.signal import Signal
Expand Down
2 changes: 1 addition & 1 deletion core/queries/ohlcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from core.events.base import EventMeta
from core.models.ohlcv import OHLCV
from core.models.entity.ohlcv import OHLCV
from core.models.symbol import Symbol
from core.models.ta import TechAnalysis
from core.models.timeframe import Timeframe
Expand Down
4 changes: 2 additions & 2 deletions exchange/_bybit_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from websockets.exceptions import ConnectionClosedError

from core.interfaces.abstract_ws import AbstractWS
from core.models.bar import Bar
from core.models.ohlcv import OHLCV
from core.models.entity.bar import Bar
from core.models.entity.ohlcv import OHLCV
from core.models.timeframe import Timeframe
from infrastructure.retry import retry

Expand Down
Loading

0 comments on commit 9e6d85c

Please sign in to comment.