Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
1.8 KB
Raw Blame
# frozen_string_literal: true

json.id trade.id
json.date trade.entry.date
json.amount trade.entry.amount_money.format
json.currency trade.currency
json.name trade.entry.name
json.notes trade.entry.notes
json.qty trade.qty
json.price trade.price_money.format
json.investment_activity_label trade.investment_activity_label
# The fee charged on the trade, formatted like price, and as an unrounded,
# locale-independent decimal string (the stored value).
json.fee trade.fee_money.format
json.fee_decimal trade.fee.to_s("F")
# The rate to the account's currency stored on the trade, for example by a
# provider that reports its own rate. The cost basis applies it to price and
# fee, from `currency` (the trade's); the cash balance applies it to `amount`,
# from amount_currency (the entry's). The two are the same unless the web form
# or PATCH changed the entry's currency, which leaves the trade's as it was.
# The rate was recorded for `currency`; the cash balance then reuses it
# unchanged for amount_currency.
# Null when the trade carries none, in which case market rates are used, and
# when both currencies are the account's.
json.exchange_rate trade.numeric_exchange_rate
json.amount_currency trade.entry.currency
json.lot_source_trade_id trade.lot_source_entry&.entryable_id

json.account do
  json.id trade.entry.account.id
  json.name trade.entry.account.name
  json.account_type trade.entry.account.accountable_type.underscore
end

if trade.security.present?
  json.security do
    json.id trade.security.id
    json.ticker trade.security.ticker
    json.name trade.security.name
  end
else
  json.security nil
end

if trade.category.present?
  json.category do
    json.id trade.category.id
    json.name trade.category.name
  end
else
  json.category nil
end

json.created_at trade.created_at.iso8601
json.updated_at trade.updated_at.iso8601