From 24b36683b467d25753bf25e192ea5016cb9ef61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20=C5=A0iljak?= <462445+alensiljak@users.noreply.github.com> Date: Sun, 25 May 2025 16:51:46 +0200 Subject: [PATCH 1/2] Brief instructions for creating a source --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 937d533..12a92df 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,28 @@ The following price sources are available: More price sources can be found at [awesome-beancount.com](https://awesome-beancount.com/#price-sources) website. +## Creating a custom price source + +To create a price source, create a package (i.e. `my_package`) with a module (i.e. `my_module`) that contains a class which inherits from the beanprice Source class: + +```python +from beanprice import source + +class Source(source.Source): + def get_latest_price(self, ticker) -> source.SourcePrice | None: + pass + + def get_historical_price(self, ticker, time): + pass +``` + +Then use your price source in the commodities + +```beancount +1900-01-01 commodity XYZ + price: "AUD:my_package.my_module/XYZ" +``` + ## Testing Run tests: From e3e50522cbc61e90313ead9ae206f2b2c72da0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alen=20=C5=A0iljak?= <462445+alensiljak@users.noreply.github.com> Date: Sun, 25 May 2025 16:54:48 +0200 Subject: [PATCH 2/2] minor expansion --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12a92df..f31d6ff 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ More price sources can be found at [awesome-beancount.com](https://awesome-beanc ## Creating a custom price source -To create a price source, create a package (i.e. `my_package`) with a module (i.e. `my_module`) that contains a class which inherits from the beanprice Source class: +To create a price source, create a package (i.e. `my_package`) with a module (i.e. `my_module`) that contains the Source class which inherits from the `beanprice.Source` class: ```python from beanprice import source @@ -86,6 +86,7 @@ class Source(source.Source): def get_historical_price(self, ticker, time): pass ``` +Implement the logic for fetching the prices. At a minimum, the `get_latest_price()` is required. Then use your price source in the commodities @@ -93,6 +94,7 @@ Then use your price source in the commodities 1900-01-01 commodity XYZ price: "AUD:my_package.my_module/XYZ" ``` +`AUD` just being an example of a currency specification. ## Testing