-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from napse-invest/dev
Dev
- Loading branch information
Showing
32 changed files
with
471 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
from datetime import timedelta | ||
|
||
import environ | ||
from django.core.exceptions import ImproperlyConfigured | ||
from django.core.management.base import BaseCommand | ||
from django.db.transaction import atomic | ||
|
||
from django_napse.core.models import Bot, Controller, DCABotConfig, DCAStrategy, SinglePairArchitecture | ||
from django_napse.core.models.accounts.exchange import BinanceAccount | ||
from django_napse.core.models.accounts.space import Space | ||
from django_napse.core.models.fleets.fleet import Fleet | ||
from django_napse.core.models.transactions.credit import Credit | ||
|
||
|
||
class Command(BaseCommand): # noqa | ||
help = "Create a prebuilt space with a fleet and a DCABot" | ||
|
||
def add_arguments(self, parser): # noqa | ||
pass | ||
|
||
def handle(self, *args, **options): # noqa | ||
env = environ.Env() | ||
with atomic(): | ||
try: | ||
public_key = env.str("BINANCE_PUBLIC_KEY") | ||
private_key = env.str("BINANCE_PRIVATE_KEY") | ||
except ImproperlyConfigured: | ||
self.stdout.write(self.style.ERROR("Please set up BINANCE_PUBLIC_KEY and BINANCE_PRIVATE_KEY in .env file")) | ||
exchange_account = BinanceAccount.objects.get( | ||
public_key=public_key, | ||
private_key=private_key, | ||
) | ||
space = Space.objects.create( | ||
name="Prebuilt Space", | ||
description="We've created a space for you with all the necessary data to try out the app.", | ||
exchange_account=exchange_account, | ||
) | ||
Credit.objects.create(wallet=space.wallet, ticker="USDT", amount=100000) | ||
config = DCABotConfig.objects.create(space=space, settings={"timeframe": timedelta(minutes=1)}) | ||
config5 = DCABotConfig.objects.create(space=space, settings={"timeframe": timedelta(minutes=5)}) | ||
fleet = Fleet.objects.create( | ||
name="Prebuilt Fleet", | ||
exchange_account=exchange_account, | ||
clusters=[ | ||
{ | ||
"template_bot": Bot.objects.create( | ||
name="Prebuilt DCABot", | ||
strategy=DCAStrategy.objects.create( | ||
config=config, | ||
architecture=SinglePairArchitecture.objects.create( | ||
constants={ | ||
"controller": Controller.get( | ||
exchange_account=exchange_account, | ||
base="BTC", | ||
quote="USDT", | ||
interval="1m", | ||
), | ||
}, | ||
), | ||
), | ||
), | ||
"share": 0.3, | ||
"breakpoint": 0, | ||
"autoscale": False, | ||
}, | ||
{ | ||
"template_bot": Bot.objects.create( | ||
name="Prebuilt DCABot", | ||
strategy=DCAStrategy.objects.create( | ||
config=config, | ||
architecture=SinglePairArchitecture.objects.create( | ||
constants={ | ||
"controller": Controller.get( | ||
exchange_account=exchange_account, | ||
base="ETH", | ||
quote="USDT", | ||
interval="1m", | ||
), | ||
}, | ||
), | ||
), | ||
), | ||
"share": 0.3, | ||
"breakpoint": 0, | ||
"autoscale": False, | ||
}, | ||
{ | ||
"template_bot": Bot.objects.create( | ||
name="Prebuilt DCABot", | ||
strategy=DCAStrategy.objects.create( | ||
config=config5, | ||
architecture=SinglePairArchitecture.objects.create( | ||
constants={ | ||
"controller": Controller.get( | ||
exchange_account=exchange_account, | ||
base="MATIC", | ||
quote="USDT", | ||
interval="1m", | ||
), | ||
}, | ||
), | ||
), | ||
), | ||
"share": 0.2, | ||
"breakpoint": 0, | ||
"autoscale": False, | ||
}, | ||
{ | ||
"template_bot": Bot.objects.create( | ||
name="Prebuilt DCABot", | ||
strategy=DCAStrategy.objects.create( | ||
config=config5, | ||
architecture=SinglePairArchitecture.objects.create( | ||
constants={ | ||
"controller": Controller.get( | ||
exchange_account=exchange_account, | ||
base="MATIC", | ||
quote="USDT", | ||
interval="5m", | ||
), | ||
}, | ||
), | ||
), | ||
), | ||
"share": 0.2, | ||
"breakpoint": 0, | ||
"autoscale": False, | ||
}, | ||
], | ||
) | ||
fleet.invest(space=space, amount=10000, ticker="USDT") | ||
fleet.running = True | ||
fleet.save() | ||
self.stdout.write(self.style.SUCCESS("DCABot has been created successfully!")) |
23 changes: 23 additions & 0 deletions
23
django_napse/core/migrations/0011_alter_strategy_architecture_alter_strategy_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.7 on 2024-03-15 16:17 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("django_napse_core", "0010_rename_napsespace_space"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="strategy", | ||
name="architecture", | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="strategy", to="django_napse_core.architecture"), | ||
), | ||
migrations.AlterField( | ||
model_name="strategy", | ||
name="config", | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name="strategy", to="django_napse_core.botconfig"), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
django_napse/core/migrations/0012_alter_strategy_architecture.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.7 on 2024-03-15 16:21 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("django_napse_core", "0011_alter_strategy_architecture_alter_strategy_config"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="strategy", | ||
name="architecture", | ||
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name="strategy", to="django_napse_core.architecture"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.