Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeannesson committed Mar 13, 2024
1 parent 0dc86ef commit 2e795f5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions django_napse/core/management/commands/create_dca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def add_arguments(self, parser): # noqa
def handle(self, *args, **options): # noqa
exchange_account = ExchangeAccount.objects.first()
space = Space.objects.first()
config = DCABotConfig.objects.create(space=space, settings={"timeframe": timedelta(minutes=5)})
config = DCABotConfig.objects.create(space=space, settings={"timeframe": timedelta(hours=1)})
controller = Controller.get(
exchange_account=exchange_account,
base="BTC",
quote="USDT",
interval="1m",
interval="15m",
)
architecture = SinglePairArchitecture.objects.create(constants={"controller": controller})
strategy = DCAStrategy.objects.create(config=config, architecture=architecture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def give_order(self, data: dict) -> list[dict]:
"asked_for_amount": 0,
"asked_for_ticker": controller.quote,
"pair": controller.pair,
"price": data["candles"][controller]["latest"]["close"],
"price": data["candles"][controller]["latest"].close,
"side": SIDES.KEEP,
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def give_order(self, data: dict) -> list[dict]:
controller = data["controllers"]["main"]
if (
self.variable_last_buy_date is None
or data["candles"][controller]["current"]["open_time"] - self.variable_last_buy_date >= data["config"]["timeframe"]
or data["candles"][controller]["current"].open_time - self.variable_last_buy_date >= data["config"]["timeframe"]
):
mbp = data["connection_data"][data["connection"]]["connection_specific_args"]["mbp"].get_value()
lbo = data["connection_data"][data["connection"]]["connection_specific_args"]["lbo"].get_value()
Expand All @@ -59,7 +59,7 @@ def give_order(self, data: dict) -> list[dict]:
)
mbp = mbp if mbp is not None else math.inf
sbv = sbv if sbv is not None else available_quote
current_price = data["candles"][controller]["latest"]["close"]
current_price = data["candles"][controller]["latest"].close
amount = data["config"]["percentage"] * sbv / 100
if lbo == 0 or current_price < mbp:
return [
Expand All @@ -69,7 +69,7 @@ def give_order(self, data: dict) -> list[dict]:
"StrategyModifications": [
{
"key": "last_buy_date",
"value": str(data["candles"][controller]["current"]["open_time"]),
"value": str(data["candles"][controller]["current"].open_time),
"target_type": "datetime",
"ignore_failed_order": False,
},
Expand All @@ -79,7 +79,7 @@ def give_order(self, data: dict) -> list[dict]:
"asked_for_amount": amount,
"asked_for_ticker": controller.quote,
"pair": controller.pair,
"price": data["candles"][controller]["latest"]["close"],
"price": data["candles"][controller]["latest"].close,
"side": SIDES.BUY,
},
]
Expand All @@ -91,7 +91,7 @@ def give_order(self, data: dict) -> list[dict]:
"StrategyModifications": [
{
"key": "last_buy_date",
"value": str(data["candles"][controller]["current"]["open_time"]),
"value": str(data["candles"][controller]["current"].open_time),
"target_type": "datetime",
"ignore_failed_order": False,
},
Expand All @@ -101,7 +101,7 @@ def give_order(self, data: dict) -> list[dict]:
"asked_for_amount": available_base,
"asked_for_ticker": controller.base,
"pair": controller.pair,
"price": data["candles"][controller]["latest"]["close"],
"price": data["candles"][controller]["latest"].close,
"side": SIDES.SELL,
},
]
Expand All @@ -112,7 +112,7 @@ def give_order(self, data: dict) -> list[dict]:
"StrategyModifications": [
{
"key": "last_buy_date",
"value": str(data["candles"][controller]["current"]["open_time"]),
"value": str(data["candles"][controller]["current"].open_time),
"target_type": "datetime",
"ignore_failed_order": False,
},
Expand All @@ -122,7 +122,7 @@ def give_order(self, data: dict) -> list[dict]:
"asked_for_amount": 0,
"asked_for_ticker": controller.quote,
"pair": controller.pair,
"price": data["candles"][controller]["latest"]["close"],
"price": data["candles"][controller]["latest"].close,
"side": SIDES.KEEP,
},
]
Expand All @@ -136,7 +136,7 @@ def give_order(self, data: dict) -> list[dict]:
"asked_for_amount": 0,
"asked_for_ticker": controller.quote,
"pair": controller.pair,
"price": data["candles"][controller]["latest"]["close"],
"price": data["candles"][controller]["latest"].close,
"side": SIDES.KEEP,
},
]
3 changes: 1 addition & 2 deletions django_napse/core/models/orders/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_status_post_process__no_db(self, receipt: dict) -> None:
buy_failed = True
if "error" in receipt[SIDES.SELL]:
sell_failed = True
print(receipt, buy_failed, sell_failed)

if buy_failed and sell_failed:
self.status = ORDER_STATUS.FAILED
elif buy_failed:
Expand Down Expand Up @@ -267,7 +267,6 @@ def apply_modifications(self) -> list["Modification"]:

def apply_swap(self) -> None:
"""Swap quote into base (BUY) or base into quote (SELL)."""
self.info()
if self.side == SIDES.BUY:
Debit.objects.create(
wallet=self.wallet,
Expand Down
1 change: 0 additions & 1 deletion django_napse/core/tasks/order_process_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def _run(self) -> None:
for order in orders:
order.apply_modifications()
order.process_payout()
order.info()

if processed > 0:
self.info(f"Processed {processed} orders")
Expand Down
11 changes: 6 additions & 5 deletions django_napse/simulations/models/simulations/simulation_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django_napse.core.models.modifications import ArchitectureModification, ConnectionModification, StrategyModification
from django_napse.core.models.orders.order import Order, OrderBatch
from django_napse.core.models.transactions.credit import Credit
from django_napse.core.pydantic.candle import CandlePydantic
from django_napse.core.pydantic.currency import CurrencyPydantic
from django_napse.simulations.models.datasets.dataset import Candle, DataSet
from django_napse.simulations.models.simulations.managers import SimulationQueueManager
Expand Down Expand Up @@ -153,7 +154,7 @@ def process_candle_data(self, candle_data, min_interval):
processed_data = {"candles": {}, "extras": {}}
current_prices = {}
for controller, candle in candle_data.items():
processed_data["candles"][controller] = {"current": candle, "latest": candle}
processed_data["candles"][controller] = {"current": CandlePydantic(**candle), "latest": CandlePydantic(**candle)}
if controller.quote == "USDT" and controller.interval == min_interval:
price = candle["close"]
current_prices[f"{controller.base}_price"] = price
Expand Down Expand Up @@ -274,8 +275,8 @@ def quick_simulation(self, bot, no_db_data, verbose=True):
"keep_orders": [order for order in order_objects if order.side == SIDES.KEEP],
"batches": [batch],
"exchange_controller": exchange_controllers[controller],
"min_trade": controller.min_notional / processed_data["candles"][controller]["latest"]["close"],
"price": processed_data["candles"][controller]["latest"]["close"],
"min_trade": controller.min_notional / processed_data["candles"][controller]["latest"].close,
"price": processed_data["candles"][controller]["latest"].close,
},
testing=True,
)
Expand Down Expand Up @@ -370,8 +371,8 @@ def irl_simulation(self, bot, no_db_data, verbose=True):
"keep_orders": [order for order in orders if order.side == SIDES.KEEP],
"batches": [batch],
"exchange_controller": exchange_controllers[controller],
"min_trade": controller.min_notional / processed_data["candles"][controller]["latest"]["close"],
"price": processed_data["candles"][controller]["latest"]["close"],
"min_trade": controller.min_notional / processed_data["candles"][controller]["latest"].close,
"price": processed_data["candles"][controller]["latest"].close,
},
testing=True,
)
Expand Down

0 comments on commit 2e795f5

Please sign in to comment.