Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/account/trades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def build_entry

def create_entry_params
params.require(:account_entry).permit(
:account_id, :date, :amount, :currency, :qty, :price, :ticker, :type, :transfer_account_id
:account_id, :date, :amount, :currency, :qty, :price, :ticker, :manual_ticker, :type, :transfer_account_id
).tap do |params|
account_id = params.delete(:account_id)
params[:account] = Current.family.accounts.find(account_id)
Expand Down
5 changes: 3 additions & 2 deletions app/models/account/trade_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Account::TradeBuilder
include ActiveModel::Model

attr_accessor :account, :date, :amount, :currency, :qty,
:price, :ticker, :type, :transfer_account_id
:price, :ticker, :manual_ticker, :type, :transfer_account_id

attr_reader :buildable

Expand Down Expand Up @@ -110,8 +110,9 @@ def family
account.family
end

# Users can either look up a ticker from our provider (Synth) or enter a manual, "offline" ticker (that we won't fetch prices for)
def security
ticker_symbol, exchange_operating_mic = ticker.split("|")
ticker_symbol, exchange_operating_mic = ticker.present? ? ticker.split("|") : [ manual_ticker, nil ]

Security.find_or_create_by(ticker: ticker_symbol, exchange_operating_mic: exchange_operating_mic) do |s|
FetchSecurityInfoJob.perform_later(s.id)
Expand Down
5 changes: 5 additions & 0 deletions app/models/security.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Security < ApplicationRecord
include Providable

before_save :upcase_ticker

has_many :trades, dependent: :nullify, class_name: "Account::Trade"
Expand All @@ -9,6 +10,10 @@ class Security < ApplicationRecord
validates :ticker, uniqueness: { scope: :exchange_operating_mic, case_sensitive: false }

class << self
def provider
security_prices_provider
end

def search(query)
security_prices_provider.search_securities(
query: query[:search],
Expand Down
15 changes: 12 additions & 3 deletions app/views/account/trades/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@
}} %>

<% if %w[buy sell].include?(type) %>
<div class="form-field combobox">
<%= form.combobox :ticker, securities_path(country_code: Current.family.country), label: t(".holding"), placeholder: t(".ticker_placeholder"), required: true %>
</div>
<% if Security.provider.present? %>
<div class="form-field combobox">
<%= form.combobox :ticker,
securities_path(country_code: Current.family.country),
name_when_new: "account_entry[manual_ticker]",
label: t(".holding"),
placeholder: t(".ticker_placeholder"),
required: true %>
</div>
<% else %>
<%= form.text_field :manual_ticker, label: "Ticker", placeholder: "AAPL", required: true %>
<% end %>
<% end %>

<%= form.date_field :date, label: true, value: Date.current, required: true %>
Expand Down