Support futures (#845)
* Support futures * Upgrade yahoo-finance2 to version 2.3.2 * Update changelog
This commit is contained in:
parent
4dc76817ce
commit
04044f8720
@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added support for commodities (via futures)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Upgraded `yahoo-finance2` from version `2.3.1` to `2.3.2`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Fixed the import validation for numbers equal 0
|
- Fixed the import validation for numbers equal 0
|
||||||
|
@ -20,10 +20,7 @@ import Big from 'big.js';
|
|||||||
import { countries } from 'countries-list';
|
import { countries } from 'countries-list';
|
||||||
import { addDays, format, isSameDay } from 'date-fns';
|
import { addDays, format, isSameDay } from 'date-fns';
|
||||||
import yahooFinance from 'yahoo-finance2';
|
import yahooFinance from 'yahoo-finance2';
|
||||||
import type {
|
import type { Price } from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-iface';
|
||||||
Price,
|
|
||||||
QuoteSummaryResult
|
|
||||||
} from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-iface';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class YahooFinanceService implements DataProviderInterface {
|
export class YahooFinanceService implements DataProviderInterface {
|
||||||
@ -92,7 +89,12 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
response.assetSubClass = assetSubClass;
|
response.assetSubClass = assetSubClass;
|
||||||
response.currency = assetProfile.price.currency;
|
response.currency = assetProfile.price.currency;
|
||||||
response.dataSource = this.getName();
|
response.dataSource = this.getName();
|
||||||
response.name = this.formatName(assetProfile);
|
response.name = this.formatName({
|
||||||
|
longName: assetProfile.price.longName,
|
||||||
|
quoteType: assetProfile.price.quoteType,
|
||||||
|
shortName: assetProfile.price.shortName,
|
||||||
|
symbol: assetProfile.price.symbol
|
||||||
|
});
|
||||||
response.symbol = aSymbol;
|
response.symbol = aSymbol;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -247,7 +249,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
|
|
||||||
const quotes = searchResult.quotes
|
const quotes = searchResult.quotes
|
||||||
.filter((quote) => {
|
.filter((quote) => {
|
||||||
// filter out undefined symbols
|
// Filter out undefined symbols
|
||||||
return quote.symbol;
|
return quote.symbol;
|
||||||
})
|
})
|
||||||
.filter(({ quoteType, symbol }) => {
|
.filter(({ quoteType, symbol }) => {
|
||||||
@ -256,7 +258,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
this.cryptocurrencyService.isCryptocurrency(
|
this.cryptocurrencyService.isCryptocurrency(
|
||||||
symbol.replace(new RegExp(`-${baseCurrency}$`), baseCurrency)
|
symbol.replace(new RegExp(`-${baseCurrency}$`), baseCurrency)
|
||||||
)) ||
|
)) ||
|
||||||
['EQUITY', 'ETF', 'MUTUALFUND'].includes(quoteType)
|
['EQUITY', 'ETF', 'FUTURE', 'MUTUALFUND'].includes(quoteType)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.filter(({ quoteType, symbol }) => {
|
.filter(({ quoteType, symbol }) => {
|
||||||
@ -264,6 +266,9 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
// Only allow cryptocurrencies in base currency to avoid having redundancy in the database.
|
// Only allow cryptocurrencies in base currency to avoid having redundancy in the database.
|
||||||
// Transactions need to be converted manually to the base currency before
|
// Transactions need to be converted manually to the base currency before
|
||||||
return symbol.includes(baseCurrency);
|
return symbol.includes(baseCurrency);
|
||||||
|
} else if (quoteType === 'FUTURE') {
|
||||||
|
// Allow GC=F, but not MGC=F
|
||||||
|
return symbol.length === 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -288,7 +293,12 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
symbol,
|
symbol,
|
||||||
currency: marketDataItem.currency,
|
currency: marketDataItem.currency,
|
||||||
dataSource: this.getName(),
|
dataSource: this.getName(),
|
||||||
name: quote?.longname || quote?.shortname || symbol
|
name: this.formatName({
|
||||||
|
longName: quote.longname,
|
||||||
|
quoteType: quote.quoteType,
|
||||||
|
shortName: quote.shortname,
|
||||||
|
symbol: quote.symbol
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -298,8 +308,18 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
return { items };
|
return { items };
|
||||||
}
|
}
|
||||||
|
|
||||||
private formatName(aAssetProfile: QuoteSummaryResult) {
|
private formatName({
|
||||||
let name = aAssetProfile.price.longName;
|
longName,
|
||||||
|
quoteType,
|
||||||
|
shortName,
|
||||||
|
symbol
|
||||||
|
}: {
|
||||||
|
longName: Price['longName'];
|
||||||
|
quoteType: Price['quoteType'];
|
||||||
|
shortName: Price['shortName'];
|
||||||
|
symbol: Price['symbol'];
|
||||||
|
}) {
|
||||||
|
let name = longName;
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
name = name.replace('iShares ETF (CH) - ', '');
|
name = name.replace('iShares ETF (CH) - ', '');
|
||||||
@ -314,7 +334,12 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
name = name.replace('Xtrackers (IE) Plc - ', '');
|
name = name.replace('Xtrackers (IE) Plc - ', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return name || aAssetProfile.price.shortName || aAssetProfile.price.symbol;
|
if (quoteType === 'FUTURE') {
|
||||||
|
// "Gold Jun 22" -> "Gold"
|
||||||
|
name = shortName?.slice(0, -6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return name || shortName || symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseAssetClass(aPrice: Price): {
|
private parseAssetClass(aPrice: Price): {
|
||||||
@ -337,6 +362,10 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
assetClass = AssetClass.EQUITY;
|
assetClass = AssetClass.EQUITY;
|
||||||
assetSubClass = AssetSubClass.ETF;
|
assetSubClass = AssetSubClass.ETF;
|
||||||
break;
|
break;
|
||||||
|
case 'future':
|
||||||
|
assetClass = AssetClass.COMMODITY;
|
||||||
|
assetSubClass = AssetSubClass.COMMODITY;
|
||||||
|
break;
|
||||||
case 'mutualfund':
|
case 'mutualfund':
|
||||||
assetClass = AssetClass.EQUITY;
|
assetClass = AssetClass.EQUITY;
|
||||||
assetSubClass = AssetSubClass.MUTUALFUND;
|
assetSubClass = AssetSubClass.MUTUALFUND;
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
"tslib": "2.0.0",
|
"tslib": "2.0.0",
|
||||||
"twitter-api-v2": "1.10.3",
|
"twitter-api-v2": "1.10.3",
|
||||||
"uuid": "8.3.2",
|
"uuid": "8.3.2",
|
||||||
"yahoo-finance2": "2.3.1",
|
"yahoo-finance2": "2.3.2",
|
||||||
"zone.js": "0.11.4"
|
"zone.js": "0.11.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -18836,10 +18836,10 @@ y18n@^5.0.5:
|
|||||||
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
|
||||||
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
|
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
|
||||||
|
|
||||||
yahoo-finance2@2.3.1:
|
yahoo-finance2@2.3.2:
|
||||||
version "2.3.1"
|
version "2.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/yahoo-finance2/-/yahoo-finance2-2.3.1.tgz#d2cffbef78f6974e4e6a40487cc08ab133dc9fc5"
|
resolved "https://registry.yarnpkg.com/yahoo-finance2/-/yahoo-finance2-2.3.2.tgz#3643b5e14f752b1d5546427d760d515401ac2ac7"
|
||||||
integrity sha512-QTXiiWgfrpVbSylchBgLqESZz+8+SyyDSqntjfZHxMIHa6d14xq+biNNDIeYd5SylcZ9Vt4zLmZXHN7EdLM1pA==
|
integrity sha512-xOBaamD/mXN9ruc3TBOEhEIhP/N+efWo/wQf2PyYtB6N68iSGZVDt+4vdJN7ra+iCVq7FnSHTDH3K4Cvqy63lQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
ajv "8.10.0"
|
ajv "8.10.0"
|
||||||
ajv-formats "2.1.1"
|
ajv-formats "2.1.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user