Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Record CoinSpot buys as cash out and sells as cash in (#4985)

Rudy Mizrahi Celeklibadd9cf095b5
diff --git a/app/models/coinspot_account/processor.rb b/app/models/coinspot_account/processor.rb
index 7b386b491d..16c749d8a8 100644
--- a/app/models/coinspot_account/processor.rb
+++ b/app/models/coinspot_account/processor.rb
@@ -115,7 +115,7 @@ class CoinspotAccount::Processor
date = parse_date!(order["solddate"] || order["created"], "order")
type = order_type
signed_quantity = type == "sell" ? -quantity.abs : quantity.abs
- amount_aud = type == "sell" ? total_aud.abs : -total_aud.abs
+ amount_aud = type == "sell" ? -total_aud.abs : total_aud.abs
amount, = convert_from_aud(amount_aud, date: date)
price = trade_price(amount: amount, quantity: quantity, fallback_rate: rate, date: date)
diff --git a/test/models/coinspot_account/processor_test.rb b/test/models/coinspot_account/processor_test.rb
index 6e04d39650..220feede3a 100644
--- a/test/models/coinspot_account/processor_test.rb
+++ b/test/models/coinspot_account/processor_test.rb
@@ -68,13 +68,15 @@ class CoinspotAccount::ProcessorTest < ActiveSupport::TestCase
assert_equal true, result[:success], result.inspect
buy = @account.entries.find_by!(external_id: "coinspot_order_buy_BTC_2026-01-02_buy-1", source: "coinspot")
- assert_equal(-100.to_d, buy.amount)
+ # Sure records a buy as cash leaving the account (positive) and a sell as
+ # cash arriving (negative), the same way the AUD withdrawal and deposit are.
+ assert_equal 100.to_d, buy.amount
assert_equal 0.001.to_d, buy.trade.qty
assert_equal 100_000.to_d, buy.trade.price
assert_equal "Buy", buy.trade.investment_activity_label
sell = @account.entries.find_by!(external_id: "coinspot_order_sell_BTC_2026-01-03_sell-1", source: "coinspot")
- assert_equal 220.to_d, sell.amount
+ assert_equal(-220.to_d, sell.amount)
assert_equal(-0.002.to_d, sell.trade.qty)
assert_equal "Sell", sell.trade.investment_activity_label