Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement forex python #225

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e973ac1
Add CSV Read for Forex Prices
macanudo527 Mar 4, 2024
f20656b
Add Documentation on How to Save CSV Files
macanudo527 Mar 4, 2024
6ad1f1f
Fix Formatting
macanudo527 Mar 4, 2024
120fe35
Add Tests for Forex CSV
Mar 4, 2024
176a314
Fix Spacing (modified by Black)
Mar 11, 2024
bb22fa1
Add Tests for New CCXT Pair Converter
May 13, 2024
dc2fdf2
Fix Bug in MappedGraph
May 13, 2024
948c456
Add Frankfurter API as default Forex Pricing Provider
May 13, 2024
8e86400
Move Tests for Exchange Rate Hosts Forex Plugin
May 13, 2024
2c84e42
Add ExchangeRateHosts Forex Plugin
May 13, 2024
19544c3
Add Test for CCXT fiat rates from CSV plugin
May 13, 2024
68810c5
Add CCXT fiat from CSV Plugin
May 13, 2024
5b3aa5c
Blacken Pandas.pyi
May 13, 2024
f2522be
Make Compatible with Other PR
May 13, 2024
de95ed2
Delete Gzip encoding due to Bug
May 13, 2024
c165d3f
Fix String Concatenation Bug
May 13, 2024
8546089
Merge branch 'main' into implement_forex_python
macanudo527 May 13, 2024
c329140
Merge branch 'main' into implement_forex_python
macanudo527 May 16, 2024
1484add
Add Docs for Forex Plugins
macanudo527 May 16, 2024
5995e02
Update Google File Id
May 24, 2024
498f35d
Make Logger Protected
macanudo527 May 24, 2024
fe722cf
Fix cache_modifier in exchangerate_host
May 24, 2024
66c0a38
Remove CCXT specific methods from abstract_pair_converter
May 27, 2024
bde959b
Squash Zeroing Out Bug
macanudo527 May 28, 2024
a2199d4
Fix Pylint Error
macanudo527 May 28, 2024
22d5af8
Fix Forex Bug
May 29, 2024
d778b89
Revise Tests for Pruning
Jun 10, 2024
cc4be9c
Revise Kraken Plugin to output week candles that start on Monday
Jun 10, 2024
234c884
Add Timezone Info to Datetime
Jun 10, 2024
c4774c0
Add __str__ to MappedGraph
Jun 10, 2024
3377c26
Add Pruning to MappedGraph
Jun 10, 2024
626053e
Add SWEAT coin to Assets
Jun 10, 2024
3cc860e
Add Skip if to and from Assets are Equal
Jun 10, 2024
8df6d0c
Add Pruning to abstract_ccxt_pair_converter_plugin
Jun 10, 2024
d1a7395
Fix pylint and mypy bugs
Jun 10, 2024
3a3dc3d
Relocate pylint disable comments
macanudo527 Jun 11, 2024
aa39c83
Restore copyright date
Jun 11, 2024
1fb4ffe
Fix Documentation
Jun 11, 2024
b2344da
Change the Name of CCXT Pair converter plugin
Jun 11, 2024
c846e7f
Add Kraken URL
Jun 11, 2024
508dc43
Rename dict variable
Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 47 additions & 3 deletions docs/configuration_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ Initialize this plugin section as follows:
[dali.plugin.pair_converter.ccxt</em>]
historical_price_type = <em>&lt;historical_price_type&gt;</em>
default_exchange = <em>&lt;default_exchange&gt;</em>
fiat_access_key = <em>&lt;fiat_access_key&gt;</em>
fiat_priority = <em>&lt;fiat_priority&gt;</em>
untradeable_assets = <em>&lt;untradeable_assets&gt;</em>
aliases = <em>&lt;untradeable_assets&gt;</em>
Expand All @@ -485,7 +484,6 @@ aliases = <em>&lt;untradeable_assets&gt;</em>
Where:
* `<historical_price_type>` is one of `open`, `high`, `low`, `close`, `nearest`. When DaLi downloads historical market data, it captures a `bar` of data surrounding the timestamp of the transaction. Each bar has a starting timestamp, an ending timestamp, and OHLC prices. You can choose which price to select for price lookups. The open, high, low, and close prices are self-explanatory. The `nearest` price is either the open price or the close price of the bar depending on whether the transaction time is nearer the bar starting time or the bar ending time.
* `default_exchange` is an optional string for the name of an exchange to use if the exchange listed in a transaction is not currently supported by the CCXT plugin. If no default is set, Kraken(US) is used. If you would like an exchange added please open an issue. The current available exchanges are "Binance.com", "Gate", "Huobi" and "Kraken". Please note that the Binance.com API is not accessible from the US, Canada, Netherlands, and other [prohibited countries](https://www.binance.com/en/legal/list-of-prohibited-countries).
* `fiat_access_key` is an optional access key that can be obtained from [Exchangerate.host](https://exchangerate.host/). It is required for any fiat conversions, which are typically required if the base fiat is other than USD.
* `fiat_priority` is an optional list of strings in JSON format (e.g. `["_1stpriority_", "_2ndpriority_"...]`) that ranks the priority of fiat in the routing system. If no `fiat_priority` is given, the default priority is USD, JPY, KRW, EUR, GBP, AUD, which is based on the volume of the fiat market paired with BTC (ie. BTC/USD has the highest worldwide volume, then BTC/JPY, etc.).
* `untradeable_assets` is a comma separated list of assets that have no market, yet. These are typically assets that are farmed or given away as a part of promotion before a market is available to price them and CCXT can not automatically assign a price. If you get the error "The asset XXX or XXX is missing from graph" and the asset is untradeable, adding the untradeable asset to this list will resolve it.
* `aliases` is a list of aliases separated by semicolons. Each alias has 4 properties: exchange, from asset, to asset, factor. `exchange` is the name of the exchange if the alias is specific or `UNIVERSAL` if you want it applied to all exchanges. The current exchanges recognized by the CCXT plugin are "Binance.com", "Binance US", "Bitfinex", "Coinbase Pro", "Gate", "Huobi", "Kraken", "Okex", "Pionex" and "Upbit". `from asset` and `to asset` are the ISO codes in all caps of the assets you want to make an alias for. Finally, `factor` is the price factor for the alias (e.g. "1" if it is one to one). Here are some examples:
Expand All @@ -506,7 +504,7 @@ Then, it will route the price through a fiat conversion to get the final price:
3. EUR -> CHF

Be aware that:
* Exchange rates for fiat transactions are based on the daily rate and not minute or hourly rates.
* The CCXT plugin makes use of the default forex exchange API, Frankfurter, which provides daily rates from the European Central Bank. Rates for bank holidays and weekends are taken from the previous trading day, so if a rate is requested for Saturday, the Friday rate will be used. Two other plugins are also available for forex - one that makes use of Exchangerate.host free plan and requires a fiat_access_key and another plugin that makes use of a CSV file for forex rates.
* If a market for the conversion exists on the exchange where the asset was purchased, no routing takes place. The plugin retrieves the price for the time period.
* The router uses the exchange listed in the transaction data to build the graph to calculate the route. If no exchange is listed, the current default is Kraken(US).
* `fiat_priority` determines what fiat the router will attempt to route through first while trying to find a path to your quote asset.
Expand All @@ -528,6 +526,49 @@ Accuracy will improve once new CSV data is released, which is typically 2 weeks
##### Note on Unified CSV File
The unified CSV file is a CSV file that contains all the candles for all the assets on the Kraken exchange. It is used to retrieve the price for the transaction if the transaction is older than the latest quarter. The plugin will prompt you to download the unified CSV file if it is needed for the transaction. It is 4 GB as of April 2024. You can also manually download the file from the <!-- markdown-link-check-disable -->[Kraken Exchange](https://support.kraken.com/hc/en-us/articles/360047124832-Downloadable-historical-OHLCVT-Open-High-Low-Close-Volume-Trades-data)<!-- markdown-link-check-enable --> and put it in `.dali_cache/kraken/csv/`.

### CCXT Exchangerate Host
This plugin is based on the CCXT Python library. It uses the Exchangerate.host API for forex rates.

Initialize this plugin section as follows:
<pre>
[dali.plugin.pair_converter.ccxt</em>]
historical_price_type = <em>&lt;historical_price_type&gt;</em>
default_exchange = <em>&lt;default_exchange&gt;</em>
fiat_access_key = <em>&lt;fiat_access_key&gt;</em>
fiat_priority = <em>&lt;fiat_priority&gt;</em>
untradeable_assets = <em>&lt;untradeable_assets&gt;</em>
aliases = <em>&lt;untradeable_assets&gt;</em>
</pre>

Where:
* `fiat_access_key` is an optional access key that can be obtained from [Exchangerate.host](https://exchangerate.host/). It is required for any fiat conversions, which are typically required if the base fiat is other than USD.
* For other parameters see the [CCXT plugin](#ccxt) section above.

## CCXT Fiat from CSV
This plugin is based on the CCXT Python library. It uses CSV files for forex rates.

Initialize this plugin section as follows:
<pre>
[dali.plugin.pair_converter.ccxt</em>]
historical_price_type = <em>&lt;historical_price_type&gt;</em>
default_exchange = <em>&lt;default_exchange&gt;</em>
fiat_priority = <em>&lt;fiat_priority&gt;</em>
untradeable_assets = <em>&lt;untradeable_assets&gt;</em>
aliases = <em>&lt;untradeable_assets&gt;</em>
</pre>

Check the [CCXT plugin](#ccxt) section above for more information on the parameters.

#### Note on Forex CSV file

If you do not want to use Exchangerate.host or the Frankfurter API for Forex prices, you can use CSV files by saving them to the folder `.dali_cache/forex`. The files must be in the format of quote_asset_base_asset.csv (e.g. USD_JPY.csv). The format should be Time, high, low, open, close, volume. Like the below example:
macanudo527 marked this conversation as resolved.
Show resolved Hide resolved

Time |Open |High |Low |Close |Volume
-------------------|------|------|------|------|------
2008-02-22 00:00:00|210.45|215.45|211.56|213.45|8900

Historical CSV Files are available from several places on the web for free. [Forexsb.com](https://forexsb.com/historical-forex-data) is a good source. Currently only 1 day candles are supported. One row per day a rate is needed is required. For example, if you want to use the [official yearly rates from the IRS](https://www.irs.gov/individuals/international-taxpayers/yearly-average-currency-exchange-rates), you will need to copy and paste the same rate for all days of the calendar year. CSV files can contain multiple years of rates.
macanudo527 marked this conversation as resolved.
Show resolved Hide resolved

### Binance Locked CCXT
This plugin makes use of the CCXT plugin, but locks all routes to Binance.com.

Expand All @@ -549,6 +590,7 @@ Be aware that:
* The router only uses Binance.com and the fiat exchange rates to build the graph to calculate the route.
* `fiat_priority` determines what fiat the router will attempt to route through first while trying to find a path to your quote asset.
* Binance.com might not be available in certain territories.
* All locked plugins make use of the default forex exchange API, Frankfurter, which provides daily rates from the European Central Bank. Rates for bank holidays and weekends are taken from the previous trading day, so if a rate is requested for Saturday, the Friday rate will be used.


### Coinbase Pro Locked CCXT
Expand All @@ -571,6 +613,7 @@ Be aware that:
* Exchange rates for fiat transactions are based on the daily rate and not minute or hourly rates.
* The router only uses Coinbase Pro and the fiat exchange rates to build the graph to calculate the route.
* `fiat_priority` determines what fiat the router will attempt to route through first while trying to find a path to your quote asset.
* All locked plugins make use of the default forex exchange API, Frankfurter, which provides daily rates from the European Central Bank. Rates for bank holidays and weekends are taken from the previous trading day, so if a rate is requested for Saturday, the Friday rate will be used.


### Kraken Locked CCXT
Expand All @@ -595,6 +638,7 @@ Be aware that:
* Exchange rates for fiat transactions are based on the daily rate and not minute or hourly rates.
* The router only uses Kraken and the fiat exchange rates to build the graph to calculate the route.
* `fiat_priority` determines what fiat the router will attempt to route through first while trying to find a path to your quote asset.
* All locked plugins make use of the default forex exchange API, Frankfurter, which provides daily rates from the European Central Bank. Rates for bank holidays and weekends are taken from the previous trading day, so if a rate is requested for Saturday, the Friday rate will be used.


### Historic Crypto
Expand Down
2 changes: 2 additions & 0 deletions input/EUR_USD.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time,Open,High,Low,Close,Volume
2020-04-04 00:00:00,1.0847,1.0847,1.0847,1.0847,0
21 changes: 21 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ disallow_any_expr = False
disallow_any_explicit = False
disallow_any_expr = False

[mypy-dali.abstract_ccxt_pair_converter_plugin]
disallow_any_explicit = False
disallow_any_expr = False

[mypy-dali.abstract_pair_converter_plugin]
disallow_any_explicit = False
disallow_any_expr = False
Expand Down Expand Up @@ -94,6 +98,14 @@ disallow_any_explicit = False
disallow_any_expr = False
disallow_any_explicit = False

[mypy-dali.plugin.pair_converter.ccxt_exchangerate_host]
disallow_any_expr = False
disallow_any_explicit = False

[mypy-dali.plugin.pair_converter.ccxt_fiat_from_csv]
disallow_any_expr = False
disallow_any_explicit = False

[mypy-dali.plugin.pair_converter.csv.kraken]
disallow_any_expr = False
disallow_any_explicit = False
Expand Down Expand Up @@ -181,6 +193,15 @@ disallow_any_explicit = False
disallow_any_expr = False
disallow_any_decorated = False

[mypy-test_plugin_ccxt_exchangerate_host]
disallow_any_explicit = False
disallow_any_expr = False
disallow_any_decorated = False

[mypy-test_plugin_ccxt_fiat_from_csv]
disallow_any_explicit = False
disallow_any_expr = False

[mypy-test_mapped_graph]
disallow_any_explicit = False
disallow_any_expr = False