-
Notifications
You must be signed in to change notification settings - Fork 40
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
base: main
Are you sure you want to change the base?
Conversation
6811add
to
bf60891
Compare
Sounds good, but should it be a separate plugin, so that the user can decide which to use and with what priority? |
I'm wondering about how to implement that. Maybe have two different CCXT pair converters one with the REST API, and one with the importing of CSV? |
Yes, that's what I was thinking: that should give the user the most flexibility. |
@eprbell btw, I'm going to try to cherry pick and splice the code from your PR. Hopefully, I can get it all put together here soon. Should I implement this with inheritance, or by parameter that will load a particular class to handle forex processing? I'm thinking making ccxt pair converter abstract and the forex processing has to inherit from it. OR, make the REST API default, and then have another CSV class inherit and override the defaults. |
Sounds good, no worries.
I'm leaning toward making the ccxt-based converter abstract and have the two forex processing plugins inherit from it. In theory we could do something similar to the input plugins and have csv and rest subdirectories, but that would not be backward compatible, would require changes in users config files, and would make this change more complex: let's leave it as is. If needed, we'll tackle that issue as a separate change later. |
8b754be
to
9a57efb
Compare
0b2ea73
to
8aebb3c
Compare
6286ef4
to
6414ff7
Compare
6414ff7
to
19047f5
Compare
ba6864a
to
5b3aa5c
Compare
@eprbell This should fix most Forex Issues. It is lacking docs, but I thought I would let you get a peek at it. |
Sounds good: I'll take a look (the diff in Github is large so it may take some time for me to go through it). |
2c33b00
to
f2522be
Compare
785412c
to
c165d3f
Compare
I figured it would take a while. I tried to figure out a way to break down into simpler parts, but kind of just had to be done all at once. Sorry. |
e257d7e
to
fe722cf
Compare
2943ca8
to
40fcb09
Compare
40fcb09
to
a2199d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, here's a first review.
@@ -485,7 +484,7 @@ aliases = <em><untradeable_assets></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. | |||
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a spurious bullet in this bullet list (which is about ccxt pair converter plugin parameters): should it be moved elsewhere?
-------------------|------|------|------|------|------ | ||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "is needed is required"
|
||
#### 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: | |
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: |
# It appears Kraken public API is limited to around 12 calls per minute. | ||
# There also appears to be a limit of how many calls per 2 hour time period. | ||
# Being authenticated lowers this limit. | ||
_REQUEST_DELAYDICT: Dict[str, float] = {_KRAKEN: 5.1, _BITFINEX: 5.0} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion
_REQUEST_DELAY_DICT
} | ||
|
||
# If Exchangerates.host is not available or the user does not have an access key, we can use this list | ||
DEFAULT_FIAT_LIST: List[str] = ["AUD", "CAD", "CHF", "EUR", "GBP", "JPY", "NZD", "USD"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this list have the same number of elements as FIAT_PRIORITY
?
@@ -1,4 +1,4 @@ | |||
# Copyright 2022 Neal Chambers | |||
# Copyright 2024 Neal Chambers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is not new, so the date should not change.
|
||
for day in range((end_of_year - beginning_of_year).days + 1): | ||
current_day: datetime = beginning_of_year + timedelta(days=day) | ||
print(f"current_day: {current_day}, timestamp: {key.timestamp}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the logger module instead of print.
@@ -0,0 +1,120 @@ | |||
# Copyright 2024 Neal Chambers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this file live in the csv subdirectory?
@@ -62,7 +62,7 @@ | |||
_GOOGLE_DRIVE_DOWNLOAD_URL: str = "https://drive.usercontent.google.com/download" | |||
|
|||
# File ID for the unified CSV file ID. This will need to be replaced every quarter. | |||
_UNIFIED_CSV_FILE_ID: str = "16YKyFkYlvawCHv3W7WuTFzM8RYgMRWMt" | |||
_UNIFIED_CSV_FILE_ID: str = "11WtjXA9kvVYV9KDoebGV5U75dmcA3bJa" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the full URL to the file into a comment, so that people can download it manually and inspect it, if they wish to do so?
@@ -1,4 +1,4 @@ | |||
# Copyright 2022 Neal Chambers | |||
# Copyright 2024 Neal Chambers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change the date.
f390aea
to
398fb05
Compare
398fb05
to
226eb8c
Compare
What?
Fixes #224
Dependent on #223
This allows users to make use of CSV files for Forex pricing instead of rely on exchangerate.host
Testing
I have not tested this with real world data at all. This is curently WIP.