mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 16:19:40 +02:00
Groundwork for security info (#1396)
* Groundwork for security info * Lint
This commit is contained in:
parent
5e2b932648
commit
e7f09e6f71
4 changed files with 44 additions and 1 deletions
20
app/jobs/fetch_security_info_job.rb
Normal file
20
app/jobs/fetch_security_info_job.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
class FetchSecurityInfoJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(security_id)
|
||||||
|
return unless Security.security_info_provider.present?
|
||||||
|
|
||||||
|
security = Security.find(security_id)
|
||||||
|
|
||||||
|
security_info_response = Security.security_info_provider.fetch_security_info(
|
||||||
|
ticker: security.ticker,
|
||||||
|
mic_code: security.exchange_mic
|
||||||
|
)
|
||||||
|
|
||||||
|
security.update(
|
||||||
|
name: security_info_response.info.dig("name"),
|
||||||
|
exchange_acronym: security_info_response.info.dig("exchange", "acronym"),
|
||||||
|
country_code: security_info_response.info.dig("exchange", "country_code")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
|
@ -33,7 +33,11 @@ class Account::TradeBuilder < Account::EntryBuilder
|
||||||
def security
|
def security
|
||||||
ticker_symbol, exchange_mic = ticker.split("|")
|
ticker_symbol, exchange_mic = ticker.split("|")
|
||||||
|
|
||||||
Security.find_or_create_by(ticker: ticker_symbol, exchange_mic: exchange_mic)
|
security = Security.find_or_create_by(ticker: ticker_symbol, exchange_mic: exchange_mic)
|
||||||
|
|
||||||
|
FetchSecurityInfoJob.perform_later(security.id)
|
||||||
|
|
||||||
|
security
|
||||||
end
|
end
|
||||||
|
|
||||||
def amount
|
def amount
|
||||||
|
|
|
@ -10,6 +10,10 @@ module Providable
|
||||||
synth_provider
|
synth_provider
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def security_info_provider
|
||||||
|
synth_provider
|
||||||
|
end
|
||||||
|
|
||||||
def exchange_rates_provider
|
def exchange_rates_provider
|
||||||
synth_provider
|
synth_provider
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ class Provider::Synth
|
||||||
response = client.get("#{base_url}/user")
|
response = client.get("#{base_url}/user")
|
||||||
JSON.parse(response.body).dig("id").present?
|
JSON.parse(response.body).dig("id").present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def usage
|
def usage
|
||||||
response = client.get("#{base_url}/user")
|
response = client.get("#{base_url}/user")
|
||||||
|
|
||||||
|
@ -147,6 +148,19 @@ class Provider::Synth
|
||||||
raw_response: response
|
raw_response: response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_security_info(ticker:, mic_code:)
|
||||||
|
response = client.get("#{base_url}/tickers/#{ticker}") do |req|
|
||||||
|
req.params["mic_code"] = mic_code
|
||||||
|
end
|
||||||
|
|
||||||
|
parsed = JSON.parse(response.body)
|
||||||
|
|
||||||
|
SecurityInfoResponse.new \
|
||||||
|
info: parsed.dig("data"),
|
||||||
|
success?: true,
|
||||||
|
raw_response: response
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :api_key
|
attr_reader :api_key
|
||||||
|
@ -156,6 +170,7 @@ class Provider::Synth
|
||||||
ExchangeRatesResponse = Struct.new :rates, :success?, :error, :raw_response, keyword_init: true
|
ExchangeRatesResponse = Struct.new :rates, :success?, :error, :raw_response, keyword_init: true
|
||||||
UsageResponse = Struct.new :used, :limit, :utilization, :plan, :success?, :error, :raw_response, keyword_init: true
|
UsageResponse = Struct.new :used, :limit, :utilization, :plan, :success?, :error, :raw_response, keyword_init: true
|
||||||
SearchSecuritiesResponse = Struct.new :securities, :success?, :error, :raw_response, keyword_init: true
|
SearchSecuritiesResponse = Struct.new :securities, :success?, :error, :raw_response, keyword_init: true
|
||||||
|
SecurityInfoResponse = Struct.new :info, :success?, :error, :raw_response, keyword_init: true
|
||||||
|
|
||||||
def base_url
|
def base_url
|
||||||
"https://api.synthfinance.com"
|
"https://api.synthfinance.com"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue