|
| 1 | +import { IGet, IPolygonQuery, IRequestOptions, getWithGlobals } from "../transport/request.js"; |
| 2 | + |
| 3 | +// ### Futures Aggregates |
| 4 | +export interface IFuturesAggsQuery extends IPolygonQuery { |
| 5 | + resolution?: string; |
| 6 | + "window_start"?: string; |
| 7 | + "window_start.gt"?: string; |
| 8 | + "window_start.gte"?: string; |
| 9 | + "window_start.lt"?: string; |
| 10 | + "window_start.lte"?: string; |
| 11 | + order?: "asc" | "desc"; |
| 12 | + limit?: number; |
| 13 | + sort?: string; |
| 14 | +} |
| 15 | + |
| 16 | +export interface IFuturesAgg { |
| 17 | + ticker: string; |
| 18 | + open: number; |
| 19 | + high: number; |
| 20 | + low: number; |
| 21 | + close: number; |
| 22 | + volume: number; |
| 23 | + window_start: number; |
| 24 | + window_end: number; |
| 25 | +} |
| 26 | + |
| 27 | +export interface IFuturesAggs { |
| 28 | + status: string; |
| 29 | + request_id: string; |
| 30 | + results?: IFuturesAgg[]; |
| 31 | +} |
| 32 | + |
| 33 | +export const listFuturesAggs = async ( |
| 34 | + get: IGet, |
| 35 | + ticker: string, |
| 36 | + query?: IFuturesAggsQuery, |
| 37 | + options?: IRequestOptions |
| 38 | +): Promise<IFuturesAggs> => |
| 39 | + get(`/futures/vX/aggs/${ticker}`, query, options); |
| 40 | + |
| 41 | +// ### Futures Contracts |
| 42 | +export interface IFuturesContract { |
| 43 | + ticker: string; |
| 44 | + name: string; |
| 45 | + product_code: string; |
| 46 | + expiration_date: string; |
| 47 | +} |
| 48 | + |
| 49 | +export interface IFuturesContracts { |
| 50 | + status: string; |
| 51 | + request_id: string; |
| 52 | + results?: IFuturesContract[]; |
| 53 | +} |
| 54 | + |
| 55 | +export const listFuturesContracts = async ( |
| 56 | + get: IGet, |
| 57 | + query?: IPolygonQuery, |
| 58 | + options?: IRequestOptions |
| 59 | +): Promise<IFuturesContracts> => |
| 60 | + get(`/futures/vX/contracts`, query, options); |
| 61 | + |
| 62 | +export const getFuturesContract = async ( |
| 63 | + get: IGet, |
| 64 | + ticker: string, |
| 65 | + options?: IRequestOptions |
| 66 | +): Promise<IFuturesContract> => |
| 67 | + get(`/futures/vX/contracts/${ticker}`, undefined, options); |
| 68 | + |
| 69 | +// ### Futures Market Status |
| 70 | +export interface IFuturesMarketStatus { |
| 71 | + status: string; |
| 72 | + timestamp: number; |
| 73 | +} |
| 74 | + |
| 75 | +export const listFuturesMarketStatuses = async ( |
| 76 | + get: IGet, |
| 77 | + options?: IRequestOptions |
| 78 | +): Promise<IFuturesMarketStatus> => |
| 79 | + get(`/futures/vX/market-status`, undefined, options); |
| 80 | + |
| 81 | +// ### Futures Products |
| 82 | +export interface IFuturesProduct { |
| 83 | + product_code: string; |
| 84 | + name: string; |
| 85 | + description?: string; |
| 86 | +} |
| 87 | + |
| 88 | +export interface IFuturesProducts { |
| 89 | + status: string; |
| 90 | + request_id: string; |
| 91 | + results?: IFuturesProduct[]; |
| 92 | +} |
| 93 | + |
| 94 | +export const listFuturesProducts = async ( |
| 95 | + get: IGet, |
| 96 | + query?: IPolygonQuery, |
| 97 | + options?: IRequestOptions |
| 98 | +): Promise<IFuturesProducts> => |
| 99 | + get(`/futures/vX/products`, query, options); |
| 100 | + |
| 101 | +export const getFuturesProduct = async ( |
| 102 | + get: IGet, |
| 103 | + product_code: string, |
| 104 | + options?: IRequestOptions |
| 105 | +): Promise<IFuturesProduct> => |
| 106 | + get(`/futures/vX/products/${product_code}`, undefined, options); |
| 107 | + |
| 108 | +// ### Futures Schedules |
| 109 | +export interface IFuturesSchedule { |
| 110 | + product_code?: string; |
| 111 | + start_date: string; |
| 112 | + end_date: string; |
| 113 | + open_time: string; |
| 114 | + close_time: string; |
| 115 | +} |
| 116 | + |
| 117 | +export interface IFuturesSchedules { |
| 118 | + status: string; |
| 119 | + request_id: string; |
| 120 | + results?: IFuturesSchedule[]; |
| 121 | +} |
| 122 | + |
| 123 | +export const listFuturesSchedules = async ( |
| 124 | + get: IGet, |
| 125 | + query?: IPolygonQuery, |
| 126 | + options?: IRequestOptions |
| 127 | +): Promise<IFuturesSchedules> => |
| 128 | + get(`/futures/vX/schedules`, query, options); |
| 129 | + |
| 130 | +export const listFuturesProductSchedules = async ( |
| 131 | + get: IGet, |
| 132 | + product_code: string, |
| 133 | + query?: IPolygonQuery, |
| 134 | + options?: IRequestOptions |
| 135 | +): Promise<IFuturesSchedules> => |
| 136 | + get(`/futures/vX/products/${product_code}/schedules`, query, options); |
| 137 | + |
| 138 | +// ### Futures Trades |
| 139 | +export interface IFuturesTrade { |
| 140 | + price: number; |
| 141 | + size: number; |
| 142 | + timestamp: number; |
| 143 | +} |
| 144 | + |
| 145 | +export interface IFuturesTrades { |
| 146 | + next_url?: string; |
| 147 | + request_id?: string; |
| 148 | + results?: IFuturesTrade[]; |
| 149 | + status?: string; |
| 150 | +} |
| 151 | + |
| 152 | +export const listFuturesTrades = async ( |
| 153 | + get: IGet, |
| 154 | + ticker: string, |
| 155 | + query?: IPolygonQuery, |
| 156 | + options?: IRequestOptions |
| 157 | +): Promise<IFuturesTrades> => |
| 158 | + get(`/futures/vX/trades/${ticker}`, query, options); |
| 159 | + |
| 160 | +// ### Futures Quotes |
| 161 | +export interface IFuturesQuote { |
| 162 | + ask_price: number; |
| 163 | + ask_size: number; |
| 164 | + bid_price: number; |
| 165 | + bid_size: number; |
| 166 | + timestamp: number; |
| 167 | +} |
| 168 | + |
| 169 | +export interface IFuturesQuotes { |
| 170 | + next_url?: string; |
| 171 | + request_id?: string; |
| 172 | + results?: IFuturesQuote[]; |
| 173 | + status?: string; |
| 174 | +} |
| 175 | + |
| 176 | +export const listFuturesQuotes = async ( |
| 177 | + get: IGet, |
| 178 | + ticker: string, |
| 179 | + query?: IPolygonQuery, |
| 180 | + options?: IRequestOptions |
| 181 | +): Promise<IFuturesQuotes> => |
| 182 | + get(`/futures/vX/quotes/${ticker}`, query, options); |
| 183 | + |
| 184 | +// ### Futures Client Interface |
| 185 | +export interface IFuturesClient { |
| 186 | + listFuturesAggs: ( |
| 187 | + ticker: string, |
| 188 | + query?: IFuturesAggsQuery, |
| 189 | + options?: IRequestOptions |
| 190 | + ) => Promise<IFuturesAggs>; |
| 191 | + listFuturesContracts: ( |
| 192 | + query?: IPolygonQuery, |
| 193 | + options?: IRequestOptions |
| 194 | + ) => Promise<IFuturesContracts>; |
| 195 | + getFuturesContract: ( |
| 196 | + ticker: string, |
| 197 | + options?: IRequestOptions |
| 198 | + ) => Promise<IFuturesContract>; |
| 199 | + listFuturesMarketStatuses: ( |
| 200 | + options?: IRequestOptions |
| 201 | + ) => Promise<IFuturesMarketStatus>; |
| 202 | + listFuturesProducts: ( |
| 203 | + query?: IPolygonQuery, |
| 204 | + options?: IRequestOptions |
| 205 | + ) => Promise<IFuturesProducts>; |
| 206 | + getFuturesProduct: ( |
| 207 | + product_code: string, |
| 208 | + options?: IRequestOptions |
| 209 | + ) => Promise<IFuturesProduct>; |
| 210 | + listFuturesSchedules: ( |
| 211 | + query?: IPolygonQuery, |
| 212 | + options?: IRequestOptions |
| 213 | + ) => Promise<IFuturesSchedules>; |
| 214 | + listFuturesProductSchedules: ( |
| 215 | + product_code: string, |
| 216 | + query?: IPolygonQuery, |
| 217 | + options?: IRequestOptions |
| 218 | + ) => Promise<IFuturesSchedules>; |
| 219 | + listFuturesTrades: ( |
| 220 | + ticker: string, |
| 221 | + query?: IPolygonQuery, |
| 222 | + options?: IRequestOptions |
| 223 | + ) => Promise<IFuturesTrades>; |
| 224 | + listFuturesQuotes: ( |
| 225 | + ticker: string, |
| 226 | + query?: IPolygonQuery, |
| 227 | + options?: IRequestOptions |
| 228 | + ) => Promise<IFuturesQuotes>; |
| 229 | +} |
| 230 | + |
| 231 | +// ### Futures Client Factory |
| 232 | +export const futuresClient = ( |
| 233 | + apiKey: string, |
| 234 | + apiBase = "https://api.polygon.io", |
| 235 | + options?: IRequestOptions |
| 236 | +): IFuturesClient => { |
| 237 | + const get = getWithGlobals(apiKey, apiBase, options); |
| 238 | + return { |
| 239 | + listFuturesAggs: (...args) => listFuturesAggs(get, ...args), |
| 240 | + listFuturesContracts: (...args) => listFuturesContracts(get, ...args), |
| 241 | + getFuturesContract: (...args) => getFuturesContract(get, ...args), |
| 242 | + listFuturesMarketStatuses: (...args) => listFuturesMarketStatuses(get, ...args), |
| 243 | + listFuturesProducts: (...args) => listFuturesProducts(get, ...args), |
| 244 | + getFuturesProduct: (...args) => getFuturesProduct(get, ...args), |
| 245 | + listFuturesSchedules: (...args) => listFuturesSchedules(get, ...args), |
| 246 | + listFuturesProductSchedules: (...args) => listFuturesProductSchedules(get, ...args), |
| 247 | + listFuturesTrades: (...args) => listFuturesTrades(get, ...args), |
| 248 | + listFuturesQuotes: (...args) => listFuturesQuotes(get, ...args), |
| 249 | + }; |
| 250 | +}; |
| 251 | + |
| 252 | +export default futuresClient; |
0 commit comments