Bugfix/fix symbol conversion for yahoo finance (#405)

* Fix symbol conversion for Yahoo Finance

* Update changelog
pull/406/head
Thomas Kaul 3 years ago committed by GitHub
parent d3c6788ad5
commit de94494aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed an issue in the symbol conversion for _Yahoo Finance_ (for a cryptocurrency with the same code as a currency)
## 1.58.0 - 02.10.2021
### Changed

@ -262,16 +262,21 @@ export const convertFromYahooFinanceSymbol = (aYahooFinanceSymbol: string) => {
* SOL1USD -> SOL1-USD
*/
export const convertToYahooFinanceSymbol = (aSymbol: string) => {
if (isCurrency(aSymbol)) {
if (isCrypto(aSymbol) || isCrypto(aSymbol.replace('1', ''))) {
if (
(aSymbol.includes('CHF') ||
aSymbol.includes('EUR') ||
aSymbol.includes('USD')) &&
aSymbol.length >= 6
) {
if (isCurrency(aSymbol.substring(0, aSymbol.length - 3))) {
return `${aSymbol}=X`;
} else if (isCrypto(aSymbol) || isCrypto(aSymbol.replace('1', ''))) {
// Add a dash before the last three characters
// BTCUSD -> BTC-USD
// DOGEUSD -> DOGE-USD
// SOL1USD -> SOL1-USD
return aSymbol.replace('USD', '-USD');
}
return `${aSymbol}=X`;
}
return aSymbol;

@ -1,3 +1,4 @@
import * as currencies from '@dinero.js/currencies';
import { getDate, getMonth, getYear, parse, subDays } from 'date-fns';
import { ghostfolioScraperApiSymbolPrefix } from './config';
@ -85,12 +86,7 @@ export function isCrypto(aSymbol = '') {
}
export function isCurrency(aSymbol = '') {
return (
(aSymbol.includes('CHF') ||
aSymbol.includes('EUR') ||
aSymbol.includes('USD')) &&
aSymbol.length >= 6
);
return currencies[aSymbol];
}
export function isGhostfolioScraperApiSymbol(aSymbol = '') {

@ -58,6 +58,7 @@
"@angular/platform-browser-dynamic": "12.2.4",
"@angular/router": "12.2.4",
"@codewithdan/observable-store": "2.2.11",
"@dinero.js/currencies": "2.0.0-alpha.8",
"@nestjs/common": "7.6.18",
"@nestjs/config": "0.6.3",
"@nestjs/core": "7.6.18",

@ -1681,6 +1681,11 @@
debug "^3.1.0"
lodash.once "^4.1.1"
"@dinero.js/currencies@2.0.0-alpha.8":
version "2.0.0-alpha.8"
resolved "https://registry.yarnpkg.com/@dinero.js/currencies/-/currencies-2.0.0-alpha.8.tgz#aa02a04ce3685a9b06a7ce12f8c924726386c3fd"
integrity sha512-zApiqtuuPwjiM9LJA5/kNcT48VSHRiz2/mktkXjIpfxrJKzthXybUAgEenExIH6dYhLDgVmsLQZtZFOsdYl0Ag==
"@discoveryjs/json-ext@0.5.3":
version "0.5.3"
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.3.tgz#90420f9f9c6d3987f176a19a7d8e764271a2f55d"

Loading…
Cancel
Save