diff --git a/api/admin.py b/api/admin.py
index 0846ad67..d853d7da 100644
--- a/api/admin.py
+++ b/api/admin.py
@@ -11,6 +11,7 @@ from rest_framework.authtoken.models import TokenProxy
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)
@@ -135,6 +136,7 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
return format_html(f'
')
actions = [
+ "cancel_public_order",
"maker_wins",
"taker_wins",
"return_everything",
@@ -142,6 +144,37 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
"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):
"""
diff --git a/api/notifications.py b/api/notifications.py
index 8d1e0e65..c1bd1f46 100644
--- a/api/notifications.py
+++ b/api/notifications.py
@@ -185,3 +185,9 @@ class Telegram:
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
diff --git a/api/tasks.py b/api/tasks.py
index aa8afe18..f91fd25e 100644
--- a/api/tasks.py
+++ b/api/tasks.py
@@ -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