Class MarketPriceService
MarketPrice.- Version:
- 3.0.6
- Author:
- Stephen Prizio
-
Constructor Summary
ConstructorsConstructorDescriptionMarketPriceService(MarketPriceRepository marketPriceRepository, MarketPriceFetchRequestDispatchService marketPriceFetchRequestDispatchService, SymbolService symbolService, SymbolAliasService symbolAliasService, jakarta.persistence.EntityManager entityManager) Creates the service. -
Method Summary
Modifier and TypeMethodDescriptionCreates a newMarketPrice.booleandeleteMarketPrice(MarketPrice marketPrice) Deletes the givenMarketPrice.Returns the finest available market prices for the givenPosition, falling back to higher intervals when minute data is unavailable.findChartMarketDataForPosition(Position position) Returns the market price payload best suited to charting the givenPosition.findChartMarketPricesForPosition(Position position) Returns theMarketPrices best suited to charting the givenPosition.Looks up aMarketPriceby its uid.findMarketPricesForPosition(Position position, MarketTimeInterval timeInterval) findMarketPricesForSymbolAlias(SymbolAlias symbolAlias, MarketTimeInterval timeInterval) findMarketPricesForSymbolAlias(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end) Returns aListofMarketPrices for the givenSymbolAliasand interval, filtered by optional start and end bounds.findMarketPricesWithinTimespan(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end) Returns aListofMarketPrices for the given symbol and datasource, within the time span.queueSymbolAnalysisMarketPriceRefreshIfNeeded(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end, int requestedBars, List<MarketPrice> marketPrices) Queues a background refresh for symbol-analysis EOD prices when the stored window is empty, materially behind the requested end date, or shorter than the requested lookback.intsaveAllSet(Collection<MarketPrice> marketPrices) Saves allMarketPrices within the given set to the database.booleanSaves theMT4MarketDataasMarketPrices to the database.org.springframework.data.domain.Page<MarketPrice> searchMarketPrices(MarketPriceFilter filter, int page, int pageSize, org.springframework.data.domain.Sort sort) Returns a paginatedPageofMarketPrices matching the given filter.updateMarketPrice(MarketPrice marketPrice, CreateUpdateMarketPriceDTO data) Updates an existingMarketPrice.Methods inherited from class AbstractGenericEntityService
refreshEntity, resolveEntity, resolveEntity, resolveEntity
-
Constructor Details
-
MarketPriceService
public MarketPriceService(MarketPriceRepository marketPriceRepository, MarketPriceFetchRequestDispatchService marketPriceFetchRequestDispatchService, SymbolService symbolService, SymbolAliasService symbolAliasService, jakarta.persistence.EntityManager entityManager) Creates the service.- Parameters:
marketPriceRepository-MarketPriceRepositorymarketPriceFetchRequestDispatchService-MarketPriceFetchRequestDispatchServicesymbolService-SymbolServicesymbolAliasService-SymbolAliasServiceentityManager-EntityManager
-
-
Method Details
-
findMarketPriceByUid
Looks up aMarketPriceby its uid.- Parameters:
uid- uid- Returns:
OptionalMarketPrice
-
createNewMarketPrice
@Transactional @CacheEvict(cacheNames="symbolAnalysis", allEntries=true) public MarketPrice createNewMarketPrice(CreateUpdateMarketPriceDTO data) Creates a newMarketPrice.- Parameters:
data-CreateUpdateMarketPriceDTO- Returns:
- new
MarketPrice
-
updateMarketPrice
@Transactional @CacheEvict(cacheNames="symbolAnalysis", allEntries=true) public MarketPrice updateMarketPrice(MarketPrice marketPrice, CreateUpdateMarketPriceDTO data) Updates an existingMarketPrice.- Parameters:
marketPrice-MarketPricedata-CreateUpdateMarketPriceDTO- Returns:
- updated
MarketPrice
-
deleteMarketPrice
@Transactional @CacheEvict(cacheNames="symbolAnalysis", allEntries=true) public boolean deleteMarketPrice(MarketPrice marketPrice) Deletes the givenMarketPrice.- Parameters:
marketPrice-MarketPrice- Returns:
- true if deleted
-
findMarketPricesWithinTimespan
public List<MarketPrice> findMarketPricesWithinTimespan(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end) Returns aListofMarketPrices for the given symbol and datasource, within the time span.- Parameters:
symbolAlias-SymbolAliastimeInterval-MarketTimeIntervalstart-LocalDateTimeend-LocalDateTime- Returns:
ListofMarketPrice
-
findMarketPricesForSymbolAlias
public List<MarketPrice> findMarketPricesForSymbolAlias(SymbolAlias symbolAlias, MarketTimeInterval timeInterval) - Parameters:
symbolAlias-SymbolAliastimeInterval-MarketTimeInterval- Returns:
ListofMarketPrice
-
findMarketPricesForSymbolAlias
public List<MarketPrice> findMarketPricesForSymbolAlias(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end) Returns aListofMarketPrices for the givenSymbolAliasand interval, filtered by optional start and end bounds.- Parameters:
symbolAlias-SymbolAliastimeInterval-MarketTimeIntervalstart- optional start date time, inclusiveend- optional end date time, exclusive- Returns:
ListofMarketPrice
-
queueSymbolAnalysisMarketPriceRefreshIfNeeded
public String queueSymbolAnalysisMarketPriceRefreshIfNeeded(SymbolAlias symbolAlias, MarketTimeInterval timeInterval, LocalDateTime start, LocalDateTime end, int requestedBars, List<MarketPrice> marketPrices) Queues a background refresh for symbol-analysis EOD prices when the stored window is empty, materially behind the requested end date, or shorter than the requested lookback.Only
DataSource.EODaliases are eligible for automatic refresh from symbol analysis. MT4 and other data sources rely on their own ingestion flows.- Parameters:
symbolAlias-SymbolAliastimeInterval-MarketTimeIntervalstart- optional request startend- request end, exclusiverequestedBars- requested bar countmarketPrices- current stored market prices for the window- Returns:
- optional note describing the queued refresh
-
searchMarketPrices
public org.springframework.data.domain.Page<MarketPrice> searchMarketPrices(MarketPriceFilter filter, int page, int pageSize, org.springframework.data.domain.Sort sort) Returns a paginatedPageofMarketPrices matching the given filter.- Parameters:
filter-MarketPriceFilterpage- current pagepageSize- page sizesort-Sort- Returns:
PageofMarketPrice
-
findMarketPricesForPosition
public List<MarketPrice> findMarketPricesForPosition(Position position, MarketTimeInterval timeInterval) - Parameters:
position-PositiontimeInterval-MarketTimeInterval- Returns:
ListofMarketPrice
-
findBestAvailableMarketPricesForPosition
Returns the finest available market prices for the givenPosition, falling back to higher intervals when minute data is unavailable.- Parameters:
position-Position- Returns:
ListofMarketPrice
-
findChartMarketPricesForPosition
Returns theMarketPrices best suited to charting the givenPosition.The resolution is derived from the position's duration so that long-running positions are not rendered with an unmanageable number of fine-grained bars (e.g. a multi-day position will not use one-minute data). The finest interval whose estimated bar count stays within
CHART_TARGET_MAX_BARSis preferred, falling back to coarser (then finer) intervals when the preferred resolution has no stored data. When the resulting series is shorter thanCHART_MIN_BARS, the window is widened symmetrically around the position to provide context.- Parameters:
position-Position- Returns:
ListofMarketPrice, empty when no data is available
-
findChartMarketDataForPosition
Returns the market price payload best suited to charting the givenPosition.The response includes the resolved symbol alias, chosen interval, and any prices found for the chart window. When no prices are available the alias and preferred interval are still returned so callers can display metadata while a background fetch request is queued.
- Parameters:
position-Position- Returns:
PositionChartMarketData
-
saveAllSet
@Transactional @CacheEvict(cacheNames="symbolAnalysis", allEntries=true) public int saveAllSet(Collection<MarketPrice> marketPrices) Saves allMarketPrices within the given set to the database.- Parameters:
marketPrices-CollectionofMarketPrice- Returns:
- count of insertions/updates
-
saveMT4MarketPriceData
@Transactional @CacheEvict(cacheNames="symbolAnalysis", allEntries=true) public boolean saveMT4MarketPriceData(MT4MarketData data) Saves theMT4MarketDataasMarketPrices to the database.- Parameters:
data-MT4MarketData- Returns:
- true if the data was saved successfully
-