kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: minor fcn signature changes and add tests
rodzic
42ff3f96a3
commit
fbb95733dd
|
@ -16,6 +16,8 @@ Otherwise, you can pass it in as an argument to the `PolygonClient ` constructor
|
|||
|
||||
1. Open [Polygon.io][polygon] and sign up for an account or log in.
|
||||
2. On the left side of the screen, click on the `API Keys` menu item.
|
||||
3. Locate your API key and copy it to your clipboard by clicking on the respective button.
|
||||
3. Locate your API key and copy it to your clipboard by clicking on the "Copy" button.
|
||||
|
||||

|
||||
|
||||
[polygon]: https://polygon.io
|
||||
|
|
|
@ -34,7 +34,7 @@ export type POLYGON_ORDER_TYPE = 'asc' | 'desc'
|
|||
*/
|
||||
export interface PolygonAggregatesInput {
|
||||
/** The ticker symbol of the stock/equity. */
|
||||
stocksTicker: string
|
||||
ticker: string
|
||||
|
||||
/** The size of the timespan multiplier. */
|
||||
multiplier: number
|
||||
|
@ -916,8 +916,6 @@ export class PolygonClient {
|
|||
/**
|
||||
* Returns the previous day's open, high, low, and close (OHLC) for the specified stock ticker.
|
||||
*
|
||||
* @see {@link https://polygon.io/docs/stocks/get_v2_aggs_ticker__stocksticker__prev}
|
||||
*
|
||||
* @param ticker - ticker symbol of the stock/equity
|
||||
* @param adjusted - whether or not the results are adjusted for splits
|
||||
* @returns promise that resolves to the previous day's open, high, low, and close (OHLC) for the specified stock ticker
|
||||
|
@ -1006,7 +1004,7 @@ export class PolygonClient {
|
|||
* @param params - input parameters (`asset_class` and `locale`)
|
||||
* @returns promise that resolves to ticker types
|
||||
*/
|
||||
async tickerTypes(params: PolygonTickerTypesInput) {
|
||||
async tickerTypes(params: PolygonTickerTypesInput = {}) {
|
||||
return this.api
|
||||
.get('v3/reference/tickers/types', { searchParams: params })
|
||||
.json<PolygonTickerTypesOutput>()
|
||||
|
@ -1050,7 +1048,7 @@ export class PolygonClient {
|
|||
* @param params - input parameters (`asset_class`, `locale`)
|
||||
* @returns promise that resolves to list of exchanges
|
||||
*/
|
||||
async exchanges(params: PolygonExchangesInput) {
|
||||
async exchanges(params: PolygonExchangesInput = {}) {
|
||||
return this.api
|
||||
.get('v3/reference/exchanges', { searchParams: params })
|
||||
.json<PolygonExchangesOutput>()
|
||||
|
@ -1063,9 +1061,8 @@ export class PolygonClient {
|
|||
* @returns promise that resolves to list of aggregates
|
||||
*/
|
||||
async aggregates(params: PolygonAggregatesInput) {
|
||||
const { stocksTicker, multiplier, timespan, from, to, ...otherParams } =
|
||||
params
|
||||
const endpoint = `v2/aggs/ticker/${stocksTicker}/range/${multiplier}/${timespan}/${from}/${to}`
|
||||
const { ticker, multiplier, timespan, from, to, ...otherParams } = params
|
||||
const endpoint = `v2/aggs/ticker/${ticker}/range/${multiplier}/${timespan}/${from}/${to}`
|
||||
return this.api
|
||||
.get(endpoint, { searchParams: otherParams })
|
||||
.json<PolygonAggregatesOutput>()
|
||||
|
|
|
@ -4,7 +4,7 @@ import { PolygonClient } from '@/services/polygon'
|
|||
|
||||
import { ky } from '../_utils'
|
||||
|
||||
test('PolygonClient.tickerDetails', async (t) => {
|
||||
test('PolygonClient.aggregates', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
@ -12,9 +12,20 @@ test('PolygonClient.tickerDetails', async (t) => {
|
|||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.tickerDetails({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.is(result.results.ticker, 'AAPL')
|
||||
const result = await client.aggregates({
|
||||
ticker: 'AAPL',
|
||||
from: '2023-01-01',
|
||||
to: '2023-01-03',
|
||||
multiplier: 1,
|
||||
timespan: 'day',
|
||||
limit: 1
|
||||
})
|
||||
t.is(typeof result.status, 'string', 'Status should be a string')
|
||||
t.is(typeof result.request_id, 'string', 'Request_id should be a string')
|
||||
t.is(typeof result.queryCount, 'number', 'queryCount should be a number')
|
||||
t.is(typeof result.resultsCount, 'number', 'resultsCount should be a number')
|
||||
t.is(typeof result.adjusted, 'boolean', 'adjusted should be a boolean')
|
||||
t.is(typeof result.results, 'object', 'results should be an object')
|
||||
})
|
||||
|
||||
test('PolygonClient.dailyOpenClose', async (t) => {
|
||||
|
@ -33,6 +44,95 @@ test('PolygonClient.dailyOpenClose', async (t) => {
|
|||
t.is(result.symbol, 'AAPL')
|
||||
})
|
||||
|
||||
test('PolygonClient.ema', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.ema({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.true(Array.isArray(result.results.values))
|
||||
})
|
||||
|
||||
test('PolygonClient.exchanges', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.exchanges({
|
||||
asset_class: 'stocks'
|
||||
})
|
||||
t.truthy(result.status)
|
||||
t.true(Array.isArray(result.results))
|
||||
})
|
||||
|
||||
test('PolygonClient.groupedDaily', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.groupedDaily('stocks', { date: '2023-06-21' })
|
||||
t.truthy(result.status)
|
||||
t.true(Array.isArray(result.results))
|
||||
})
|
||||
|
||||
test('PolygonClient.macd', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.macd({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.true(Array.isArray(result.results.values))
|
||||
})
|
||||
|
||||
test('PolygonClient.marketHolidays', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.marketHolidays()
|
||||
t.true(Array.isArray(result), 'Result should be an array')
|
||||
})
|
||||
|
||||
test('PolygonClient.marketStatus', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.marketStatus()
|
||||
|
||||
t.true(typeof result.afterHours === 'boolean')
|
||||
t.truthy(result.currencies)
|
||||
t.true(typeof result.currencies.crypto === 'string')
|
||||
t.true(typeof result.currencies.fx === 'string')
|
||||
t.true(typeof result.earlyHours === 'boolean')
|
||||
t.truthy(result.exchanges)
|
||||
t.true(typeof result.exchanges.nasdaq === 'string')
|
||||
t.true(typeof result.exchanges.nyse === 'string')
|
||||
t.true(typeof result.exchanges.otc === 'string')
|
||||
t.true(typeof result.market === 'string')
|
||||
t.true(typeof result.serverTime === 'string')
|
||||
})
|
||||
|
||||
test('PolygonClient.previousClose', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
|
@ -45,3 +145,92 @@ test('PolygonClient.previousClose', async (t) => {
|
|||
t.truthy(result.ticker)
|
||||
t.is(result.ticker, 'AAPL')
|
||||
})
|
||||
|
||||
test('PolygonClient.rsi', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.rsi({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.true(Array.isArray(result.results.values))
|
||||
})
|
||||
|
||||
test('PolygonClient.sma', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.sma({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.true(Array.isArray(result.results.values))
|
||||
})
|
||||
|
||||
test('PolygonClient.tickerDetails', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.tickerDetails({ ticker: 'AAPL' })
|
||||
t.truthy(result.results)
|
||||
t.is(result.results.ticker, 'AAPL')
|
||||
})
|
||||
|
||||
test('PolygonClient.tickerNews', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
let result = await client.tickerNews({ ticker: 'AAPL', limit: 3 })
|
||||
t.truthy(result.status)
|
||||
t.true(Array.isArray(result.results))
|
||||
t.is(result.results.length, 3)
|
||||
|
||||
result = await client.tickerNews({ ticker: 'NFLX', limit: 1 })
|
||||
t.truthy(result.status)
|
||||
t.true(Array.isArray(result.results))
|
||||
t.is(result.results.length, 1)
|
||||
})
|
||||
|
||||
test('PolygonClient.tickerTypes', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.tickerTypes()
|
||||
t.is(typeof result.status, 'string', 'Status should be a string')
|
||||
t.is(typeof result.request_id, 'string', 'Request_id should be a string')
|
||||
t.is(typeof result.count, 'number', 'Count should be a number')
|
||||
})
|
||||
|
||||
test('PolygonClient.tickers', async (t) => {
|
||||
if (!process.env.POLYGON_API_KEY) {
|
||||
return t.pass()
|
||||
}
|
||||
|
||||
t.timeout(2 * 60 * 1000)
|
||||
const client = new PolygonClient({ ky })
|
||||
|
||||
const result = await client.tickers({
|
||||
ticker: 'AAPL',
|
||||
limit: 1
|
||||
})
|
||||
t.is(typeof result.status, 'string', 'Status should be a string')
|
||||
t.is(typeof result.request_id, 'string', 'Request_id should be a string')
|
||||
t.is(typeof result.count, 'number', 'Count should be a number')
|
||||
})
|
||||
|
|
Ładowanie…
Reference in New Issue