Skip to content

Commit

Permalink
Improve TraderoBotGroup
Browse files Browse the repository at this point in the history
- Add jumping action
  • Loading branch information
math-a3k committed Aug 21, 2023
1 parent 4211b28 commit e5a3abf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,12 @@ def liquidate(self):
bot.off()
return True

def jump(self, to_symbol):
for bot in self.bots.all():
if not bot.price_buying:
bot.jump(to_symbol)
return True

@property
def current_valuation(self):
valuations = [
Expand Down
3 changes: 3 additions & 0 deletions base/templates/base/botzinhos_group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ <h4 class="mt-3">Actions</h4>
<li>
<a class="btn btn-primary" href="{% url "base:botzinhos-create" %}?group={{group.pk}}">Novo Botzinho</a>
</li>
<li>
{% include "base/_jumping_form.html" with view="base:botzinhos-group-action" obj=group %}
</li>
<li>
{% url "base:botzinhos-group-action" group.pk "off" as action_url %}
{% action_button action_url "Turn OFF" "btn-dark" %}
Expand Down
18 changes: 18 additions & 0 deletions base/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,24 @@ def test_botzinhos_group_actions(self):
self.assertEqual(self.bot2.status, TraderoBot.Status.INACTIVE)
self.assertIn("Sold", self.bot1.others["last_logs"][-2])
self.assertIn("OFF", self.bot1.others["last_logs"][-1])
with requests_mock.Mocker() as m:
m.get(
f"{BINANCE_API_URL}/api/v3/ticker/price",
json={"symbol": "S1BUSD", "price": "1.0"},
)
self.bot2.buy()
url = reverse(
"base:botzinhos-group-action",
kwargs={
"pk": self.group1.pk,
"action": "jump",
},
)
response = self.client.post(
url, {"to_symbol": self.s1.pk}, follow=True
)
self.assertEqual(response.status_code, 200)
self.assertIn(b"SUCCESS at", response.content)


class TestAdmin(TestCase):
Expand Down
8 changes: 7 additions & 1 deletion base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def get_context_data(self, **kwargs):
context["bots"] = bots
context["summary"] = summary
context["quote_asset"] = settings.QUOTE_ASSET
context["form_jumping"] = JumpingForm()
return context


Expand Down Expand Up @@ -326,7 +327,12 @@ class BotzinhosGroupActionView(ActionView):
Runs Actions on Botzinhos Group
"""

ACTIONS = ["on", "off", "liquidate"]
ACTIONS = {
"on": {"params": None},
"off": {"params": None},
"liquidate": {"params": None},
"jump": {"params": {"to_symbol": {"type": "Model", "class": Symbol}}},
}

def get_object(self):
self.object = get_object_or_404(TraderoBotGroup, pk=self.pk)
Expand Down

0 comments on commit e5a3abf

Please sign in to comment.