Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.

Commit 9138bd2

Browse files
authored
Allow offline trade tickers (#1925)
1 parent 882857f commit 9138bd2

4 files changed

Lines changed: 21 additions & 6 deletions

File tree

app/controllers/account/trades_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def build_entry
1010

1111
def create_entry_params
1212
params.require(:account_entry).permit(
13-
:account_id, :date, :amount, :currency, :qty, :price, :ticker, :type, :transfer_account_id
13+
:account_id, :date, :amount, :currency, :qty, :price, :ticker, :manual_ticker, :type, :transfer_account_id
1414
).tap do |params|
1515
account_id = params.delete(:account_id)
1616
params[:account] = Current.family.accounts.find(account_id)

app/models/account/trade_builder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Account::TradeBuilder
22
include ActiveModel::Model
33

44
attr_accessor :account, :date, :amount, :currency, :qty,
5-
:price, :ticker, :type, :transfer_account_id
5+
:price, :ticker, :manual_ticker, :type, :transfer_account_id
66

77
attr_reader :buildable
88

@@ -110,8 +110,9 @@ def family
110110
account.family
111111
end
112112

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

116117
Security.find_or_create_by(ticker: ticker_symbol, exchange_operating_mic: exchange_operating_mic) do |s|
117118
FetchSecurityInfoJob.perform_later(s.id)

app/models/security.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Security < ApplicationRecord
22
include Providable
3+
34
before_save :upcase_ticker
45

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

1112
class << self
13+
def provider
14+
security_prices_provider
15+
end
16+
1217
def search(query)
1318
security_prices_provider.search_securities(
1419
query: query[:search],

app/views/account/trades/_form.html.erb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@
2727
}} %>
2828

2929
<% if %w[buy sell].include?(type) %>
30-
<div class="form-field combobox">
31-
<%= form.combobox :ticker, securities_path(country_code: Current.family.country), label: t(".holding"), placeholder: t(".ticker_placeholder"), required: true %>
32-
</div>
30+
<% if Security.provider.present? %>
31+
<div class="form-field combobox">
32+
<%= form.combobox :ticker,
33+
securities_path(country_code: Current.family.country),
34+
name_when_new: "account_entry[manual_ticker]",
35+
label: t(".holding"),
36+
placeholder: t(".ticker_placeholder"),
37+
required: true %>
38+
</div>
39+
<% else %>
40+
<%= form.text_field :manual_ticker, label: "Ticker", placeholder: "AAPL", required: true %>
41+
<% end %>
3342
<% end %>
3443

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

0 commit comments

Comments
 (0)