UNPKG

@airnub/unusualwhales-api-client

Version:

A client library for interacting with the UnusualWhales API, written in TypeScript

274 lines (273 loc) 10.2 kB
"use strict"; // Copyright (c) 2023 Airnub Technologies LTD. All rights reserved. // Licensed under the MIT License. See LICENSE file in the project root for full license information. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StockApi = void 0; class StockApi { constructor(axiosInstance) { this.axiosInstance = axiosInstance; } /** * Analyst Rating * Returns the latest analyst rating for the given ticker. * @param ticker (Required) */ getAnalystsRating(ticker) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/analysts`, { params: {}, }); return response.data; } catch (error) { console.error('Error fetching getAnalysts:', error); throw error; } }); } /** * Greek Exposure * The daily sum of the option greeks based on open contracts. Popular greek exposure values include gamma (GEX) and delta (DEX). * @param ticker (Required) * @param date (Optional) Default last trading date * @param timeframe (Optional) The timeframe of the data to return. Default 1Y Can be one of the following formats: - YTD - 1D, 2D, etc. - 1W, 2W, etc. - 1M, 2M, etc. - 1Y, 2Y, etc. */ getGreekExposure(ticker, date, timeframe) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/greek-exposure`, { params: { date, timeframe, }, }); return response.data; } catch (error) { console.error('Error fetching getGreekExposure:', error); throw error; } }); } /** * Information * Returns a information about the given ticker. * @param ticker (Required) */ getInfo(ticker) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/info`, { params: {}, }); return response.data; } catch (error) { console.error('Error fetching getInfo:', error); throw error; } }); } /** * Net Premium Ticks * Returns the net premium ticks for a given ticker. Each tick is resembling the data for a single minute tick. * @param ticker (Required) * @param date (Optional) */ getNetPremiumTicks(ticker, date) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/net-prem-ticks`, { params: { date, }, }); return response.data; } catch (error) { console.error('Error fetching getNetPremTicks:', error); throw error; } }); } /** * OHLC * Returns the Open High Low Close (OHLC) candle data for a given ticker. Results are limitted to 2,500 elements even if there are more available. * @param ticker (Required) * @param candle_size The duration of the candle. (Required) * @param timeframe The timeframe of the data to return. (Optional) Default 1Y Can be one of the following formats: - YTD - 1D, 2D, etc. - 1W, 2W, etc. - 1M, 2M, etc. - 1Y, 2Y, etc. */ getOHLC(ticker, candle_size, timeframe) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/ohlc/${candle_size}`, { params: { timeframe, }, }); return response.data; } catch (error) { console.error('Error fetching get{candle_size}:', error); throw error; } }); } /** * Option Chains * Returns all option symbols for the given ticker. * You can use the following regex to extract underlying ticker, option type, expiry & strike: * `^(?<symbol>[\w]*)(?<expiry>(\d{2})(\d{2})(\d{2}))(?<type>[PC])(?<strike>\d{8})$` * Keep in mind that the strike needs to be divided by 1,000. * @param ticker (Required) */ getOptionChains(ticker) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/option-chains`, { params: {}, }); return response.data; } catch (error) { console.error('Error fetching getOptionChains:', error); throw error; } }); } /** * Option Price Levels * Returns the call and put volume per price level for the given ticker. ---- Can be used to build a chart such as following: ![Option Price Level chart](https://i.imgur.com/y6BZ4sG.png) * @param ticker (Required) * @param date (Optional) */ getStockPriceLevels(ticker, date) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/option/stock-price-levels`, { params: { date, }, }); return response.data; } catch (error) { console.error('Error fetching getStockPriceLevels:', error); throw error; } }); } /** * Volume & OI per Expiry * Returns the total volume and open interest per expiry for the given ticker. * @param ticker (Required) * @param date (Optional) */ getVolumeOiExpiry(ticker, date) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/option/volume-oi-expiry`, { params: { date, }, }); return response.data; } catch (error) { console.error('Error fetching getVolumeOiEpxiry:', error); throw error; } }); } /** * Options Volume * Returns the options volume & premium for all trade executions that happened on a given trading date for the given ticker. * @param ticker (Required) * @param limit (Optional) Number of items to return. Default: 1. Max: 500. */ getOptionsVolume(ticker, limit) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/options-volume`, { params: { limit, }, }); return response.data; } catch (error) { console.error('Error fetching getOptionsVolume:', error); throw error; } }); } /** * Off/Lit Price Levels * Returns the lit & off lit stock volume per price level for the given ticker. * Important: The volume does **NOT** represent the full market dialy volume. * It only represents the volume of executed trades on exchanges operated by Nasdaq and FINRA off lit exchanges. * @param ticker (Required) * @param date (Optional) */ getStockVolumePriceLevels(ticker, date) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/stock-volume-price-levels`, { params: { date, }, }); return response.data; } catch (error) { console.error('Error fetching getStockVolumePriceLevels:', error); throw error; } }); } /** * Implied Volatility Term Structure * The average of the latest volatilities for the at the money call and put contracts for every expiry date. * @param ticker (Required) * @param date (Optional) */ getTermStructure(ticker, date) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield this.axiosInstance.get(`/api/stock/${ticker}/volatility/term-structure`, { params: { date, }, }); return response.data; } catch (error) { console.error('Error fetching getTermStructure:', error); throw error; } }); } } exports.StockApi = StockApi;