mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-07 06:25:19 +02:00
Integrate investment analytics app
This commit is contained in:
parent
13ec520618
commit
deb228a55e
6 changed files with 38 additions and 11 deletions
|
@ -3,3 +3,7 @@ SELF_HOSTED=false
|
||||||
|
|
||||||
# Enable Synth market data (careful, this will use your API credits)
|
# Enable Synth market data (careful, this will use your API credits)
|
||||||
SYNTH_API_KEY=yourapikeyhere
|
SYNTH_API_KEY=yourapikeyhere
|
||||||
|
|
||||||
|
# Enable the Investment Analytics app and configure FMP API access
|
||||||
|
ENABLE_INVESTMENT_ANALYTICS_APP=false
|
||||||
|
FMP_API_KEY=yourfmpapikeyhere
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# app/apps/investment_analytics/services/investment_analytics/fmp_provider.rb
|
# app/apps/investment_analytics/services/investment_analytics/fmp_provider.rb
|
||||||
|
|
||||||
module InvestmentAnalytics
|
module InvestmentAnalytics
|
||||||
class FmpProvider
|
require Rails.root.join("app", "models", "provider")
|
||||||
include Provider::Base
|
class FmpProvider < ::Provider
|
||||||
|
|
||||||
BASE_URL = "https://financialmodelingprep.com/api/v3"
|
BASE_URL = "https://financialmodelingprep.com/api/v3"
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,17 @@ class Provider::Registry
|
||||||
validates :concept, inclusion: { in: CONCEPTS }
|
validates :concept, inclusion: { in: CONCEPTS }
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@@additional_providers = {}
|
||||||
|
|
||||||
def for_concept(concept)
|
def for_concept(concept)
|
||||||
new(concept.to_sym)
|
new(concept.to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_provider(name, provider_class)
|
||||||
|
@@additional_providers[name.to_sym] = provider_class
|
||||||
|
define_singleton_method(name) { provider_class.new }
|
||||||
|
end
|
||||||
|
|
||||||
def get_provider(name)
|
def get_provider(name)
|
||||||
send(name)
|
send(name)
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
|
@ -98,7 +105,7 @@ class Provider::Registry
|
||||||
when :llm
|
when :llm
|
||||||
%i[openai]
|
%i[openai]
|
||||||
else
|
else
|
||||||
%i[synth plaid_us plaid_eu github openai]
|
%i[synth plaid_us plaid_eu github openai] + self.class.class_variable_get(:@@additional_providers).keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
# Ensure the InvestmentAnalytics module is loaded
|
# Ensure the InvestmentAnalytics module is loaded
|
||||||
require_relative '../../app/apps/investment_analytics/investment_analytics'
|
require_relative '../../app/apps/investment_analytics/investment_analytics'
|
||||||
|
require Rails.root.join('app', 'models', 'provider')
|
||||||
|
require Rails.root.join('app', 'models', 'provider', 'registry')
|
||||||
|
|
||||||
# Ensure the FmpProvider class is loaded
|
# Ensure the FmpProvider class is loaded
|
||||||
require_relative '../../app/apps/investment_analytics/services/investment_analytics/fmp_provider'
|
require_relative '../../app/apps/investment_analytics/services/investment_analytics/fmp_provider'
|
||||||
|
|
|
@ -262,14 +262,6 @@ Rails.application.routes.draw do
|
||||||
get "privacy", to: redirect("https://maybefinance.com/privacy")
|
get "privacy", to: redirect("https://maybefinance.com/privacy")
|
||||||
get "terms", to: redirect("https://maybefinance.com/tos")
|
get "terms", to: redirect("https://maybefinance.com/tos")
|
||||||
|
|
||||||
namespace :investment_analytics do
|
|
||||||
resources :dashboards, only: [:index] do
|
|
||||||
collection do
|
|
||||||
get :portfolio_summary
|
|
||||||
get :dividend_forecast
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Defines the root path route ("/")
|
# Defines the root path route ("/")
|
||||||
root "pages#dashboard"
|
root "pages#dashboard"
|
||||||
|
|
22
test/models/provider/fmp_provider_test.rb
Normal file
22
test/models/provider/fmp_provider_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
require "test_helper"
|
||||||
|
require "ostruct"
|
||||||
|
|
||||||
|
class InvestmentAnalytics::FmpProviderTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
@provider = InvestmentAnalytics::FmpProvider.new(api_key: "test")
|
||||||
|
end
|
||||||
|
|
||||||
|
test "quote returns parsed data" do
|
||||||
|
response = OpenStruct.new(success?: true, body: [{ price: 10 }.to_json])
|
||||||
|
HTTParty.expects(:get).returns(response)
|
||||||
|
|
||||||
|
result = @provider.quote("AAPL")
|
||||||
|
assert_equal({"price" => 10}, result)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "error responses raise provider error" do
|
||||||
|
response = OpenStruct.new(success?: false, code: 404, body: "not found")
|
||||||
|
assert_raises(Provider::Error) { @provider.send(:handle_response, response) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue