Skip to content

Commit

Permalink
Add new admin action to close public order
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Jan 28, 2024
1 parent 6297643 commit 4aca6b9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
33 changes: 33 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from api.logics import Logics
from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot
from api.utils import objects_to_hyperlinks
from api.tasks import send_notification

admin.site.unregister(Group)
admin.site.unregister(User)
Expand Down Expand Up @@ -135,13 +136,45 @@ def _logs(self, obj):
return format_html(f'<table style="width: 100%">{with_hyperlinks}</table>')

actions = [
"cancel_public_order",
"maker_wins",
"taker_wins",
"return_everything",
"successful_trade",
"compute_median_trade_time",
]

@admin.action(description="Close public order")
def cancel_public_order(self, request, queryset):
"""
Closes an existing Public/Paused order.
"""
for order in queryset:
if order.status in [Order.Status.PUB, Order.Status.PAU]:
if Logics.return_bond(order.maker_bond):
order.update_status(Order.Status.UCA)
self.message_user(
request,
f"Order {order.id} successfully closed",
messages.SUCCESS,
)
send_notification.delay(
order_id=order.id, message="coordinator_cancelled"
)
else:
self.message_user(
request,
f"Could not unlock bond of {order.id}",
messages.ERROR,
)

else:
self.message_user(
request,
f"Order {order.id} is not public or paused",
messages.ERROR,
)

@admin.action(description="Solve dispute: maker wins")
def maker_wins(self, request, queryset):
"""
Expand Down
6 changes: 6 additions & 0 deletions api/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ def new_chat_message(self, order, chat_message):
self.send_message(user.robot.telegram_chat_id, text)

return

def coordinator_cancelled(self, order):
if order.maker.robot.telegram_enabled:
text = f"🛠️ Your order with ID {order.id} has been cancelled by the coordinator {config('COORDINATOR_ALIAS', cast=str, default='NoAlias')} for the upcoming maintenance stop."
self.send_message(order.maker.robot.telegram_chat_id, text)
return
3 changes: 3 additions & 0 deletions api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,7 @@ def send_notification(order_id=None, chat_message_id=None, message=None):
elif message == "new_chat_message":
telegram.new_chat_message(order, chat_message)

elif message == "coordinator_cancelled":
telegram.coordinator_cancelled(order)

return

0 comments on commit 4aca6b9

Please sign in to comment.