diff --git a/src/__mocks__/fixtures/v3/daily.js b/src/__mocks__/fixtures/v3/daily.js index 2f3ab5c..6b6e1e1 100644 --- a/src/__mocks__/fixtures/v3/daily.js +++ b/src/__mocks__/fixtures/v3/daily.js @@ -14,11 +14,11 @@ module.exports = { }, market_capital: { name_jp: '時価総額', - unit: '百万円' + unit: '円' }, enterprise_value: { name_jp: '企業価値', - unit: '百万円' + unit: '円' }, eps_forecast: { name_jp: 'EPS(会社予想)', @@ -38,7 +38,7 @@ module.exports = { }, ebitda_forecast: { name_jp: 'EBITDA(会社予想)', - unit: '百万円' + unit: '円' }, ev_ebitda_forecast: { name_jp: 'EV/EBITDA(会社予想)', diff --git a/src/__mocks__/fixtures/v3/quarter-property.js b/src/__mocks__/fixtures/v3/quarter-property.js deleted file mode 100644 index d284384..0000000 --- a/src/__mocks__/fixtures/v3/quarter-property.js +++ /dev/null @@ -1,746 +0,0 @@ -module.exports = { - company_name: { - name_jp: '社名', - unit: 'なし' - }, - ceo_name: { - name_jp: '代表者名', - unit: 'なし' - }, - headquarters_address: { - name_jp: '所在地', - unit: 'なし' - }, - end_date: { - name_jp: '有価証券報告書の期末日', - unit: '日付' - }, - edinet_updated_date: { - name_jp: 'edinet発行日', - unit: '日付' - }, - tdnet_updated_date: { - name_jp: 'tdnet発行日', - unit: '日付' - }, - edinet_title: { - name_jp: 'edinet開示資料名', - unit: 'なし' - }, - tdnet_title: { - name_jp: 'tdnet開示資料名', - unit: 'なし' - }, - accounting_standard: { - name_jp: '会計基準', - unit: 'なし' - }, - num_of_shares: { - name_jp: '株式総数', - unit: '株' - }, - issued_share_num: { - name_jp: '発行済株式総数', - unit: '株' - }, - treasury_stock_num: { - name_jp: '自己株数', - unit: '株' - }, - assets: { - name_jp: '総資産', - unit: '百万円' - }, - current_assets: { - name_jp: '流動資産', - unit: '百万円' - }, - cash_and_deposits: { - name_jp: '現預金', - unit: '百万円' - }, - trade_receivables: { - name_jp: '売上債権', - unit: '百万円' - }, - notes_accounts_receivable: { - name_jp: '受取手形および売掛金', - unit: '百万円' - }, - notes_receivable: { - name_jp: '受取手形', - unit: '百万円' - }, - accounts_receivable: { - name_jp: '売掛金', - unit: '百万円' - }, - current_securities: { - name_jp: '有価証券', - unit: '百万円' - }, - inventories: { - name_jp: '棚卸資産', - unit: '百万円' - }, - merchandise: { - name_jp: '商品', - unit: '百万円' - }, - work_in_process: { - name_jp: '仕掛品', - unit: '百万円' - }, - raw_materials_and_supplies: { - name_jp: '原材料', - unit: '百万円' - }, - prepaid_expenses: { - name_jp: '前払金', - unit: '百万円' - }, - current_dta: { - name_jp: '繰延税金資産(流動)', - unit: '百万円' - }, - current_allowance_doubtful_accounts: { - name_jp: '貸倒引当金', - unit: '百万円' - }, - non_current_assets: { - name_jp: '固定資産', - unit: '百万円' - }, - tangible_fixed_assets: { - name_jp: '有形固定資産', - unit: '百万円' - }, - buildings: { - name_jp: '建物・構築物', - unit: '百万円' - }, - machineries: { - name_jp: '機械・運搬具・工具', - unit: '百万円' - }, - land: { - name_jp: '土地', - unit: '百万円' - }, - construction_in_progress: { - name_jp: '建設仮勘定', - unit: '百万円' - }, - intangible_assets: { - name_jp: '無形固定資産', - unit: '百万円' - }, - good_will: { - name_jp: 'のれん', - unit: '百万円' - }, - investments_and_other_assets: { - name_jp: '投資その他の資産', - unit: '百万円' - }, - investment_securities: { - name_jp: '投資有価証券', - unit: '百万円' - }, - non_current_dta: { - name_jp: '繰延税金資産(固定)', - unit: '百万円' - }, - non_current_allowance_doubtful_accounts: { - name_jp: '貸倒引当金', - unit: '百万円' - }, - lease_and_guarantee_deposits: { - name_jp: '敷金および保証金', - unit: '百万円' - }, - liabilities: { - name_jp: '負債', - unit: '百万円' - }, - debt: { - name_jp: '有利子負債', - unit: '百万円' - }, - current_liabilities: { - name_jp: '流動負債', - unit: '百万円' - }, - trade_payables: { - name_jp: '仕入債務', - unit: '百万円' - }, - notes_accounts_payable: { - name_jp: '支払手形および買掛金', - unit: '百万円' - }, - accounts_payable: { - name_jp: '買掛金', - unit: '百万円' - }, - notes_payable: { - name_jp: '支払手形', - unit: '百万円' - }, - short_term_bonds_payable: { - name_jp: '短期社債', - unit: '百万円' - }, - short_term_loans_payable: { - name_jp: '短期借入金', - unit: '百万円' - }, - commercial_papers_liabilities: { - name_jp: 'コマーシャルペーパー', - unit: '百万円' - }, - current_lease_obligations: { - name_jp: 'リース債務(流動負債)', - unit: '百万円' - }, - current_portion_of_long_term_loans: { - name_jp: '1年以内返済の長期借入金', - unit: '百万円' - }, - current_portion_of_bonds: { - name_jp: '1年以内返済の社債', - unit: '百万円' - }, - current_portion_of_convertible_bonds: { - name_jp: '1年以内返済の転換社債', - unit: '百万円' - }, - current_portion_of_bonds_with_subscription_rights: { - name_jp: '1年以内返済の新株予約権付社債', - unit: '百万円' - }, - advances_received: { - name_jp: '前受金', - unit: '百万円' - }, - corporate_tax_payable: { - name_jp: '未払法人税等', - unit: '百万円' - }, - non_current_liabilities: { - name_jp: '固定負債', - unit: '百万円' - }, - bonds_payable: { - name_jp: '社債', - unit: '百万円' - }, - convertible_bonds: { - name_jp: '転換社債', - unit: '百万円' - }, - convertible_bond_type_bonds_with_subscription_rights: { - name_jp: '新株予約権付転換社債', - unit: '百万円' - }, - non_current_bonds_with_subscription_right: { - name_jp: '新株予約権付社債', - unit: '百万円' - }, - long_term_loans_payable: { - name_jp: '長期借入金', - unit: '百万円' - }, - non_current_lease_obligations: { - name_jp: 'リース債務(固定負債)', - unit: '百万円' - }, - non_current_dtl: { - name_jp: '繰延税金負債(固定)', - unit: '百万円' - }, - net_assets: { - name_jp: '純資産', - unit: '百万円' - }, - shareholders_equity: { - name_jp: '株主資本', - unit: '百万円' - }, - capital_stock: { - name_jp: '資本金', - unit: '百万円' - }, - additional_capital_stock: { - name_jp: '資本剰余金', - unit: '百万円' - }, - retained_earnings: { - name_jp: '利益剰余金', - unit: '百万円' - }, - treasury_stock: { - name_jp: '自己株式', - unit: '百万円' - }, - valuation_and_translation_adjustments: { - name_jp: '評価換算差額等', - unit: '百万円' - }, - non_controlling_interests: { - name_jp: '非支配持分', - unit: '百万円' - }, - net_sales: { - name_jp: '売上', - unit: '百万円' - }, - cost_of_sales: { - name_jp: '売上原価', - unit: '百万円' - }, - gross_profit: { - name_jp: '売上高総利益', - unit: '百万円' - }, - gross_margin: { - name_jp: '売上高総利益率', - unit: '%' - }, - sga: { - name_jp: '販売費および一般管理費', - unit: '百万円' - }, - operating_income: { - name_jp: '営業利益', - unit: '百万円' - }, - operating_margin: { - name_jp: '営業利益率', - unit: '%' - }, - non_operating_income: { - name_jp: '営業外収益', - unit: '百万円' - }, - interest_and_dividends_income: { - name_jp: '受取利息および受取配当金', - unit: '百万円' - }, - interest_income: { - name_jp: '受取利息', - unit: '百万円' - }, - dividends_income: { - name_jp: '受取配当金', - unit: '百万円' - }, - equity_method_income: { - name_jp: '持分法による投資利益', - unit: '百万円' - }, - non_operating_expenses: { - name_jp: '営業外費用', - unit: '百万円' - }, - interest_expense: { - name_jp: '支払利息', - unit: '百万円' - }, - equity_method_loss: { - name_jp: '持分法による投資損失', - unit: '百万円' - }, - ordinary_income: { - name_jp: '経常利益', - unit: '百万円' - }, - extraordinary_income: { - name_jp: '特別利益', - unit: '百万円' - }, - gain_of_sales_non_current_assets: { - name_jp: '固定資産売却益', - unit: '百万円' - }, - gain_of_sales_investment_securities: { - name_jp: '投資有価証券売却益', - unit: '百万円' - }, - extraordinary_loss: { - name_jp: '特別損失', - unit: '百万円' - }, - loss_of_sales_non_current_assets: { - name_jp: '固定資産売却損', - unit: '百万円' - }, - loss_of_valuation_investment_securities: { - name_jp: '投資有価証券売却損', - unit: '百万円' - }, - impairment_loss: { - name_jp: '減損損失', - unit: '百万円' - }, - income_before_income_taxes: { - name_jp: '税引前当期純利益', - unit: '百万円' - }, - income_taxes: { - name_jp: '法人税等', - unit: '百万円' - }, - real_corporate_tax_rate: { - name_jp: '実質法人税率', - unit: '%' - }, - net_income: { - name_jp: '当期純利益', - unit: '百万円' - }, - non_controling_interests: { - name_jp: '非支配株主に帰属する当期純利益', - unit: '百万円' - }, - profit_loss_attributable_to_owners_of_parent: { - name_jp: '親会社株主に帰属する当期純利益', - unit: '百万円' - }, - net_profit_margin: { - name_jp: '当期純利益率', - unit: '%' - }, - operating_cash_flow: { - name_jp: '営業キャッシュフロー', - unit: '百万円' - }, - income_before_taxes: { - name_jp: '税金等調整前当期純利益', - unit: '百万円' - }, - depreciation: { - name_jp: '減価償却費', - unit: '百万円' - }, - amortization: { - name_jp: 'のれん償却費', - unit: '百万円' - }, - decrease_trade_receivables_op_cf: { - name_jp: '売上債権の増減額', - unit: '百万円' - }, - decrease_inventories_op_cf: { - name_jp: '棚卸資産の増減額', - unit: '百万円' - }, - increase_trade_payables_op_cf: { - name_jp: '仕入債務の増減額', - unit: '百万円' - }, - investment_cash_flow: { - name_jp: '投資キャッシュフロー', - unit: '百万円' - }, - purchase_of_property: { - name_jp: '有形固定資産の取得による支出', - unit: '百万円' - }, - sale_of_property: { - name_jp: '有形固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_intangible_assets: { - name_jp: '無形固定資産の取得による支出', - unit: '百万円' - }, - sale_of_intangible_assets: { - name_jp: '無形固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_non_current_assets: { - name_jp: '固定資産の取得による支出', - unit: '百万円' - }, - sale_of_non_current_assets: { - name_jp: '固定資産の売却による収入', - unit: '百万円' - }, - purchase_of_securities: { - name_jp: '有価証券の取得による支出', - unit: '百万円' - }, - sale_of_securities: { - name_jp: '有価証券の売却・償還による収入', - unit: '百万円' - }, - purchase_of_investment_securities: { - name_jp: '投資有価証券の取得による支出', - unit: '百万円' - }, - sale_of_investment_securities: { - name_jp: '投資有価証券の売却・償還による収入', - unit: '百万円' - }, - lending: { - name_jp: '貸付けによる支出', - unit: '百万円' - }, - return_of_lending: { - name_jp: '貸付金の回収による収入', - unit: '百万円' - }, - financial_cash_flow: { - name_jp: '財務キャッシュフロー', - unit: '百万円' - }, - net_short_term_debt: { - name_jp: '短期借入金の純増減額', - unit: '百万円' - }, - long_term_debt_issuance: { - name_jp: '長期借入れによる収入', - unit: '百万円' - }, - long_term_debt_repayment: { - name_jp: '長期借入金の返済による支出', - unit: '百万円' - }, - bonds_issuance: { - name_jp: '社債の発行による収入', - unit: '百万円' - }, - bonds_repayment: { - name_jp: '社債の償還による支出', - unit: '百万円' - }, - share_repurchase: { - name_jp: '自己株式の取得による支出', - unit: '百万円' - }, - share_sales: { - name_jp: '自己株式の売却による収入', - unit: '百万円' - }, - dividend_payment: { - name_jp: '配当金の支払額', - unit: '百万円' - }, - cash_translation_difference: { - name_jp: '現金及び現金同等物に係る換算差額', - unit: '百万円' - }, - free_cash_flow: { - name_jp: 'フリーキャッシュフロー', - unit: '百万円' - }, - ex_net_sales: { - name_jp: '売上(会社予想)', - unit: '百万円' - }, - ex_operating_income: { - name_jp: '営業利益(会社予想)', - unit: '百万円' - }, - ex_ordinary_income: { - name_jp: '経常利益(会社予想)', - unit: '百万円' - }, - ex_net_income: { - name_jp: '当期純利益(会社予想)', - unit: '百万円' - }, - dividend: { - name_jp: '配当金(実績)', - unit: '円' - }, - eps_actual: { - name_jp: 'EPS(実績)', - unit: '円' - }, - bps: { - name_jp: 'BPS', - unit: '円' - }, - ebitda_forecast: { - name_jp: 'EBITDA(会社予想)', - unit: '百万円' - }, - ebitda_actual: { - name_jp: 'EBITDA(実績)', - unit: '百万円' - }, - roe: { - name_jp: 'ROE', - unit: '%' - }, - real_roe: { - name_jp: '実質ROE', - unit: '%' - }, - total_asset_turnover: { - name_jp: '総資産回転率', - unit: '倍' - }, - financial_leverage: { - name_jp: '財務レバレッジ', - unit: '倍' - }, - roa: { - name_jp: 'ROA', - unit: '%' - }, - roic: { - name_jp: 'ROIC', - unit: '%' - }, - doe: { - name_jp: '自己資本配当率', - unit: '%' - }, - net_sales_operating_cash_flow_ratio: { - name_jp: '営業キャッシュフロー/売上比率', - unit: '%' - }, - sga_ratio: { - name_jp: '販管費/売上率', - unit: '%' - }, - depreciation_gross_profit_ratio: { - name_jp: '減価償却費/粗利比率', - unit: '%' - }, - r_and_d_ratio: { - name_jp: '研究開発費/売上比率', - unit: '%' - }, - interest_op_income_ratio: { - name_jp: '支払利息/営業利益比率', - unit: '%' - }, - interest_coverage_ratio: { - name_jp: 'インタレストカバレッジレシオ ', - unit: '倍' - }, - net_sales_progress: { - name_jp: '売上進捗率', - unit: '%' - }, - operating_income_progress: { - name_jp: '営業利益進捗率', - unit: '%' - }, - net_income_progress: { - name_jp: '純利益進捗率', - unit: '%' - }, - net_sales_growth_rate_forecast: { - name_jp: '売上高成長率(直近年度実績→会社予想)', - unit: '%' - }, - operating_income_growth_rate_forecast: { - name_jp: '営業利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - net_income_growth_rate_forecast: { - name_jp: '純利益成長率(直近年度実績→会社予想)', - unit: '%' - }, - cash_assets_ratio: { - name_jp: '現金総資産比率', - unit: '%' - }, - cash_monthly_sales_ratio: { - name_jp: '現金売上倍率', - unit: '倍' - }, - accounts_receivable_turnover: { - name_jp: '売上債権回転期間', - unit: '日' - }, - inventory_turnover: { - name_jp: '棚卸資産回転期間', - unit: '日' - }, - trade_payable_turnover: { - name_jp: '仕入債務回転期間', - unit: '日' - }, - working_capital: { - name_jp: '運転資本', - unit: '百万円' - }, - ccc: { - name_jp: 'CCC', - unit: '日' - }, - tangible_fixed_assets_turnover: { - name_jp: '有形固定資産回転率', - unit: '%' - }, - debt_assets_ratio: { - name_jp: '有利子負債/総資産比率', - unit: '%' - }, - debt_monthly_sales_ratio: { - name_jp: '有利子負債/月商比率', - unit: 'ヶ月' - }, - operating_cash_flow_debt_ratio: { - name_jp: '有利子負債/営業キャッシュフロー倍率', - unit: '倍' - }, - net_debt: { - name_jp: '純有利子負債', - unit: '百万円' - }, - adjusted_debt_ratio: { - name_jp: '自己株式調整済負債比率', - unit: '%' - }, - de_ratio: { - name_jp: 'DE比率', - unit: '%' - }, - current_ratio: { - name_jp: '流動比率', - unit: '%' - }, - net_debt_net_income_ratio: { - name_jp: 'ネットD純利益比率', - unit: '倍' - }, - equity: { - name_jp: '自己資本', - unit: '百万円' - }, - equity_ratio: { - name_jp: '自己資本比率', - unit: '%' - }, - accrual: { - name_jp: 'アクルーアル ', - unit: '百万円' - }, - employee_num: { - name_jp: '従業員数', - unit: '人' - }, - net_sales_per_employee: { - name_jp: '従業員一人あたり売上', - unit: '百万円' - }, - operating_income_per_employee: { - name_jp: '従業員一人あたり営業利益', - unit: '百万円' - }, - fiscal_year: { - name_jp: '会計年度', - unit: 'なし' - }, - fiscal_quarter: { - name_jp: '四半期', - unit: 'なし' - } -} diff --git a/src/custom-functions/bcode.ts b/src/custom-functions/bcode.ts index 74d1594..79bd1be 100644 --- a/src/custom-functions/bcode.ts +++ b/src/custom-functions/bcode.ts @@ -1,4 +1,5 @@ import { bcode as bcodeV2 } from '~/custom-functions/v2/bcode' +import { bcode as bcodeV3 } from '~/custom-functions/v3/bcode' export function castStringAsBoolean(bool: string | boolean): boolean { return typeof bool === 'string' ? bool.toLowerCase() === 'true' : bool @@ -30,8 +31,20 @@ export function bcode( param5: string | boolean = false ): number | string { if (param1 instanceof Date || isV3Call(param1, param2)) { - throw new Error( - `<<引数が不正な形式です。param1: ${param1} (${typeof param1}), param2: ${param2} (${typeof param2})>>` + if (typeof param1 === 'number') { + param1 = param1.toString() + } + + if (typeof param2 === 'number') { + param2 = param2.toString() + } + + return bcodeV3( + ticker, + param1, + param2, + castStringAsBoolean(param3), + castStringAsBoolean(param4) ) } else { return bcodeV2( diff --git a/src/custom-functions/v2/bcode-indicator.test.ts b/src/custom-functions/v2/bcode-indicator.test.ts index 9af9c3c..d077b1c 100644 --- a/src/custom-functions/v2/bcode-indicator.test.ts +++ b/src/custom-functions/v2/bcode-indicator.test.ts @@ -1,6 +1,6 @@ import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { bcodeIndicator } from '~/custom-functions/v2/bcode-indicator' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' import { IndicatorCache } from '~/services/indicator-cache' import { IndicatorPropertyCache } from '~/services/indicator-property-cache' diff --git a/src/custom-functions/v2/bcode-indicator.ts b/src/custom-functions/v2/bcode-indicator.ts index 9e3dfb3..7d4bc53 100644 --- a/src/custom-functions/v2/bcode-indicator.ts +++ b/src/custom-functions/v2/bcode-indicator.ts @@ -1,7 +1,7 @@ import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' -import { BcodeResult } from '~/custom-functions/bcode-result' import { ApiResponseError } from '~/custom-functions/error' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' export function bcodeIndicator( client: CachingBuffettCodeApiClientV2, diff --git a/src/custom-functions/v2/bcode-quarter.test.ts b/src/custom-functions/v2/bcode-quarter.test.ts index cb2cae8..592109f 100644 --- a/src/custom-functions/v2/bcode-quarter.test.ts +++ b/src/custom-functions/v2/bcode-quarter.test.ts @@ -1,7 +1,7 @@ import { QuarterCache } from '~/__mocks__/services/quarter-cache' import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { bcodeQuarter } from '~/custom-functions/v2/bcode-quarter' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' import { YearQuarter } from '~/fiscal-periods/year-quarter' import { QuarterPropertyCache } from '~/services/quarter-property-cache' diff --git a/src/custom-functions/v2/bcode-quarter.ts b/src/custom-functions/v2/bcode-quarter.ts index 580ebfc..fe37a19 100644 --- a/src/custom-functions/v2/bcode-quarter.ts +++ b/src/custom-functions/v2/bcode-quarter.ts @@ -1,12 +1,12 @@ import { CompanyService } from '~/api/company-service' import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' import { CachingQuarterProperty } from '~/api/v2/caching-quarter-property' -import { BcodeResult } from '~/custom-functions/bcode-result' import { ApiResponseError, OndemandApiNotEnabledError, UnsupportedTickerError } from '~/custom-functions/error' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' export function bcodeQuarter( diff --git a/src/custom-functions/bcode-result.test.ts b/src/custom-functions/v2/bcode-result.test.ts similarity index 95% rename from src/custom-functions/bcode-result.test.ts rename to src/custom-functions/v2/bcode-result.test.ts index c40a584..f71cd1d 100644 --- a/src/custom-functions/bcode-result.test.ts +++ b/src/custom-functions/v2/bcode-result.test.ts @@ -1,4 +1,4 @@ -import { BcodeResult } from '~/custom-functions/bcode-result' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' test('format', () => { expect(new BcodeResult(1234.5678, '日').format(false, false)).toBe(1234.6) diff --git a/src/custom-functions/bcode-result.ts b/src/custom-functions/v2/bcode-result.ts similarity index 100% rename from src/custom-functions/bcode-result.ts rename to src/custom-functions/v2/bcode-result.ts diff --git a/src/custom-functions/v2/bcode.ts b/src/custom-functions/v2/bcode.ts index b91fd9a..ccc2f40 100644 --- a/src/custom-functions/v2/bcode.ts +++ b/src/custom-functions/v2/bcode.ts @@ -2,7 +2,6 @@ import { HttpError } from '~/api/http-error' import { CachingBuffettCodeApiClientV2 } from '~/api/v2/caching-client' import { CachingIndicatorProperty } from '~/api/v2/caching-indicator-property' import { QuarterProperty } from '~/api/v2/quarter-property' -import { BcodeResult } from '~/custom-functions/bcode-result' import { ApiResponseError, OndemandApiNotEnabledError, @@ -10,6 +9,7 @@ import { } from '~/custom-functions/error' import { bcodeIndicator } from '~/custom-functions/v2/bcode-indicator' import { bcodeQuarter } from '~/custom-functions/v2/bcode-quarter' +import { BcodeResult } from '~/custom-functions/v2/bcode-result' import { InvalidLYLQError, InvalidYearError, diff --git a/src/custom-functions/v3/bcode-daily.test.ts b/src/custom-functions/v3/bcode-daily.test.ts index 5f2934d..35ddb4f 100644 --- a/src/custom-functions/v3/bcode-daily.test.ts +++ b/src/custom-functions/v3/bcode-daily.test.ts @@ -1,6 +1,6 @@ import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { bcodeDaily } from '~/custom-functions/v3/bcode-daily' +import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { DateParam } from '~/fiscal-periods/date-param' import { DailyCache } from '~/services/daily-cache' @@ -24,6 +24,6 @@ test('bcodeDaily', () => { const client = new CachingBuffettCodeApiClientV3('token') const result = bcodeDaily(client, ticker, date, propertyName, false) - expect(result).toEqual(new BcodeResult(550294097166, '百万円')) + expect(result).toEqual(new BcodeResult(propertyName, 550294097166, '円')) expect(DailyCache.get(ticker, date)).not.toBeNull() }) diff --git a/src/custom-functions/v3/bcode-daily.ts b/src/custom-functions/v3/bcode-daily.ts index 47422c5..e42b502 100644 --- a/src/custom-functions/v3/bcode-daily.ts +++ b/src/custom-functions/v3/bcode-daily.ts @@ -1,12 +1,12 @@ import { CompanyService } from '~/api/company-service' import { BuffettCodeApiClientV3 } from '~/api/v3/client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { ApiResponseError, OndemandApiNotEnabledError, PropertyNotFoundError, UnsupportedTickerError } from '~/custom-functions/error' +import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { Daily } from '~/entities/v3/daily' import { DateParam } from '~/fiscal-periods/date-param' @@ -47,5 +47,5 @@ export function bcodeDaily( const value = daily.data[propertyName] const unit = property['unit'] - return new BcodeResult(value, unit) + return new BcodeResult(propertyName, value, unit) } diff --git a/src/custom-functions/v3/bcode-quarter.test.ts b/src/custom-functions/v3/bcode-quarter.test.ts index 6b61025..b01d2d4 100644 --- a/src/custom-functions/v3/bcode-quarter.test.ts +++ b/src/custom-functions/v3/bcode-quarter.test.ts @@ -1,6 +1,6 @@ import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { bcodeQuarter } from '~/custom-functions/v3/bcode-quarter' +import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { YearQuarter } from '~/fiscal-periods/year-quarter' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' import { QuarterCache } from '~/services/quarter-cache' @@ -31,6 +31,6 @@ test('bcodeQuarter', () => { false ) - expect(result).toEqual(new BcodeResult(12513000000, '円')) + expect(result).toEqual(new BcodeResult(propertyName, 12513000000, '円')) expect(QuarterCache.get(ticker, period)).not.toBeNull() }) diff --git a/src/custom-functions/v3/bcode-quarter.ts b/src/custom-functions/v3/bcode-quarter.ts index 98a74b8..eba4eb8 100644 --- a/src/custom-functions/v3/bcode-quarter.ts +++ b/src/custom-functions/v3/bcode-quarter.ts @@ -1,12 +1,12 @@ import { CompanyService } from '~/api/company-service' import { BuffettCodeApiClientV3 } from '~/api/v3/client' -import { BcodeResult } from '~/custom-functions/bcode-result' import { ApiResponseError, OndemandApiNotEnabledError, PropertyNotFoundError, UnsupportedTickerError } from '~/custom-functions/error' +import { BcodeResult } from '~/custom-functions/v3/bcode-result' import { Quarter } from '~/entities/v3/quarter' import { YearQuarterParam } from '~/fiscal-periods/year-quarter-param' @@ -47,5 +47,5 @@ export function bcodeQuarter( const value = quarter.data[propertyName] const unit = property['unit'] - return new BcodeResult(value, unit) + return new BcodeResult(propertyName, value, unit) } diff --git a/src/custom-functions/v3/bcode-result.test.ts b/src/custom-functions/v3/bcode-result.test.ts new file mode 100644 index 0000000..08bb2ac --- /dev/null +++ b/src/custom-functions/v3/bcode-result.test.ts @@ -0,0 +1,52 @@ +import { BcodeResult } from '~/custom-functions/v3/bcode-result' + +test('format (days)', () => { + expect(new BcodeResult('ccc', 1234.5678, '日').format(false, false)).toBe( + 1234.6 + ) + expect(new BcodeResult('ccc', 1234.5678, '日').format(true, false)).toBe( + 1234.5678 + ) + expect(new BcodeResult('ccc', 1234.5678, '日').format(false, true)).toBe( + '1,234.6日' + ) + expect(new BcodeResult('ccc', 1234.5678, '日').format(true, true)).toBe( + '1,234.5678日' + ) +}) + +test('format (yen)', () => { + expect(new BcodeResult('', 430602000000, '円').format(false, false)).toBe( + 430602000000 + ) + expect(new BcodeResult('', 430602000000, '円').format(true, false)).toBe( + 430602000000 + ) + expect(new BcodeResult('', 430602000000, '円').format(false, true)).toBe( + '430,602,000,000円' + ) + expect(new BcodeResult('', 430602000000, '円').format(true, true)).toBe( + '430,602,000,000円' + ) +}) + +test('format (million-yen)', () => { + // using unit-mapping.json + expect( + new BcodeResult('market_capital', 550294097166, '円').format(false, false) + ).toBe(550294) + expect( + new BcodeResult('market_capital', 550294097166, '円').format(true, false) + ).toBe(550294097166) + expect( + new BcodeResult('market_capital', 550294097166, '円').format(false, true) + ).toBe('550,294百万円') + expect( + new BcodeResult('market_capital', 550294097166, '円').format(true, true) + ).toBe('550,294,097,166円') +}) + +test('format (null)', () => { + expect(new BcodeResult('net_sales', null, '円').format(true, false)).toBe('') + expect(new BcodeResult('net_sales', null, '円').format(true, true)).toBe('') +}) diff --git a/src/custom-functions/v3/bcode-result.ts b/src/custom-functions/v3/bcode-result.ts new file mode 100644 index 0000000..a11a892 --- /dev/null +++ b/src/custom-functions/v3/bcode-result.ts @@ -0,0 +1,42 @@ +import * as unitConversion from '~/custom-functions/v3/unit-conversion.js' +import { Formatter } from '~/services/formatter' + +export class BcodeResult { + constructor( + public name: string, + public value: number | string | null, + public unit: string + ) {} + + private isMillionYenProperty(): boolean { + return unitConversion.millionYen.includes(this.name) + } + + public format(isRawValue: boolean, isWithUnits: boolean): number | string { + let value = this.value + let unit = this.unit + + if (value === null) { + return '' + } + + if (!isRawValue && typeof value === 'number') { + if (unit === '円' && this.isMillionYenProperty()) { + value = Formatter.round(value / 1000000, 0) // 整数に丸める + unit = '百万円' + } else { + value = Formatter.round(value, 1) // 小数点第1位までに丸める + } + } + + if (isWithUnits) { + if (typeof value == 'number') { + return Formatter.commaStyled(value) + unit + } else { + return value + unit + } + } else { + return value + } + } +} diff --git a/src/custom-functions/v3/bcode.ts b/src/custom-functions/v3/bcode.ts new file mode 100644 index 0000000..1c0b9b5 --- /dev/null +++ b/src/custom-functions/v3/bcode.ts @@ -0,0 +1,112 @@ +import { HttpError } from '~/api/http-error' +import { CachingBuffettCodeApiClientV3 } from '~/api/v3/caching-client' +import { + ApiResponseError, + OndemandApiNotEnabledError, + UnsupportedTickerError +} from '~/custom-functions/error' +import { bcodeDaily } from '~/custom-functions/v3/bcode-daily' +import { bcodeQuarter } from '~/custom-functions/v3/bcode-quarter' +import { BcodeResult } from '~/custom-functions/v3/bcode-result' +import { DateParam } from '~/fiscal-periods/date-param' +import { + InvalidLYLQError, + InvalidYearError, + InvalidQuarterError +} from '~/fiscal-periods/error' +import { PeriodParser } from '~/fiscal-periods/period-parser' +import { Setting } from '~/setting' + +function handleError(e): void { + if (e instanceof ApiResponseError) { + throw new Error('<<指定されたデータを取得できませんでした>>') + } else if (e instanceof OndemandApiNotEnabledError) { + throw new Error('<<従量課金APIが有効になっていません>>') + } else if (e instanceof UnsupportedTickerError) { + throw new Error('<<サポートされていないtickerです>>') + } else if (e instanceof HttpError) { + const code = e.response.getResponseCode() + + if (e.isInvalidTestingRequest()) { + throw new Error('<<テスト用のAPIキーでは取得できないデータです>>') + } else if (e.isInvalidTokenRequest()) { + throw new Error('<>') + } else if (code === 403) { + throw new Error('<<月間リクエスト制限に達しています>>') + } else if (code === 429) { + throw new Error('<>') + } else if (Math.floor(code / 100) === 4) { + throw new Error(`<<無効なリクエストです。${e.name}: ${e.message}>>`) + } else { + console.error('システムエラー', e.name, e.message) + throw new Error( + `<<システムエラーが発生しました。${e.name}: ${e.message}>>` + ) + } + } else if (e instanceof InvalidLYLQError) { + throw new Error('<>') + } else if (e instanceof InvalidYearError) { + throw new Error(`<<無効な決算年度が指定されています>>`) + } else if (e instanceof InvalidQuarterError) { + throw new Error(`<<無効な四半期が指定されています>>`) + } else { + console.error('未定義のエラー', e.name, e.message) + throw new Error(`<<未定義のエラーが発生しました。${e.name}: ${e.message}>>`) + } +} + +export function bcode( + ticker: string, + period: string | Date, + propertyName: string, + isRawValue = false, + isWithUnits = false +): number | string { + if (!ticker) { + throw new Error('<>') + } + + if (!period) { + throw new Error('<>') + } + + if (!propertyName) { + throw new Error('<>') + } + + if (period instanceof Date) { + period = period.toISOString().substring(0, 10) + } + + const setting = Setting.load() + if (!setting.token) { + throw new Error('<>') + } + + try { + const client = new CachingBuffettCodeApiClientV3(setting.token) + const parsedPeriod = PeriodParser.parse(period) + let result: BcodeResult + if (parsedPeriod instanceof DateParam) { + result = bcodeDaily( + client, + ticker, + parsedPeriod, + propertyName, + setting.ondemandApiEnabled + ) + } else { + result = bcodeQuarter( + client, + ticker, + parsedPeriod, + propertyName, + setting.ondemandApiEnabled + ) + } + + return result.format(isRawValue, isWithUnits) + } catch (e) { + handleError(e) + } +} diff --git a/src/custom-functions/v3/unit-conversion.js b/src/custom-functions/v3/unit-conversion.js new file mode 100644 index 0000000..2ecb20c --- /dev/null +++ b/src/custom-functions/v3/unit-conversion.js @@ -0,0 +1,138 @@ +module.exports = { + millionYen: [ + 'accounts_payable', + 'accounts_receivable', + 'accrual', + 'additional_capital_stock', + 'advances_received', + 'amortization', + 'assets', + 'bonds_issuance', + 'bonds_payable', + 'bonds_repayment', + 'buildings', + 'capital_stock', + 'cash_and_deposits', + 'cash_translation_difference', + 'commercial_papers_liabilities', + 'construction_in_progress', + 'convertible_bond_type_bonds_with_subscription_rights', + 'convertible_bonds', + 'corporate_tax_payable', + 'cost_of_sales', + 'current_allowance_doubtful_accounts', + 'current_assets', + 'current_dta', + 'current_lease_obligations', + 'current_liabilities', + 'current_portion_of_bonds', + 'current_portion_of_bonds_with_subscription_rights', + 'current_portion_of_convertible_bonds', + 'current_portion_of_long_term_loans', + 'current_securities', + 'debt', + 'decrease_inventories_op_cf', + 'decrease_trade_receivables_op_cf', + 'depreciation', + 'dividend_payment', + 'dividends_income', + 'ebitda_actual', + 'ebitda_forecast', + 'enterprise_value', + 'equity', + 'equity_method_income', + 'equity_method_loss', + 'ex_net_income', + 'ex_net_sales', + 'ex_operating_income', + 'ex_ordinary_income', + 'extraordinary_income', + 'extraordinary_loss', + 'financial_cash_flow', + 'free_cash_flow', + 'gain_of_sales_investment_securities', + 'gain_of_sales_non_current_assets', + 'good_will', + 'gross_profit', + 'impairment_loss', + 'income_before_income_taxes', + 'income_before_taxes', + 'income_taxes', + 'increase_in_properties', + 'increase_trade_payables_op_cf', + 'intangible_assets', + 'interest_and_dividends_income', + 'interest_expense', + 'interest_income', + 'inventories', + 'investment_cash_flow', + 'investment_securities', + 'investments_and_other_assets', + 'land', + 'lease_and_guarantee_deposits', + 'lending', + 'liabilities', + 'long_term_debt_issuance', + 'long_term_debt_repayment', + 'long_term_loans_payable', + 'loss_of_sales_non_current_assets', + 'loss_of_valuation_investment_securities', + 'machineries', + 'market_capital', + 'merchandise', + 'net_assets', + 'net_debt', + 'net_income', + 'net_sales', + 'net_sales_per_employee', + 'net_short_term_debt', + 'non_controling_interests', + 'non_controlling_interests', + 'non_current_allowance_doubtful_accounts', + 'non_current_assets', + 'non_current_bonds_with_subscription_right', + 'non_current_dta', + 'non_current_dtl', + 'non_current_lease_obligations', + 'non_current_liabilities', + 'non_operating_expenses', + 'non_operating_income', + 'notes_accounts_payable', + 'notes_accounts_receivable', + 'notes_payable', + 'notes_receivable', + 'operating_cash_flow', + 'operating_income', + 'operating_income_per_employee', + 'ordinary_income', + 'prepaid_expenses', + 'profit_loss_attributable_to_owners_of_parent', + 'purchase_of_intangible_assets', + 'purchase_of_investment_securities', + 'purchase_of_non_current_assets', + 'purchase_of_property', + 'purchase_of_securities', + 'r_and_d_expenses', + 'raw_materials_and_supplies', + 'retained_earnings', + 'return_of_lending', + 'sale_of_intangible_assets', + 'sale_of_investment_securities', + 'sale_of_non_current_assets', + 'sale_of_property', + 'sale_of_securities', + 'sga', + 'share_repurchase', + 'share_sales', + 'shareholders_equity', + 'short_term_bonds_payable', + 'short_term_loans_payable', + 'tangible_fixed_assets', + 'trade_payables', + 'trade_receivables', + 'treasury_stock', + 'valuation_and_translation_adjustments', + 'work_in_process', + 'working_capital' + ] +} diff --git a/src/main.ts b/src/main.ts index ffd919d..14d9203 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,8 +38,7 @@ global.exportCsv = exportCsv * 指定した銘柄の財務数字や指標を取得します。 * * @param {"6501"} ticker 銘柄コード - * @param {"2017"} fiscalYear 会計年度 (または"LY") - * @param {"4"} fiscalQuarter 四半期 (1~4の数字または"LQ") + * @param {"2017Q4"} period 会計期間 (例: 四半期 '2017Q4', 日付 '2020-09-06') * @param {"net_sales"} propertyName 項目名 * @param {TRUE} isRawValue (オプション) 数値をRAWデータで表示するかどうか (デフォルト値: FALSE) * @param {TRUE} isWithUnits (オプション) 単位を末尾に付加するかどうか (デフォルト値: FALSE)