Skip to content

Commit

Permalink
[Portfolio] Refactor creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Sep 5, 2020
1 parent 651f5f2 commit 0807587
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 7 deletions.
8 changes: 3 additions & 5 deletions octobot_trading/data_manager/portfolio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from octobot_trading.channels.exchange_channel import get_chan
from octobot_trading.constants import CONFIG_SIMULATOR, \
CONFIG_STARTING_PORTFOLIO, CURRENT_PORTFOLIO_STRING, BALANCE_CHANNEL
from octobot_trading.data.margin_portfolio import MarginPortfolio
from octobot_trading.portfolios.portfolio_factory import create_portfolio_from_exchange_manager
from octobot_trading.portfolios.types.margin_portfolio import MarginPortfolio
from octobot_trading.data.portfolio import Portfolio
from octobot_trading.data.portfolio_profitability import PortfolioProfitabilty
from octobot_trading.util.initializable import Initializable
Expand Down Expand Up @@ -75,10 +76,7 @@ async def _reset_portfolio(self):
"""
Reset the portfolio and portfolio profitability instances
"""
if self.exchange_manager.is_margin:
self.portfolio = MarginPortfolio(self.exchange_manager.get_exchange_name(), self.trader.simulate)
else:
self.portfolio = Portfolio(self.exchange_manager.get_exchange_name(), self.trader.simulate)
self.portfolio = create_portfolio_from_exchange_manager(self.exchange_manager)
await self.portfolio.initialize()
self._load_portfolio()

Expand Down
15 changes: 15 additions & 0 deletions octobot_trading/portfolios/__init__.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
15 changes: 15 additions & 0 deletions octobot_trading/portfolios/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
20 changes: 20 additions & 0 deletions octobot_trading/portfolios/portfolio_factory.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# cython: language_level=3
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_trading.data.portfolio cimport Portfolio
from octobot_trading.exchanges.exchange_manager cimport ExchangeManager

cpdef Portfolio create_portfolio_from_exchange_manager(ExchangeManager exchange_manager)
27 changes: 27 additions & 0 deletions octobot_trading/portfolios/portfolio_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_trading.portfolios.types.future_portfolio import FuturePortfolio
from octobot_trading.portfolios.types.margin_portfolio import MarginPortfolio
from octobot_trading.portfolios.types.spot_portfolio import SpotPortfolio


def create_portfolio_from_exchange_manager(exchange_manager):
if exchange_manager.is_future:
return FuturePortfolio(exchange_manager.get_exchange_name(), exchange_manager.trader.simulate)
if exchange_manager.is_margin:
return MarginPortfolio(exchange_manager.get_exchange_name(), exchange_manager.trader.simulate)
return SpotPortfolio(exchange_manager.get_exchange_name(), exchange_manager.trader.simulate)

File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions octobot_trading/portfolios/types/__init__.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
15 changes: 15 additions & 0 deletions octobot_trading/portfolios/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
22 changes: 22 additions & 0 deletions octobot_trading/portfolios/types/future_portfolio.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cython: language_level=3
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.


from octobot_trading.data.portfolio cimport Portfolio

cdef class FuturePortfolio(Portfolio):
pass
20 changes: 20 additions & 0 deletions octobot_trading/portfolios/types/future_portfolio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_trading.data.portfolio import Portfolio


class FuturePortfolio(Portfolio):
pass
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions octobot_trading/portfolios/types/spot_portfolio.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# cython: language_level=3
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.


from octobot_trading.data.portfolio cimport Portfolio

cdef class SpotPortfolio(Portfolio):
pass
21 changes: 21 additions & 0 deletions octobot_trading/portfolios/types/spot_portfolio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Drakkar-Software OctoBot-Trading
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_trading.data.portfolio import Portfolio


class SpotPortfolio(Portfolio):
pass

7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ def build_ext(*args, **kwargs):
"octobot_trading.producers.simulator.prices_updater_simulator",
"octobot_trading.producers.simulator.recent_trade_updater_simulator",
"octobot_trading.producers.simulator.ticker_updater_simulator",
"octobot_trading.data.margin_portfolio",
"octobot_trading.data.order",
"octobot_trading.data.position",
"octobot_trading.data.trade",
"octobot_trading.data.portfolio",
"octobot_trading.data.portfolio_profitability",
"octobot_trading.data.sub_portfolio",
"octobot_trading.data_adapters.candles_adapter",
"octobot_trading.data_manager.candles_manager",
"octobot_trading.data_manager.funding_manager",
Expand Down Expand Up @@ -108,6 +106,11 @@ def build_ext(*args, **kwargs):
"octobot_trading.orders.types.trailing.trailing_stop_order",
"octobot_trading.orders.types.trailing.trailing_stop_limit_order",
"octobot_trading.orders.types.unknown_order",
"octobot_trading.portfolios.portfolio_factory",
"octobot_trading.portfolios.sub_portfolio",
"octobot_trading.portfolios.types.future_portfolio",
"octobot_trading.portfolios.types.margin_portfolio",
"octobot_trading.portfolios.types.spot_portfolio",
"octobot_trading.traders.trader",
"octobot_trading.traders.trader_simulator",
"octobot_trading.trades.trade_factory",
Expand Down

0 comments on commit 0807587

Please sign in to comment.