mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 10:56:24 +00:00
Fix premium percentile computation
This commit is contained in:
parent
848a513bc3
commit
7c0e3a74fa
@ -112,11 +112,10 @@ class Logics():
|
|||||||
# Do not change order status if an order in any with
|
# Do not change order status if an order in any with
|
||||||
# any of these status is sent to expire here
|
# any of these status is sent to expire here
|
||||||
do_nothing = [Order.Status.DEL, Order.Status.UCA,
|
do_nothing = [Order.Status.DEL, Order.Status.UCA,
|
||||||
Order.Status.EXP, Order.Status.FSE,
|
Order.Status.EXP, Order.Status.TLD,
|
||||||
Order.Status.DIS, Order.Status.CCA,
|
Order.Status.DIS, Order.Status.CCA,
|
||||||
Order.Status.PAY, Order.Status.SUC,
|
Order.Status.PAY, Order.Status.SUC,
|
||||||
Order.Status.FAI, Order.Status.MLD,
|
Order.Status.FAI, Order.Status.MLD]
|
||||||
Order.Status.TLD]
|
|
||||||
|
|
||||||
if order.status in do_nothing:
|
if order.status in do_nothing:
|
||||||
return False
|
return False
|
||||||
@ -196,8 +195,8 @@ class Logics():
|
|||||||
cls.publish_order(order)
|
cls.publish_order(order)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
elif order.status == Order.Status.CHA:
|
elif order.status in [Order.Status.CHA, Order.Status.FSE]:
|
||||||
# Another weird case. The time to confirm 'fiat sent' expired. Yet no dispute
|
# Another weird case. The time to confirm 'fiat sent or received' expired. Yet no dispute
|
||||||
# was opened. Hint: a seller-scammer could persuade a buyer to not click "fiat
|
# was opened. Hint: a seller-scammer could persuade a buyer to not click "fiat
|
||||||
# sent", we assume this is a dispute case by default.
|
# sent", we assume this is a dispute case by default.
|
||||||
cls.open_dispute(order)
|
cls.open_dispute(order)
|
||||||
@ -674,16 +673,11 @@ class Logics():
|
|||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def pay_buyer_invoice(order):
|
|
||||||
''' Pay buyer invoice'''
|
|
||||||
suceeded, context = follow_send_payment(order.buyer_invoice)
|
|
||||||
return suceeded, context
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def confirm_fiat(cls, order, user):
|
def confirm_fiat(cls, order, user):
|
||||||
''' If Order is in the CHAT states:
|
''' If Order is in the CHAT states:
|
||||||
If user is buyer: mark FIAT SENT and settle escrow!
|
If user is buyer: mark FIAT SENT!
|
||||||
If User is the seller and FIAT is SENT: Pay buyer invoice!'''
|
If User is the seller and FIAT is SENT: Settle escrow and pay buyer invoice!'''
|
||||||
|
|
||||||
if order.status == Order.Status.CHA or order.status == Order.Status.FSE: # TODO Alternatively, if all collateral is locked? test out
|
if order.status == Order.Status.CHA or order.status == Order.Status.FSE: # TODO Alternatively, if all collateral is locked? test out
|
||||||
|
|
||||||
@ -692,7 +686,7 @@ class Logics():
|
|||||||
order.status = Order.Status.FSE
|
order.status = Order.Status.FSE
|
||||||
order.is_fiat_sent = True
|
order.is_fiat_sent = True
|
||||||
|
|
||||||
# If seller and fiat was sent, SETTLE ESCRO AND PAY BUYER INVOICE
|
# If seller and fiat was sent, SETTLE ESCROw AND PAY BUYER INVOICE
|
||||||
elif cls.is_seller(order, user):
|
elif cls.is_seller(order, user):
|
||||||
if not order.is_fiat_sent:
|
if not order.is_fiat_sent:
|
||||||
return False, {'bad_request':'You cannot confirm to have received the fiat before it is confirmed to be sent by the buyer.'}
|
return False, {'bad_request':'You cannot confirm to have received the fiat before it is confirmed to be sent by the buyer.'}
|
||||||
@ -706,7 +700,7 @@ class Logics():
|
|||||||
|
|
||||||
# Double check the escrow is settled.
|
# Double check the escrow is settled.
|
||||||
if LNNode.double_check_htlc_is_settled(order.trade_escrow.payment_hash):
|
if LNNode.double_check_htlc_is_settled(order.trade_escrow.payment_hash):
|
||||||
is_payed, context = cls.pay_buyer_invoice(order) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
|
is_payed, context = follow_send_payment(order.buyer_invoice) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
|
||||||
if is_payed:
|
if is_payed:
|
||||||
order.status = Order.Status.SUC
|
order.status = Order.Status.SUC
|
||||||
order.buyer_invoice.status = LNPayment.Status.SUCCED
|
order.buyer_invoice.status = LNPayment.Status.SUCCED
|
||||||
@ -716,9 +710,10 @@ class Logics():
|
|||||||
# RETURN THE BONDS
|
# RETURN THE BONDS
|
||||||
cls.return_bond(order.taker_bond)
|
cls.return_bond(order.taker_bond)
|
||||||
cls.return_bond(order.maker_bond)
|
cls.return_bond(order.maker_bond)
|
||||||
|
return True, context
|
||||||
else:
|
else:
|
||||||
# error handling here
|
# error handling here
|
||||||
pass
|
return False, context
|
||||||
else:
|
else:
|
||||||
return False, {'bad_request':'You cannot confirm the fiat payment at this stage'}
|
return False, {'bad_request':'You cannot confirm the fiat payment at this stage'}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ premium_percentile = {}
|
|||||||
@ring.dict(premium_percentile, expire=300)
|
@ring.dict(premium_percentile, expire=300)
|
||||||
def compute_premium_percentile(order):
|
def compute_premium_percentile(order):
|
||||||
|
|
||||||
queryset = Order.objects.filter(currency=order.currency, status=Order.Status.PUB)
|
queryset = Order.objects.filter(currency=order.currency, status=Order.Status.PUB).exclude(id=order.id)
|
||||||
|
|
||||||
print(len(queryset))
|
print(len(queryset))
|
||||||
if len(queryset) <= 1:
|
if len(queryset) <= 1:
|
||||||
@ -84,5 +84,8 @@ def compute_premium_percentile(order):
|
|||||||
rates.append(float(similar_order.last_satoshis) / float(similar_order.amount))
|
rates.append(float(similar_order.last_satoshis) / float(similar_order.amount))
|
||||||
|
|
||||||
rates = np.array(rates)
|
rates = np.array(rates)
|
||||||
|
print(rates)
|
||||||
|
print(order_rate)
|
||||||
|
print(np.sum(rates < order_rate))
|
||||||
return round(np.sum(rates < order_rate) / len(rates),2)
|
return round(np.sum(rates < order_rate) / len(rates),2)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ export default class BookPage extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
orders: new Array({id:0,}),
|
orders: new Array({id:0,}),
|
||||||
currency: 0,
|
currency: 0,
|
||||||
type: 1,
|
type: 2,
|
||||||
currencies_dict: {"0":"ANY"},
|
currencies_dict: {"0":"ANY"},
|
||||||
loading: true,
|
loading: true,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user