mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Allow offline trade tickers (#1925)
This commit is contained in:
parent
882857fcf0
commit
9138bd2b76
4 changed files with 21 additions and 6 deletions
|
@ -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
|
||||
|
||||
|
@ -110,8 +110,9 @@ class Account::TradeBuilder
|
|||
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)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Security < ApplicationRecord
|
||||
include Providable
|
||||
|
||||
before_save :upcase_ticker
|
||||
|
||||
has_many :trades, dependent: :nullify, class_name: "Account::Trade"
|
||||
|
@ -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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue