mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-17 16:23:13 +00:00
Add new admin action to close public order
This commit is contained in:
33
api/admin.py
33
api/admin.py
@ -11,6 +11,7 @@ from rest_framework.authtoken.models import TokenProxy
|
|||||||
from api.logics import Logics
|
from api.logics import Logics
|
||||||
from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot
|
from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot
|
||||||
from api.utils import objects_to_hyperlinks
|
from api.utils import objects_to_hyperlinks
|
||||||
|
from api.tasks import send_notification
|
||||||
|
|
||||||
admin.site.unregister(Group)
|
admin.site.unregister(Group)
|
||||||
admin.site.unregister(User)
|
admin.site.unregister(User)
|
||||||
@ -135,6 +136,7 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
|||||||
return format_html(f'<table style="width: 100%">{with_hyperlinks}</table>')
|
return format_html(f'<table style="width: 100%">{with_hyperlinks}</table>')
|
||||||
|
|
||||||
actions = [
|
actions = [
|
||||||
|
"cancel_public_order",
|
||||||
"maker_wins",
|
"maker_wins",
|
||||||
"taker_wins",
|
"taker_wins",
|
||||||
"return_everything",
|
"return_everything",
|
||||||
@ -142,6 +144,37 @@ class OrderAdmin(AdminChangeLinksMixin, admin.ModelAdmin):
|
|||||||
"compute_median_trade_time",
|
"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")
|
@admin.action(description="Solve dispute: maker wins")
|
||||||
def maker_wins(self, request, queryset):
|
def maker_wins(self, request, queryset):
|
||||||
"""
|
"""
|
||||||
|
@ -185,3 +185,9 @@ class Telegram:
|
|||||||
self.send_message(user.robot.telegram_chat_id, text)
|
self.send_message(user.robot.telegram_chat_id, text)
|
||||||
|
|
||||||
return
|
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
|
||||||
|
@ -304,4 +304,7 @@ def send_notification(order_id=None, chat_message_id=None, message=None):
|
|||||||
elif message == "new_chat_message":
|
elif message == "new_chat_message":
|
||||||
telegram.new_chat_message(order, chat_message)
|
telegram.new_chat_message(order, chat_message)
|
||||||
|
|
||||||
|
elif message == "coordinator_cancelled":
|
||||||
|
telegram.coordinator_cancelled(order)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user