fix for total sell
This commit is contained in:
parent
fcddb09694
commit
5cfc670ada
@ -501,28 +501,28 @@ class LocalTrade():
|
|||||||
profit = 0
|
profit = 0
|
||||||
idx = -1
|
idx = -1
|
||||||
while sell_amount:
|
while sell_amount:
|
||||||
border = orders[idx]
|
b_order = orders[idx]
|
||||||
buy_amount = border.filled or border.amount
|
buy_amount = b_order.filled or b_order.amount
|
||||||
buy_rate = border.average or border.price
|
buy_rate = b_order.average or b_order.price
|
||||||
if sell_amount < buy_amount:
|
if sell_amount < buy_amount:
|
||||||
amount = sell_amount
|
amount = sell_amount
|
||||||
else:
|
else:
|
||||||
if len(orders) == 1 and sell_amount == buy_amount:
|
if len(orders) == 1 and sell_amount == self.amount:
|
||||||
self.close(safe_value_fallback(order, 'average', 'price'))
|
self.close(safe_value_fallback(order, 'average', 'price'))
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
return
|
return
|
||||||
border.is_realized = True
|
b_order.is_realized = True
|
||||||
self.update_order(border)
|
self.update_order(b_order)
|
||||||
idx -= 1
|
idx -= 1
|
||||||
amount = buy_amount
|
amount = buy_amount
|
||||||
sell_amount -= amount
|
sell_amount -= amount
|
||||||
profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
profit += self.calc_profit2(buy_rate, sell_rate, amount)
|
||||||
border2 = orders[idx]
|
b_order2 = orders[idx]
|
||||||
if not border.is_realized:
|
if not b_order.is_realized:
|
||||||
border2.filled -= amount
|
b_order2.filled -= amount
|
||||||
amount2 = border2.filled or border2.amount
|
amount2 = b_order2.filled or b_order2.amount
|
||||||
border2.average = (border2.average * amount2 - profit) / amount2
|
b_order2.average = (b_order2.average * amount2 - profit) / amount2
|
||||||
self.update_order(border2)
|
self.update_order(b_order2)
|
||||||
Order.query.session.commit()
|
Order.query.session.commit()
|
||||||
self.recalc_trade_from_orders()
|
self.recalc_trade_from_orders()
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
|
Loading…
Reference in New Issue
Block a user