From 305e24831080305d5b84de9a7bbedf30019e6c9f Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sun, 3 Dec 2023 02:41:03 +0100 Subject: [PATCH] Fix wrong share balance if sell order canceled --- db/market.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/market.go b/db/market.go index 1aee810..f8ad4a8 100644 --- a/db/market.go +++ b/db/market.go @@ -302,7 +302,8 @@ func (db *DB) FetchUserBalance(tx *sql.Tx, ctx context.Context, marketId int, pu "FROM orders o " + "LEFT JOIN invoices i ON i.id = o.invoice_id " + "JOIN shares s ON s.id = o.share_id " + - "WHERE o.pubkey = $1 AND s.market_id = $2 AND ( (o.side = 'BUY' AND i.confirmed_at IS NOT NULL AND o.order_id IS NOT NULL) OR o.side = 'SELL' ) " + + "WHERE o.pubkey = $1 AND s.market_id = $2 AND o.deleted_at IS NULL " + + "AND ( (o.side = 'BUY' AND i.confirmed_at IS NOT NULL AND o.order_id IS NOT NULL) OR o.side = 'SELL' ) " + "GROUP BY o.pubkey, s.description" rows, err := tx.QueryContext(ctx, query, pubkey, marketId) if err != nil {