From 38318688b98ec94fec8253135db693d48abf957d Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 2 Dec 2023 02:56:58 +0100 Subject: [PATCH] Fix user balance query --- db/market.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/market.go b/db/market.go index 2872c66..0aa87e0 100644 --- a/db/market.go +++ b/db/market.go @@ -271,7 +271,7 @@ func (db *DB) FetchUserBalance(tx *sql.Tx, ctx context.Context, marketId int, pu "SELECT s.description, " + "SUM(CASE WHEN o.side = 'BUY' THEN o.quantity ELSE -o.quantity END) " + "FROM orders o " + - "JOIN invoices i ON i.id = o.invoice_id " + + "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' ) " + "GROUP BY o.pubkey, s.description"