-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for grouping by liquidity and fix max deviation reporting
- Loading branch information
1 parent
9a17ad2
commit 47a58d1
Showing
6 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package snapshot | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/MicroFish91/portfolio-instruments-api/api/constants" | ||
) | ||
|
||
func (s *PostgresSnapshotStore) GroupByLiquidity(ctx context.Context, userId, snapId int) (float64, error) { | ||
c, cancel := context.WithTimeout(ctx, constants.TIMEOUT_MEDIUM) | ||
defer cancel() | ||
|
||
row := s.db.QueryRow( | ||
c, | ||
` | ||
select | ||
SUM(snapshots_values.total) AS liquid_total | ||
from | ||
snapshots_values | ||
inner join | ||
accounts | ||
on | ||
snapshots_values.account_id = accounts.account_id | ||
inner join | ||
holdings | ||
on | ||
snapshots_values.holding_id = holdings.holding_id | ||
where | ||
snapshots_values.user_id = $1 | ||
and snapshots_values.snap_id = $2 | ||
and accounts.tax_shelter = 'TAXABLE' | ||
and holdings.asset_category = 'CASH' | ||
`, | ||
userId, snapId, | ||
) | ||
|
||
var liquid_total float64 | ||
err := row.Scan( | ||
&liquid_total, | ||
) | ||
|
||
if err != nil { | ||
return 0, err | ||
} | ||
return liquid_total, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters