Update readme
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Steven Polley 2023-11-13 15:37:40 -07:00
parent feaa07e251
commit 1328310dbd
1 changed files with 34 additions and 0 deletions

View File

@ -10,6 +10,40 @@ It syncs your balance like magic!
[logo]: https://deadbeef.codes/steven/ynab-portfolio-monitor/raw/branch/main/example-image.png "It syncs your balance like magic!"
### Architecture
#### Main Package
Each account provider / integration is defined in its own package and adheres to the interface specified in accountProviders.go. When the program starts, init() inside main.go attempts to configure all providers, and uses providers where configuration succeeds and ignores providers if configuration fails (eg: missing environment variable or config file). init() will run again if SIGHUP is received to reload configuration.
The main() program loop refreshes data every 6 hours by looping through each configured provider and calling AccountProvider.GetBalances(). This returns a slice of balances, and a slice of YNAB account IDs. The index position of the balance slice maps with the index of the YNAB account ID slice. This allows a single provider to provide multiple balances for different YNAB accounts depending on the provider's configuration (eg: if you have multiple accounts at your broker). We loop through the balance slice and update each YNAB account balance with the value. Finally, sleep for 6 hours before doing it again.
#### Provider Packages
Provider packages are used for any integration and are found in their own sub directories. Providers must adhere to the interface speficied in accountProviders.go.
```golang
// AccountProvider is the base set of requirements to be implemented for any integration
type AccountProvider interface {
Name() string // Returns the name of the provider
Configure() error // Configures the provider for first use - if an error is returned the provider is not used
GetBalances() ([]int, []string, error) // A slice of balances, and an index mapped slice of ynab account IDs this provider handles is returned
}
```
By convention, these methods are implemented in a file called providerImpl.go in each of the provider packages.
The following providers are currently available:
* bitcoin
* questrade
* staticjsonFinnhub
* staticjsonYahooFinance
#### YNAB Package
This is a special package used for messaging to and from YNAB, instead of adhering to the AccountProvider interface, it exposes multiple public methods for use in the Main package's business logic.
### Example docker-compose.yml
The values below are examples only, and show how to configure the Questrade and Bitcoin providers. With these providers, you can configure as many account pairings as you want using environment variables in a continuous series starting from 0 as shown below. Two example Questrade accounts are configured ending in _0 and _1 but a third can be added by adding account numbers/ID with _2. See the respective README.md files inside the provider directories for more details.