Add Interactive Brokers Provider (#1722)

* Display multi-currency holdings correctly

* Implement IBKR provider

* Fix: Use historical exchange rate for historical prices

* Add brokerage exchange rate for trades

* Sync historical balances from IBKR

* Add logos in activity history

* Fix privacy mode blur in account view

* Improve IBKR XML Flex report parser errors
This commit is contained in:
Gian-Reto Tarnutzer
2026-05-12 23:45:19 +02:00
committed by GitHub
parent 3c4c32584a
commit ce5d7dd736
81 changed files with 3838 additions and 59 deletions

View File

@@ -0,0 +1,100 @@
require "test_helper"
class IbkrItemsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
@ibkr_item = ibkr_items(:configured_item)
end
test "select_existing_account renders available ibkr accounts" do
get select_existing_account_ibkr_items_url, params: { account_id: accounts(:investment).id }
assert_response :success
assert_includes response.body, ibkr_accounts(:main_account).name
end
test "create redirects to accounts on success" do
assert_difference "IbkrItem.count", 1 do
post ibkr_items_url, params: {
ibkr_item: {
query_id: "QUERYNEW",
token: "TOKENNEW"
}
}
end
assert_redirected_to accounts_path
end
test "update redirects to accounts on success" do
patch ibkr_item_url(@ibkr_item), params: {
ibkr_item: {
query_id: "",
token: ""
}
}
assert_redirected_to accounts_path
end
test "complete_account_setup creates investment account and provider link" do
assert_difference "Account.count", 1 do
assert_difference "AccountProvider.count", 1 do
post complete_account_setup_ibkr_item_url(@ibkr_item), params: {
account_ids: [ ibkr_accounts(:main_account).id ]
}
end
end
created_account = Account.order(created_at: :desc).first
assert_equal "Investment", created_account.accountable_type
assert_equal "brokerage", created_account.accountable.subtype
assert_redirected_to accounts_path
ibkr_accounts(:main_account).reload
assert_equal created_account, ibkr_accounts(:main_account).current_account
end
test "link_existing_account links manual investment account" do
account = accounts(:investment)
assert_difference "AccountProvider.count", 1 do
post link_existing_account_ibkr_items_url, params: {
account_id: account.id,
ibkr_account_id: ibkr_accounts(:main_account).id
}
end
assert_redirected_to account_path(account)
ibkr_accounts(:main_account).reload
assert_equal account, ibkr_accounts(:main_account).current_account
end
test "link_existing_account rejects already linked ibkr account" do
original_account = accounts(:investment)
ibkr_account = ibkr_accounts(:main_account)
AccountProvider.create!(account: original_account, provider: ibkr_account)
replacement_account = Account.create!(
family: @ibkr_item.family,
owner: @user,
name: "Replacement Brokerage Account",
balance: 2500,
cash_balance: 2500,
currency: "USD",
accountable: Investment.create!(subtype: "brokerage")
)
assert_no_difference "AccountProvider.count" do
post link_existing_account_ibkr_items_url, params: {
account_id: replacement_account.id,
ibkr_account_id: ibkr_account.id
}
end
assert_redirected_to account_path(replacement_account)
assert_equal "This Interactive Brokers account is already linked.", flash[:alert]
ibkr_account.reload
assert_equal original_account, ibkr_account.current_account
end
end