Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
m5l14i11 committed Dec 6, 2023
1 parent 547ffe7 commit afb98d6
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ risk_reward_ratio = 1.5
risk_buffer = 0.0001
twap_duration = 300
max_order_slice = 8
entry_timeout = 60
entry_timeout = 30
stop_loss_threshold = 0.5

[portfolio]
Expand Down
2 changes: 1 addition & 1 deletion core/queries/position.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from core.models.order import Order

from core.models.order import Order
from core.models.position import Position
from core.queries.base import Query

Expand Down
4 changes: 1 addition & 3 deletions executor/market_order_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ async def _close_position(self, event: PositionCloseRequested):

await self.ask(ClosePosition(current_position))

order = await self.ask(
GetClosePosition(current_position)
)
order = await self.ask(GetClosePosition(current_position))

current_position = current_position.add_order(order)

Expand Down
2 changes: 1 addition & 1 deletion portfolio/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ async def update_account_size(self, command: UpdateAccountSize):

@command_handler(PortfolioReset)
async def portfolio_reset(self, _event: PortfolioReset):
await self.state.reset_all()
await self.state.reset_all()
Empty file.
4 changes: 2 additions & 2 deletions quant.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def main():
"bus": {"num_workers": os.cpu_count()},
"store": {"base_dir": LOG_DIR},
"generator": {
"timeframes": [str(Timeframe.FIVE_MINUTES)],
"timeframes": [str(Timeframe.ONE_MINUTE)],
"blacklist": ["USDCUSDT"],
},
}
Expand All @@ -79,7 +79,7 @@ async def main():
exchange_factory = ExchangeFactory(EnvironmentSecretService())

Portfolio(config_service)
SmartRouter(exchange_factory)
SmartRouter(exchange_factory, config_service)

Backtest(DataSourceFactory(exchange_factory), config_service)
feed = Feed(EnvironmentSecretService())
Expand Down
12 changes: 9 additions & 3 deletions sor/_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from core.interfaces.abstract_exhange_factory import AbstractExchangeFactory
from core.models.exchange import ExchangeType
from core.models.order import Order, OrderStatus
from core.models.position import PositionSide
from core.queries.account import GetBalance
from core.queries.broker import GetSymbol, GetSymbols
from core.queries.position import GetClosePosition, GetOpenPosition
Expand Down Expand Up @@ -46,7 +45,7 @@ def get_open_position(self, query: GetOpenPosition):
@query_handler(GetClosePosition)
def get_close_position(self, query: GetClosePosition):
position = query.position

symbol = position.signal.symbol

trade = self.exchange.fetch_trade(symbol)
Expand Down Expand Up @@ -87,15 +86,22 @@ async def open_position(self, command: OpenPosition):
symbol = position.signal.symbol
position_side = position.side
position_size = position.size
stop_loss = position.stop_loss_price
distance_to_stop_loss = abs(position.entry_price - stop_loss)

min_size = symbol.min_position_size
max_order_slice = self.config["max_order_slice"]
entry_timeout = self.config["entry_timeout"]
stop_loss_threshold = self.config["stop_loss_threshold"]

num_orders = min(max(1, int(position_size / min_size)), max_order_slice)
size = round(position_size / num_orders, symbol.position_precision)
order_counter = 0

for price in self.entry_price.calculate(symbol, self.exchange):
if distance_to_stop_loss > stop_loss_threshold * abs(stop_loss - price):
break

order_id = self.exchange.create_limit_order(
symbol, position_side, size, price
)
Expand All @@ -108,7 +114,7 @@ async def open_position(self, command: OpenPosition):
if order_counter >= num_orders:
break

await asyncio.sleep(self.config["entry_timeout"])
await asyncio.sleep(entry_timeout)

@command_handler(ClosePosition)
def close_position(self, command: ClosePosition):
Expand Down
1 change: 1 addition & 0 deletions sor/_twap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time

import numpy as np

from core.interfaces.abstract_config import AbstractConfig
Expand Down
Empty file added strategy/baseline/__init__.py
Empty file.
Empty file added strategy/stop_loss/__init__.py
Empty file.

0 comments on commit afb98d6

Please sign in to comment.