laplace-api
Advanced tools
Comparing version 1.0.13 to 1.1.0
{ | ||
"name": "laplace-api", | ||
"version": "1.0.13", | ||
"version": "1.1.0", | ||
"description": "Client library for Laplace API for the US stock market and BIST (Istanbul stock market) fundamental financial data.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,2 +28,10 @@ import { Client } from './client'; | ||
export enum HistoricalPriceInterval { | ||
OneMinute = "1m", | ||
FiveMinute = "5m", | ||
ThirtyMinute = "30m", | ||
OneHour = "1h", | ||
OneDay = "24h", | ||
} | ||
export interface Stock { | ||
@@ -38,3 +46,3 @@ id: string; | ||
dailyChange?: number; | ||
active?: boolean; | ||
active: boolean; | ||
} | ||
@@ -60,4 +68,17 @@ | ||
updatedDate: string; | ||
active: boolean; | ||
markets: Market[]; | ||
} | ||
export enum Market { | ||
Yildiz = "YILDIZ", | ||
Ana = "ANA", | ||
Alt = "ALT", | ||
YakinIzleme = "YAKIN_IZLEME", | ||
POIP = "POIP", | ||
Fon = "FON", | ||
Girisim = "GIRISIM", | ||
Emtia = "EMTIA", | ||
} | ||
export interface PriceDataPoint { | ||
@@ -83,2 +104,24 @@ d: number; | ||
export interface StockRestriction { | ||
id: number; | ||
title: string; | ||
description: string; | ||
startDate: string; | ||
endDate: string; | ||
} | ||
export interface TickRule { | ||
basePrice: number; | ||
additionalPrice: number; | ||
lowerPriceLimit: number; | ||
upperPriceLimit: number; | ||
rules: TickSizeRule[]; | ||
} | ||
export interface TickSizeRule { | ||
priceFrom: number; | ||
priceTo: number; | ||
tickSize: number; | ||
} | ||
export class StockClient extends Client { | ||
@@ -120,2 +163,37 @@ async getAllStocks(region: Region): Promise<Stock[]> { | ||
} | ||
} | ||
async getCustomHistoricalPrices(stock: string, region: Region, fromDate: string, toDate: string, interval: HistoricalPriceInterval, detail: boolean): Promise<PriceDataPoint[]> { | ||
this.validateCustomHistoricalPriceDate(fromDate); | ||
this.validateCustomHistoricalPriceDate(toDate); | ||
return this.sendRequest<PriceDataPoint[]>({ | ||
method: 'GET', | ||
url: '/api/v1/stock/price/interval', | ||
params: { stock, region, fromDate, toDate, interval, detail }, | ||
}); | ||
} | ||
async validateCustomHistoricalPriceDate(date: string) { | ||
const pattern = /^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$/; | ||
const matched = date.match(pattern); | ||
if (!matched) { | ||
throw new Error("Invalid date format, allowed formats: YYYY-MM-DD, YYYY-MM-DD HH:MM:SS"); | ||
} | ||
} | ||
async getStockRestrictions(symbol: string, region: Region): Promise<StockRestriction[]> { | ||
return this.sendRequest<StockRestriction[]>({ | ||
method: 'GET', | ||
url: '/api/v1/stock/restrictions', | ||
params: { symbol, region }, | ||
}); | ||
} | ||
async getTickRules(symbol: string, region: Region): Promise<TickRule> { | ||
return this.sendRequest<TickRule>({ | ||
method: 'GET', | ||
url: '/api/v1/stock/rules', | ||
params: { symbol, region }, | ||
}); | ||
} | ||
} |
import { Logger } from 'winston'; | ||
import { LaplaceConfiguration } from '../utilities/configuration'; | ||
import { StockClient, AssetClass, HistoricalPricePeriod } from '../client/stocks'; | ||
import { StockClient, AssetClass, HistoricalPricePeriod, HistoricalPriceInterval } from '../client/stocks'; | ||
import { Region, Locale } from '../client/collections'; | ||
@@ -51,2 +51,41 @@ import './client_test_suite'; | ||
}); | ||
}); | ||
test('GetCustomHistoricalPrices', async () => { | ||
let resp = await client.getCustomHistoricalPrices( | ||
"TUPRS", | ||
Region.Tr, | ||
"2024-01-01", | ||
"2024-03-01", | ||
HistoricalPriceInterval.OneDay, | ||
false | ||
); | ||
expect(resp).not.toBeEmpty(); | ||
for (const price of resp) { | ||
expect(price).not.toBeEmpty(); | ||
} | ||
resp = await client.getCustomHistoricalPrices( | ||
"SASA", | ||
Region.Tr, | ||
"2024-01-01 10:00:00", | ||
"2024-01-05 10:00:00", | ||
HistoricalPriceInterval.OneHour, | ||
true | ||
); | ||
expect(resp).not.toBeEmpty(); | ||
for (const price of resp) { | ||
expect(price).not.toBeEmpty(); | ||
} | ||
}); | ||
test('GetStockRestrictions', async () => { | ||
await client.getStockRestrictions("TUPRS", Region.Tr); | ||
}); | ||
test('GetTickRules', async () => { | ||
const resp = await client.getTickRules("TUPRS", Region.Tr); | ||
expect(resp).not.toBeEmpty(); | ||
}); | ||
}); |
54404
30
1472