Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f9a1bafa0 | |||
| 6f72a03ecf | |||
| 5b8e4c634e | |||
| 70c3f7162e | |||
| cb9199431a | |||
| cba9fe1e7b | |||
| baa49e77eb | |||
| b015462e50 | |||
| c9f1fc1bea | |||
| 1177886271 | |||
| 0e1c56dd18 | |||
| eefe237dff | |||
| 8d4e004177 | |||
| 1c63e2b856 | |||
| 3040cbf49a | |||
| 1a124a2571 | |||
| 26c8c3f3b9 | |||
| 50d814ebf6 | |||
| 7fc20876dd | |||
| 183108400e | |||
| 3055d34979 | |||
| 747f5f5f42 | |||
| 4db9409b94 | |||
| 8693bb29ca | |||
| 524d8ca41d | |||
| 3c77eca689 | |||
| 307f74b1d9 | |||
| 0c29393f3b | |||
| af3726cb91 | |||
| 0d40fd92f0 | |||
| 0f55d84355 | |||
| eafa889827 | |||
| 60cd880c2e | |||
| ea8de69863 | |||
| 11ef26e878 |
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
APP_NAME=Investbrain
|
APP_NAME=Investbrain
|
||||||
APP_ENV=production
|
APP_ENV=production
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=false
|
APP_DEBUG=true
|
||||||
APP_TIMEZONE=UTC
|
APP_TIMEZONE=UTC
|
||||||
APP_PORT=8000
|
APP_PORT=8000
|
||||||
APP_URL="http://localhost:${APP_PORT}"
|
APP_URL="http://localhost:${APP_PORT}"
|
||||||
|
|||||||
@@ -6,9 +6,21 @@ Investbrain is a smart open-source investment tracker that helps you manage, tra
|
|||||||
|
|
||||||
<p align="center"><a href="https://investbra.in" target="_blank"><img src="https://raw.githubusercontent.com/investbrainapp/investbrain/main/screenshot.png" width="100%" alt="Investbrain Screenshot"></a></p>
|
<p align="center"><a href="https://investbra.in" target="_blank"><img src="https://raw.githubusercontent.com/investbrainapp/investbrain/main/screenshot.png" width="100%" alt="Investbrain Screenshot"></a></p>
|
||||||
|
|
||||||
|
## Table of contents
|
||||||
|
- [Under the hood](#under-the-hood)
|
||||||
|
- [Install (self hosting)](#self-hosting)
|
||||||
|
- [Chat with your holdings](#chat-with-your-holdings)
|
||||||
|
- [Market data providers](#market-data-providers)
|
||||||
|
- [Import / Export](#import--export)
|
||||||
|
- [Configuration](#configuration)
|
||||||
|
- [Updating](#updating)
|
||||||
|
- [Command line utilities](#command-line-utilities)
|
||||||
|
- [Troubleshooting](#troubleshooting)
|
||||||
|
- [Testing](#testing)
|
||||||
|
|
||||||
## Under the hood
|
## Under the hood
|
||||||
|
|
||||||
Investbrain is a Laravel PHP web application that leverages Livewire and Tailwind for its frontend. Most databases should work, including MySQL and SQLite. Out of the box, we feature three market data providers: [Yahoo Finance](https://finance.yahoo.com/), [Finnhub](https://finnhub.io/pricing-stock-api-market-data), and [Alpha Vantage](https://www.alphavantage.co/support/). But we also offer an extensible market data provider interface for intrepid developers to create their own! We also offer an integration with OpenAI's LLMs for our ["chat with your holdings"](#chat-with-your-holdings) capability. Finally, of course we have robust support for i18n, a11y, and dark mode.
|
Investbrain is a Laravel PHP web application that leverages Livewire and Tailwind for its frontend. Most databases should work, including MySQL and SQLite. Out of the box, we feature three market data providers: [Yahoo Finance](https://finance.yahoo.com/), [Finnhub](https://finnhub.io/pricing-stock-api-market-data), and [Alpha Vantage](https://www.alphavantage.co/support/). But we also offer an extensible market data provider interface for intrepid developers to create their own! We also offer an integration with OpenAI for our ["chat with your holdings"](#chat-with-your-holdings) capability. Finally, of course we have robust support for i18n, a11y, and dark mode.
|
||||||
|
|
||||||
## Self hosting
|
## Self hosting
|
||||||
|
|
||||||
@@ -44,9 +56,11 @@ Congrats! You've just installed Investbrain!
|
|||||||
|
|
||||||
Investbrain offers an AI powered chat assistant that is grounded on *your* investments. This enables you to use AI as a thought partner when making investment decisions.
|
Investbrain offers an AI powered chat assistant that is grounded on *your* investments. This enables you to use AI as a thought partner when making investment decisions.
|
||||||
|
|
||||||
When self-hosting, you can enable the chat assstant by configuring your OpenAI Secret Key and Organization ID in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file. Navigate to OpenAI to [create your keys](https://platform.openai.com/api-keys).
|
When self-hosting, you can enable the chat assistant by configuring your OpenAI Secret Key and Organization ID in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file. Navigate to OpenAI to [create your keys](https://platform.openai.com/api-keys).
|
||||||
|
|
||||||
Always keep in mind the limitations of large language models. When in doubt, consult a licensed investment advisor.
|
If you are self-hosting your own large language models ("LLMs") that expose an OpenAI compatible API (e.g. [Ollama](https://ollama.com/blog/openai-compatibility)), you can update the `OPENAI_BASE_URI` configuration to your self-hosted instance. Ensure you also update the `OPENAI_MODEL` to an available model.
|
||||||
|
|
||||||
|
Always keep in mind the limitations of LLMs. When in doubt, consult a licensed investment advisor.
|
||||||
|
|
||||||
## Market data providers
|
## Market data providers
|
||||||
|
|
||||||
@@ -93,6 +107,18 @@ MARKET_DATA_PROVIDER=yahoo,alphavantage,custom_provider
|
|||||||
|
|
||||||
Feel free to submit a PR with any custom providers you create.
|
Feel free to submit a PR with any custom providers you create.
|
||||||
|
|
||||||
|
## Import / Export
|
||||||
|
|
||||||
|
Investbrain includes a convenient feature which allows you to import and export portfolios and transaction data.
|
||||||
|
|
||||||
|
### Import
|
||||||
|
|
||||||
|
Imports are "upserted" to the database. If the record does not already exist in the database, the record will be created. However, when a portfolio or transaction exists (the record's ID matches an existing record), the record will be updated. This way, you can simultaneously create new records, but also bulk update records.
|
||||||
|
|
||||||
|
### Export
|
||||||
|
|
||||||
|
Exporting your portfolios and transactions is a convenient way to back-up your Investbrain data. It is also a convenient way to maintain portability of *your* data.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
There are several optional configurations available when installing using the recommended [Docker method](#self-hosting). These options are configurable using an environment file. Changes can be made in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file before installation.
|
There are several optional configurations available when installing using the recommended [Docker method](#self-hosting). These options are configurable using an environment file. Changes can be made in your [.env](https://github.com/investbrainapp/investbrain/blob/main/.env.example) file before installation.
|
||||||
@@ -109,11 +135,12 @@ There are several optional configurations available when installing using the re
|
|||||||
| AI_CHAT_ENABLED | Whether to enable AI chat features | `false` |
|
| AI_CHAT_ENABLED | Whether to enable AI chat features | `false` |
|
||||||
| OPENAI_API_KEY | OpenAI secret key (required for AI chat) | `null` |
|
| OPENAI_API_KEY | OpenAI secret key (required for AI chat) | `null` |
|
||||||
| OPENAI_ORGANIZATION | OpenAI org id (required for AI chat) | `null` |
|
| OPENAI_ORGANIZATION | OpenAI org id (required for AI chat) | `null` |
|
||||||
|
| OPENAI_MODEL | The selected LLM used for AI chat | gpt-4o |
|
||||||
|
| OPENAI_BASE_URI | The URI for your self-hosted LLM | api.openai.com/v1 |
|
||||||
| DAILY_CHANGE_TIME | The time of day to capture daily change | 23:00 |
|
| DAILY_CHANGE_TIME | The time of day to capture daily change | 23:00 |
|
||||||
| REGISTRATION_ENABLED | Whether to enable registration of new users | `true` |
|
| REGISTRATION_ENABLED | Whether to enable registration of new users | `true` |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
> Note: These options affect the [docker-compose.yml](https://github.com/investbrainapp/investbrain/blob/main/docker-compose.yml) file, so if you decide to make any changes to these default configurations, you'll have to restart the Docker containers before your changes take effect.
|
> Note: These options affect the [docker-compose.yml](https://github.com/investbrainapp/investbrain/blob/main/docker-compose.yml) file, so if you decide to make any changes to these default configurations, you'll have to restart the Docker containers before your changes take effect.
|
||||||
|
|
||||||
## Updating
|
## Updating
|
||||||
@@ -159,6 +186,31 @@ Just to be safe, we recommend backing up your portfolios before using these comm
|
|||||||
| sync:daily-change | Re-calculates daily snapshots of your portfolio's daily performance. Useful to fill in gaps in your portfolio charts. (Note: this is an extremely resource intensive query.) |
|
| sync:daily-change | Re-calculates daily snapshots of your portfolio's daily performance. Useful to fill in gaps in your portfolio charts. (Note: this is an extremely resource intensive query.) |
|
||||||
| sync:holdings | Re-calculates performance of holdings with related transactions (i.e. dividends, realized gains, etc). |
|
| sync:holdings | Re-calculates performance of holdings with related transactions (i.e. dividends, realized gains, etc). |
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
If you are facing issues with Investbrain, it can be handy to monitor the application's logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec -it investbrain-app cat storage/logs/laravel.log
|
||||||
|
```
|
||||||
|
or you can live monitor logs using `tail`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker exec -it investbrain-app tail -f storage/logs/laravel.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Common issues
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
**<summary>Market data not refreshing on fresh install</summary>**
|
||||||
|
|
||||||
|
If you're unable to refresh market data out of the box (i.e. your market data provider is set to Yahoo), there is a chance Yahoo is being blocked by a firewall or adblocker. Pihole is known to block `fc.yahoo.com` which is the domain used to query Yahoo.
|
||||||
|
|
||||||
|
Once you whitelist `fc.yahoo.com` in pihole, your market data should begin populating!
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
Investbrain has a robus PHPUnit test suite that creates an in-memory SQLite database and runs any queued jobs synchronously using Laravel's array driver. You can run the entire Investbrain test suite from within the Docker container by running:
|
Investbrain has a robus PHPUnit test suite that creates an in-memory SQLite database and runs any queued jobs synchronously using Laravel's array driver. You can run the entire Investbrain test suite from within the Docker container by running:
|
||||||
@@ -185,7 +237,7 @@ We ask that you be kind and polite when interacting with the Investbrain communi
|
|||||||
|
|
||||||
## Security Vulnerabilities
|
## Security Vulnerabilities
|
||||||
|
|
||||||
If you discover a security vulnerability within Investbrain, please create an issue in the [Github repository](https://github.com/investbrainapp/investbrain). All security vulnerabilities will be promptly addressed.
|
If you discover a security vulnerability within Investbrain, please submit your report via [Github](https://github.com/investbrainapp/investbrain/security/advisories/new). All security vulnerabilities will be promptly addressed. We ask that you keep any suspected vulnerabilities private and confidential until they have been appropriately addressed.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
| Version | Supported |
|
||||||
|
| ------- | ------------------ |
|
||||||
|
| 1.0.x | :white_check_mark: |
|
||||||
|
| < 1.0.0 | :x: |
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you discover a security vulnerability within Investbrain, please submit your report via [Github](https://github.com/investbrainapp/investbrain/security/advisories/new). All security vulnerabilities will be promptly addressed. We ask that you keep any suspected vulnerabilities private and confidential until they have been appropriately addressed.
|
||||||
+11
-9
@@ -27,7 +27,7 @@ class Dividend extends Model
|
|||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'date' => 'datetime',
|
'date' => 'datetime',
|
||||||
'last_date' => 'datetime',
|
'last_dividend_update' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function marketData() {
|
public function marketData() {
|
||||||
@@ -50,25 +50,29 @@ class Dividend extends Model
|
|||||||
/**
|
/**
|
||||||
* Grab new dividend data
|
* Grab new dividend data
|
||||||
*
|
*
|
||||||
* @param string $symbol
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public static function refreshDividendData(string $symbol)
|
public static function refreshDividendData(string $symbol): void
|
||||||
{
|
{
|
||||||
$dividends_meta = self::where(['symbol' => $symbol])
|
$dividends_meta = self::where(['symbol' => $symbol])
|
||||||
->selectRaw('COUNT(symbol) as total_dividends')
|
->selectRaw('COUNT(symbol) as total_dividends')
|
||||||
->selectRaw('MAX(date) as last_date')
|
->selectRaw('MAX(created_at) as last_dividend_update')
|
||||||
->get()
|
->get()
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
// assume we need to populate ALL dividend data
|
// assume we need to populate ALL dividend data
|
||||||
$start_date = new \DateTime('@0');
|
$start_date = new Carbon('@0');
|
||||||
$end_date = now();
|
$end_date = now();
|
||||||
|
|
||||||
// nope, refresh forward looking only
|
// nope, refresh forward looking only
|
||||||
if ( $dividends_meta->total_dividends ) {
|
if ( $dividends_meta->total_dividends ) {
|
||||||
|
|
||||||
|
$start_date = $dividends_meta->last_dividend_update->addHours(24);
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip refresh if there's already recent data
|
||||||
|
if ($start_date->greaterThan($end_date)) {
|
||||||
|
|
||||||
$start_date = $dividends_meta->last_date->addHours(48);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get some data
|
// get some data
|
||||||
@@ -99,8 +103,6 @@ class Dividend extends Model
|
|||||||
$market_data->last_dividend_amount = $dividend_data->sortByDesc('date')->first()['dividend_amount'];
|
$market_data->last_dividend_amount = $dividend_data->sortByDesc('date')->first()['dividend_amount'];
|
||||||
$market_data->save();
|
$market_data->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $dividend_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function syncHoldings(string $symbol): void
|
public static function syncHoldings(string $symbol): void
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class Transaction extends Model
|
|||||||
|
|
||||||
public function scopeBeforeDate($query, $date)
|
public function scopeBeforeDate($query, $date)
|
||||||
{
|
{
|
||||||
return $query->whereDate('date', '<', $date);
|
return $query->whereDate('date', '<=', $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeMyTransactions()
|
public function scopeMyTransactions()
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Laravel\Jetstream\Features;
|
||||||
use App\Actions\Jetstream\DeleteUser;
|
use App\Actions\Jetstream\DeleteUser;
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Laravel\Jetstream\Jetstream;
|
use Laravel\Jetstream\Jetstream;
|
||||||
|
|
||||||
@@ -26,6 +29,13 @@ class JetstreamServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Jetstream::deleteUsersUsing(DeleteUser::class);
|
Jetstream::deleteUsersUsing(DeleteUser::class);
|
||||||
|
|
||||||
|
if ( config('investbrain.self_hosted', false) ) {
|
||||||
|
|
||||||
|
Config::set(
|
||||||
|
'jetstream.features',
|
||||||
|
array_keys(Arr::except(array_values(config('jetstream.features')), Features::termsAndPrivacyPolicy()))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class QuantityValidationRule implements ValidationRule
|
|||||||
|
|
||||||
$maxQuantity = $purchase_qty - $sales_qty;
|
$maxQuantity = $purchase_qty - $sales_qty;
|
||||||
|
|
||||||
if ($value > $maxQuantity) {
|
if (round($value, 3) > round($maxQuantity, 3)) {
|
||||||
$fail(__('The quantity must not be greater than the available quantity.'));
|
$fail(__('The quantity must not be greater than the available quantity.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
"livewire/livewire": "^3.5",
|
"livewire/livewire": "^3.5",
|
||||||
"livewire/volt": "^1.6",
|
"livewire/volt": "^1.6",
|
||||||
"maatwebsite/excel": "^3.1",
|
"maatwebsite/excel": "^3.1",
|
||||||
"openai-php/laravel": "^0.10.2",
|
"openai-php/client": "^0.10.3",
|
||||||
"predis/predis": "^2.2",
|
"predis/predis": "^2.2",
|
||||||
"robsontenorio/mary": "^1.35",
|
"robsontenorio/mary": "^1.35",
|
||||||
"scheb/yahoo-finance-api": "^4.11",
|
"scheb/yahoo-finance-api": "^4.11",
|
||||||
|
|||||||
Generated
+460
-488
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -143,7 +143,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'inject_morph_markers' => true,
|
'inject_morph_markers' => false,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|---------------------------------------------------------------------------
|
|---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ return [
|
|||||||
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
|
'request_timeout' => env('OPENAI_REQUEST_TIMEOUT', 30),
|
||||||
|
|
||||||
//
|
//
|
||||||
|
'base_uri' => env('OPENAI_BASE_URI', 'api.openai.com/v1'),
|
||||||
'model' => env('OPENAI_MODEL', 'gpt-4o'),
|
'model' => env('OPENAI_MODEL', 'gpt-4o'),
|
||||||
];
|
];
|
||||||
|
|||||||
Generated
+25
-21
@@ -11,12 +11,12 @@
|
|||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
"autoprefixer": "^10.4.19",
|
"autoprefixer": "^10.4.19",
|
||||||
"axios": "^1.6.4",
|
"axios": "^1.7.4",
|
||||||
"daisyui": "^4.12.10",
|
"daisyui": "^4.12.10",
|
||||||
"laravel-vite-plugin": "^1.0",
|
"laravel-vite-plugin": "^1.0",
|
||||||
"postcss": "^8.4.40",
|
"postcss": "^8.4.40",
|
||||||
"tailwindcss": "^3.4.7",
|
"tailwindcss": "^3.4.7",
|
||||||
"vite": "^5.0"
|
"vite": "^5.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@alloc/quick-lru": {
|
"node_modules/@alloc/quick-lru": {
|
||||||
@@ -862,9 +862,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
"node_modules/axios": {
|
||||||
"version": "1.7.3",
|
"version": "1.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz",
|
||||||
"integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==",
|
"integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"follow-redirects": "^1.15.6",
|
"follow-redirects": "^1.15.6",
|
||||||
@@ -1721,9 +1721,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/picocolors": {
|
"node_modules/picocolors": {
|
||||||
"version": "1.0.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||||
"integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==",
|
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/picomatch": {
|
"node_modules/picomatch": {
|
||||||
@@ -1757,9 +1757,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/postcss": {
|
"node_modules/postcss": {
|
||||||
"version": "8.4.40",
|
"version": "8.4.47",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.40.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.47.tgz",
|
||||||
"integrity": "sha512-YF2kKIUzAofPMpfH6hOi2cGnv/HrUlfucspc7pDyvv7kGdqXrfj8SCl/t8owkEgKEuu8ZcRjSOxFxVLqwChZ2Q==",
|
"integrity": "sha512-56rxCq7G/XfB4EkXq9Egn5GCqugWvDFjafDOThIdMBsI15iqPqR5r15TfSr1YPYeEI19YeaXMCbY6u88Y76GLQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -1777,8 +1777,8 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nanoid": "^3.3.7",
|
"nanoid": "^3.3.7",
|
||||||
"picocolors": "^1.0.1",
|
"picocolors": "^1.1.0",
|
||||||
"source-map-js": "^1.2.0"
|
"source-map-js": "^1.2.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "^10 || ^12 || >=14"
|
"node": "^10 || ^12 || >=14"
|
||||||
@@ -2090,9 +2090,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/source-map-js": {
|
"node_modules/source-map-js": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||||
"integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==",
|
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
@@ -2437,14 +2437,14 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/vite": {
|
"node_modules/vite": {
|
||||||
"version": "5.3.5",
|
"version": "5.4.10",
|
||||||
"resolved": "https://registry.npmjs.org/vite/-/vite-5.3.5.tgz",
|
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.10.tgz",
|
||||||
"integrity": "sha512-MdjglKR6AQXQb9JGiS7Rc2wC6uMjcm7Go/NHNO63EwiJXfuk9PgqiP/n5IDJCziMkfw9n4Ubp7lttNwz+8ZVKA==",
|
"integrity": "sha512-1hvaPshuPUtxeQ0hsVH3Mud0ZanOLwVTneA1EgbAM5LhaZEqyPWGRQ7BtaMvUrTDeEaC8pxtj6a6jku3x4z6SQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.21.3",
|
"esbuild": "^0.21.3",
|
||||||
"postcss": "^8.4.39",
|
"postcss": "^8.4.43",
|
||||||
"rollup": "^4.13.0"
|
"rollup": "^4.20.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"vite": "bin/vite.js"
|
"vite": "bin/vite.js"
|
||||||
@@ -2463,6 +2463,7 @@
|
|||||||
"less": "*",
|
"less": "*",
|
||||||
"lightningcss": "^1.21.0",
|
"lightningcss": "^1.21.0",
|
||||||
"sass": "*",
|
"sass": "*",
|
||||||
|
"sass-embedded": "*",
|
||||||
"stylus": "*",
|
"stylus": "*",
|
||||||
"sugarss": "*",
|
"sugarss": "*",
|
||||||
"terser": "^5.4.0"
|
"terser": "^5.4.0"
|
||||||
@@ -2480,6 +2481,9 @@
|
|||||||
"sass": {
|
"sass": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
"sass-embedded": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"stylus": {
|
"stylus": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-2
@@ -9,12 +9,12 @@
|
|||||||
"@tailwindcss/forms": "^0.5.7",
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
"@tailwindcss/typography": "^0.5.10",
|
||||||
"autoprefixer": "^10.4.19",
|
"autoprefixer": "^10.4.19",
|
||||||
"axios": "^1.6.4",
|
"axios": "^1.7.4",
|
||||||
"daisyui": "^4.12.10",
|
"daisyui": "^4.12.10",
|
||||||
"laravel-vite-plugin": "^1.0",
|
"laravel-vite-plugin": "^1.0",
|
||||||
"postcss": "^8.4.40",
|
"postcss": "^8.4.40",
|
||||||
"tailwindcss": "^3.4.7",
|
"tailwindcss": "^3.4.7",
|
||||||
"vite": "^5.0"
|
"vite": "^5.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"apexcharts": "^3.51.0"
|
"apexcharts": "^3.51.0"
|
||||||
|
|||||||
@@ -63,7 +63,9 @@
|
|||||||
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-3">
|
<x-ib-card title="{{ __('Recent activity') }}" class="md:col-span-3">
|
||||||
|
|
||||||
@livewire('transactions-list', [
|
@livewire('transactions-list', [
|
||||||
'transactions' => $user->transactions
|
'transactions' => $user->transactions,
|
||||||
|
'showPortfolio' => true,
|
||||||
|
'paginate' => false
|
||||||
])
|
])
|
||||||
|
|
||||||
</x-ib-card>
|
</x-ib-card>
|
||||||
|
|||||||
@@ -207,7 +207,7 @@
|
|||||||
* 52 week high: {$holding->market_data->fifty_two_week_high}
|
* 52 week high: {$holding->market_data->fifty_two_week_high}
|
||||||
* Dividend yield: {$holding->market_data->dividend_yield}
|
* Dividend yield: {$holding->market_data->dividend_yield}
|
||||||
|
|
||||||
Based on this current market data, quantity owned, and average cost basis, you should determine if the {$holding->symbol} holding is making or losing money.
|
This data is current as of today's date: " . now()->format('Y-m-d') . ". Based on this current market data, quantity owned, and average cost basis, you should determine if the {$holding->symbol} holding is making or losing money.
|
||||||
|
|
||||||
Below is the question from the investor. Considering these facts, provide a concise response to the following question (give a direct response). Limit your response to no more than 75 words and consider using a common decision framework. Use github style markdown for any formatting:"
|
Below is the question from the investor. Considering these facts, provide a concise response to the following question (give a direct response). Limit your response to no more than 75 words and consider using a common decision framework. Use github style markdown for any formatting:"
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use App\Models\AiChat;
|
|||||||
use App\Models\Holding;
|
use App\Models\Holding;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Livewire\Volt\Component;
|
use Livewire\Volt\Component;
|
||||||
use OpenAI\Laravel\Facades\OpenAI;
|
use OpenAI\Factory;
|
||||||
use OpenAI\Responses\StreamResponse;
|
use OpenAI\Responses\StreamResponse;
|
||||||
|
|
||||||
new class extends Component {
|
new class extends Component {
|
||||||
@@ -67,7 +67,9 @@ new class extends Component {
|
|||||||
{
|
{
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$stream = OpenAI::chat()->createStreamed([
|
$client = $this->createOpenAiClient();
|
||||||
|
|
||||||
|
$stream = $client->chat()->createStreamed([
|
||||||
'model' => config('openai.model'),
|
'model' => config('openai.model'),
|
||||||
'messages' => [
|
'messages' => [
|
||||||
['role' => 'system', 'content' => "Today's date is "
|
['role' => 'system', 'content' => "Today's date is "
|
||||||
@@ -104,7 +106,9 @@ new class extends Component {
|
|||||||
public function generateSuggestedPrompts(): void
|
public function generateSuggestedPrompts(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$suggested_prompts = OpenAI::chat()->create([
|
$client = $this->createOpenAiClient();
|
||||||
|
|
||||||
|
$suggested_prompts = $client->chat()->create([
|
||||||
'model' => config('openai.model'),
|
'model' => config('openai.model'),
|
||||||
'response_format' => [
|
'response_format' => [
|
||||||
'type' => 'json_schema',
|
'type' => 'json_schema',
|
||||||
@@ -192,6 +196,21 @@ new class extends Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createOpenAiClient()
|
||||||
|
{
|
||||||
|
$apiKey = config('openai.api_key');
|
||||||
|
$organization = config('openai.organization');
|
||||||
|
$baseUri = config('openai.base_uri');
|
||||||
|
|
||||||
|
return OpenAI::factory()
|
||||||
|
->withApiKey($apiKey)
|
||||||
|
->withOrganization($organization)
|
||||||
|
->withHttpHeader('OpenAI-Beta', 'assistants=v2')
|
||||||
|
->withHttpClient(new \GuzzleHttp\Client(['timeout' => config('openai.request_timeout', 30)]))
|
||||||
|
->withBaseUri($baseUri)
|
||||||
|
->make();
|
||||||
|
}
|
||||||
|
|
||||||
}; ?>
|
}; ?>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ new class extends Component {
|
|||||||
'symbol' => ['required', 'string', new SymbolValidationRule],
|
'symbol' => ['required', 'string', new SymbolValidationRule],
|
||||||
'transaction_type' => 'required|string|in:BUY,SELL',
|
'transaction_type' => 'required|string|in:BUY,SELL',
|
||||||
'portfolio_id' => 'required|exists:portfolios,id',
|
'portfolio_id' => 'required|exists:portfolios,id',
|
||||||
'date' => 'required|date_format:Y-m-d',
|
'date' => ['required', 'date_format:Y-m-d', 'before_or_equal:' . now()->format('Y-m-d')],
|
||||||
'quantity' => [
|
'quantity' => [
|
||||||
'required',
|
'required',
|
||||||
'numeric',
|
'numeric',
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ new class extends Component {
|
|||||||
public ?Portfolio $portfolio;
|
public ?Portfolio $portfolio;
|
||||||
public ?Transaction $editingTransaction;
|
public ?Transaction $editingTransaction;
|
||||||
public Bool $shouldGoToHolding = true;
|
public Bool $shouldGoToHolding = true;
|
||||||
|
public Bool $showPortfolio = false;
|
||||||
|
public Bool $paginate = true;
|
||||||
|
public Int $perPage = 5;
|
||||||
|
public Int $offset = 0;
|
||||||
|
|
||||||
protected $listeners = [
|
protected $listeners = [
|
||||||
'transaction-updated' => '$refresh',
|
'transaction-updated' => '$refresh',
|
||||||
@@ -38,17 +42,23 @@ new class extends Component {
|
|||||||
return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']]));
|
return $this->redirect(route('holding.show', ['portfolio' => $holding['portfolio_id'], 'symbol' => $holding['symbol']]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateOffset($amount = 0)
|
||||||
|
{
|
||||||
|
$this->offset = $this->offset + $amount;
|
||||||
|
}
|
||||||
|
|
||||||
}; ?>
|
}; ?>
|
||||||
|
|
||||||
<div class="">
|
<div class="">
|
||||||
|
|
||||||
@foreach($transactions->sortByDesc('date')->take(10) as $transaction)
|
@foreach($transactions->sortByDesc('date')->slice($offset)->take($perPage) as $transaction)
|
||||||
|
|
||||||
<x-list-item
|
<x-list-item
|
||||||
no-separator
|
no-separator
|
||||||
:item="$transaction"
|
:item="$transaction"
|
||||||
class="cursor-pointer"
|
class="cursor-pointer"
|
||||||
x-data="{ loading: false, timeout: null }"
|
x-data="{ loading: false, timeout: null }"
|
||||||
|
:key="$transaction->id"
|
||||||
@click="
|
@click="
|
||||||
if ($wire.shouldGoToHolding) {
|
if ($wire.shouldGoToHolding) {
|
||||||
|
|
||||||
@@ -83,12 +93,44 @@ new class extends Component {
|
|||||||
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
<x-loading x-show="loading" x-cloak class="text-gray-400 ml-2" />
|
||||||
</x-slot:value>
|
</x-slot:value>
|
||||||
<x-slot:sub-value>
|
<x-slot:sub-value>
|
||||||
|
@if($showPortfolio)
|
||||||
|
<span title="{{ __('Portfolio') }}">{{ $transaction->portfolio->title }} </span>
|
||||||
|
·
|
||||||
|
@endif
|
||||||
<span title="{{ __('Transaction Date') }}">{{ $transaction->date->format('F j, Y') }} </span>
|
<span title="{{ __('Transaction Date') }}">{{ $transaction->date->format('F j, Y') }} </span>
|
||||||
</x-slot:sub-value>
|
</x-slot:sub-value>
|
||||||
</x-list-item>
|
</x-list-item>
|
||||||
|
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
@if ($paginate && count($transactions) > $perPage)
|
||||||
|
<div class="flex justify-between">
|
||||||
|
|
||||||
|
<span>
|
||||||
|
@if($offset > 0)
|
||||||
|
<x-button
|
||||||
|
class="btn btn-sm btn-ghost text-secondary"
|
||||||
|
wire:click="updateOffset(-{{ $perPage }})"
|
||||||
|
>
|
||||||
|
{!! __('pagination.previous') !!}
|
||||||
|
</x-button>
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span>
|
||||||
|
@if(count($transactions) - $offset > $offset)
|
||||||
|
<x-button
|
||||||
|
class="btn btn-sm btn-ghost text-secondary"
|
||||||
|
wire:click="updateOffset({{ $perPage }})"
|
||||||
|
>
|
||||||
|
{!! __('pagination.next') !!}
|
||||||
|
</x-button>
|
||||||
|
@endif
|
||||||
|
</span>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<x-ib-alpine-modal
|
<x-ib-alpine-modal
|
||||||
key="manage-transaction"
|
key="manage-transaction"
|
||||||
title="{{ __('Manage Transaction') }}"
|
title="{{ __('Manage Transaction') }}"
|
||||||
@@ -96,7 +138,7 @@ new class extends Component {
|
|||||||
@livewire('manage-transaction-form', [
|
@livewire('manage-transaction-form', [
|
||||||
'portfolio' => $portfolio,
|
'portfolio' => $portfolio,
|
||||||
'transaction' => $editingTransaction,
|
'transaction' => $editingTransaction,
|
||||||
], key($editingTransaction->id ?? 'new'))
|
], key($editingTransaction?->id.rand()))
|
||||||
|
|
||||||
</x-ib-alpine-modal>
|
</x-ib-alpine-modal>
|
||||||
</div>
|
</div>
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
|
|
||||||
{$formattedHoldings}
|
{$formattedHoldings}
|
||||||
|
|
||||||
Based on the current market data, quantity owned, and average cost basis, you can determine the performance of any holding.
|
This data is current as of today's date: " . now()->format('Y-m-d') . ". Based on the current market data, quantity owned, and average cost basis, you can determine the performance of any holding.
|
||||||
|
|
||||||
Below is the question from the investor. Considering these facts, provide a concise response to the following question (give a direct response). Limit your response to no more than 75 words and consider using a common decision framework. Use github style markdown for any formatting:"
|
Below is the question from the investor. Considering these facts, provide a concise response to the following question (give a direct response). Limit your response to no more than 75 words and consider using a common decision framework. Use github style markdown for any formatting:"
|
||||||
])
|
])
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@ use App\Console\Commands\{RefreshMarketData, CaptureDailyChange, RefreshDividend
|
|||||||
* This scheduled job refreshes market data from your selected data provider
|
* This scheduled job refreshes market data from your selected data provider
|
||||||
* Update the cadence with the MARKET_DATA_REFRESH key in your env file
|
* Update the cadence with the MARKET_DATA_REFRESH key in your env file
|
||||||
*/
|
*/
|
||||||
Schedule::command(RefreshMarketData::class)->everyMinute()->weekdays();
|
Schedule::command(RefreshMarketData::class)->weekdays()->everyMinute();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -20,7 +20,7 @@ Schedule::command(CaptureDailyChange::class)->dailyAt(config('investbrain.daily_
|
|||||||
*
|
*
|
||||||
* Refreshes dividend data for your holdings (and syncs new dividends to holdings)
|
* Refreshes dividend data for your holdings (and syncs new dividends to holdings)
|
||||||
*/
|
*/
|
||||||
Schedule::command(RefreshDividendData::class)->days([1, 3, 5])->weekdays();
|
Schedule::command(RefreshDividendData::class)->daily()->days([1, 3, 5]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -61,4 +61,26 @@ class DividendsTest extends TestCase
|
|||||||
$this->assertCount(3, $transactions);
|
$this->assertCount(3, $transactions);
|
||||||
$this->assertEqualsWithDelta(4.95, $dividendsReinvested * $market_data->market_value, 0.01);
|
$this->assertEqualsWithDelta(4.95, $dividendsReinvested * $market_data->market_value, 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
public function test_do_not_duplicate_recent_dividends(): void
|
||||||
|
{
|
||||||
|
$this->actingAs($user = User::factory()->create());
|
||||||
|
|
||||||
|
$portfolio = Portfolio::factory()->create();
|
||||||
|
Transaction::factory()->buy()->yearsAgo()->portfolio($portfolio->id)->symbol('ACME')->create();
|
||||||
|
|
||||||
|
$holding = Holding::query()->portfolio($portfolio->id)->symbol('ACME')->first();
|
||||||
|
|
||||||
|
Dividend::create([
|
||||||
|
'symbol' => 'ACME',
|
||||||
|
'date' => now()->subDay(2),
|
||||||
|
'dividend_amount' => .01
|
||||||
|
]);
|
||||||
|
|
||||||
|
Dividend::refreshDividendData('ACME');
|
||||||
|
|
||||||
|
$this->assertCount(1, $holding->dividends);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user