Skip to content
New issue

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

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

Already on GitHub? # to your account

Add Daily Treasury Rates endpoint #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Below is a list of the iexcloud APIs that have ([x]) and have not ([ ]) been imp
| [x] | Cash Flow | 1000 |per symbol per period
| [x] | Collections | 1 |per symbol in collection
| [x] | Company | 1 |per symbol
| [x] | CEO Compensation | 20 |per symbol
| [x] | Delayed Quote | 1 |per symbol
| [x] | Dividends | 10 |per symbol
| [x] | Earnings | 1000 |per symbol per period
Expand Down Expand Up @@ -181,6 +182,11 @@ Below is a list of the iexcloud APIs that have ([x]) and have not ([ ]) been imp
| [x] | News
| [ ] | Crypto

### Treasuries
| | Endpoint | Message Units | per |
|-----|----------------|---------------:|-----|
| [x] | Daily Treasury Rates | 1000 | per symbol per date

### Reference Data
| | Endpoint | Message Units | per |
|-----|----------------|---------------:|-----|
Expand Down
3 changes: 2 additions & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export declare const company: (symbol: string) => Promise<Company>;

export declare const cryptoQuote: (symbol: string) => Promise<CryptoQuote>;

export declare const dailyTreasuryRates: (symbol: string) => Promise<DailyTreasuryRate[]>;

export declare const delayedQuote: (symbol: string) => Promise<DelayedQuote>;

export declare type timePeriod = "next" | "1m" | "3m" | "6m" | "ytd" | "1y" | "2y" | "5y";
Expand Down Expand Up @@ -228,4 +230,3 @@ export declare const officialPrice: (symbol: string) => Promise<DEEPOfficialPric

export declare const deepTrades: (symbol: string) => Promise<DEEPTrade[]>;
```

65 changes: 65 additions & 0 deletions src/Services/DailyTreasuryRates.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { DynamicObject, iexApiRequest, KVP } from "./iexcloud.service";

/**
* Daily Treasury Rates
* https://iexcloud.io/docs/api/#daily-treasury-rates
*
* Provides the time series data of daily constant maturity rate for treasuries.
*
* - Data Weigthing: 1000 per symbol per date
*
* @param symbol - a treasury symbol
* @returns array of records
*
*/
export const dailyTreasuryRates = async (
symbol: TreasurySymbolType
): Promise<readonly IEXDailyTreasuryRate[]> => {
const dailyTreasuryRatesData: KVP = await iexApiRequest(
`/time-series/treasury/${symbol}`
);

return dailyTreasuryRatesData.map(
(o: KVP) =>
new DailyTreasuryRate({
symbol,
...o,
})
);
};

export interface IEXDailyTreasuryRate {
/** Treasury Symbol */
readonly symbol: string;
/** Rate value of the treasury */
readonly value: number;
/** Id of the treasury */
readonly id: string;
/** Key of the treasury */
readonly key: string;
/** Sub key of the treasury */
readonly subkey: string;
/** Last updated time of the data point represented as millisecond epoch. */
readonly updated: number;
}

export class DailyTreasuryRate extends DynamicObject
implements IEXDailyTreasuryRate {
public symbol: string = "";
public value: number = 0;
public id: string = "";
public key: string = "";
public subkey: string = "";
public updated: number = 0;
}

export type TreasurySymbolType =
| "DGS30" // 30 Year constant maturity rate
| "DGS20" // 20 Year constant maturity rate
| "DGS10" // 10 Year constant maturity rate
| "DGS5" // 5 Year constant maturity rate
| "DGS2" // 2 Year constant maturity rate
| "DGS1" // 1 Year constant maturity rate
| "DGS6MO" // 6 Month constant maturity rate
| "DGS3MO" // 3 Month constant maturity rate
| "DGS1MO"; // 1 Month constant maturity rate
2 changes: 1 addition & 1 deletion src/Services/History.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const history = async (
chartLast: lastN,
chartReset,
chartSimplify,
chartByDay
chartByDay,
});

return data.map((o: KVP) =>
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/DailyTreasuryRates.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @jest-environment node
*/

import * as service from "../Services/DailyTreasuryRates.service";

test("dailyTreasuryRates", async () => {
expect(await service.dailyTreasuryRates("DGS10")).toEqual(
expect.arrayContaining([expect.any(service.DailyTreasuryRate)])
);
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./Services/CeoCompensation.service";
export * from "./Services/Collection.service";
export * from "./Services/Company.service";
export * from "./Services/CryptoQuote.service";
export * from "./Services/DailyTreasuryRates.service";
export * from "./Services/DEEPAuction.service";
export * from "./Services/DEEPBook.service";
export * from "./Services/DEEPOfficialPrice.service";
Expand Down