-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Stock filter #1376
Stock filter #1376
Changes from all commits
f50bccb
e8004ea
1b5caf6
d9945db
f4ba65d
bd9007f
80f7e7b
4c5d102
f478dea
7b55929
2ce5b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ def create_entry | |
| end | ||
|
|
||
| def security | ||
| return Security.find(ticker) if ticker.match?(/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i) | ||
| Security.find_or_create_by(ticker: ticker) | ||
|
Comment on lines
+34
to
35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Shpigford @zachgoll you might want to have some additional processing here. Because you're returning search results on company names (in addition to ticker symbols), and also allowing free-text entry, people might enter e.g. "Apple". They'll see that the combobox returned an equivalent result, and blur the combobox without selecting anything. At that point the combobox will think they meant to enter the literal string "Apple", and not "AAPL". I think that'll result in a Security with ticker "Apple" being created globally. But I haven't taken the time to really understand this builder class yet. Might not be a problem in practice, just wanted to point that out.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a tricky one because for self-hosters who won't have the securities loaded yet, we'd still need to support the free-text entry. That said, I think @Shpigford is working on a slightly different data model for securities + prices right now that may make it so we can be more strict with this input—i.e. only allowing IDs to be passed to the input's value and throwing a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That new data model solution sounds good! If and when you switch to that, changing the combobox to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @josefarias awesome, will do. Thanks for the heads up! |
||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <div class="flex items-center"> | ||
| <%= image_tag("https://logo.synthfinance.com/ticker/#{tickers&.ticker}", class: "rounded-full h-8 w-8 inline-block mr-2") %> | ||
| <div class="flex flex-col"> | ||
| <span class="text-sm font-medium"><%= tickers&.name.presence || tickers&.ticker %></span> | ||
| <span class="text-xs text-gray-500"><%= "#{tickers&.ticker} (#{tickers&.exchange_acronym})" %></span> | ||
| </div> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <%= async_combobox_options @securities, | ||
| render_in: { partial: "account/trades/tickers" }, | ||
| next_page: @pagy.next %> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class AddSearchVectorToSecurities < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :securities, :search_vector, :virtual, type: :tsvector, as: "setweight(to_tsvector('simple', coalesce(ticker, '')), 'B') || to_tsvector('simple', coalesce(name, ''))", stored: true | ||
| add_index :securities, :search_vector, using: :gin | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| aapl: | ||
| ticker: AAPL | ||
| name: Apple | ||
| exchange_mic: XNAS | ||
|
|
||
| msft: | ||
| ticker: MSFT | ||
| name: Microsoft | ||
| exchange_mic: XNAS |
Uh oh!
There was an error while loading. Please reload this page.