Package cloud.metaapi.sdk.meta_api
Class HistoryFileManager
- java.lang.Object
-
- cloud.metaapi.sdk.meta_api.HistoryFileManager
-
public class HistoryFileManager extends Object
History storage file manager which saves and loads history on disk
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHistoryFileManager.HistoryClass to store history deals and orders
-
Field Summary
Fields Modifier and Type Field Description protected intupdateJobIntervalInMillisecondsDefines interval between update jobs.
-
Constructor Summary
Constructors Constructor Description HistoryFileManager(String accountId, HistoryStorage historyStorage)Constructs the history file manager instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Void>deleteStorageFromDisk()Deletes storage files from diskCompletableFuture<HistoryFileManager.History>getHistoryFromDisk()Retrieves history from saved fileintgetItemSize(Object item)Helper function to calculate object size in bytes in utf-8 encodingvoidsetStartNewDealIndex(int index)Sets the index of the earliest changed deal recordvoidsetStartNewOrderIndex(int index)Sets the index of the earliest changed historyOrder recordvoidstartUpdateJob()Starts a job to periodically save history on diskvoidstopUpdateJob()Stops a job to periodically save history on diskCompletableFuture<Void>updateDiskStorage()Saves unsaved history items to disk storage
-
-
-
Constructor Detail
-
HistoryFileManager
public HistoryFileManager(String accountId, HistoryStorage historyStorage)
Constructs the history file manager instance- Parameters:
accountId- accound idhistoryStorage- history storage
-
-
Method Detail
-
startUpdateJob
public void startUpdateJob()
Starts a job to periodically save history on disk
-
stopUpdateJob
public void stopUpdateJob()
Stops a job to periodically save history on disk
-
getItemSize
public int getItemSize(Object item) throws com.fasterxml.jackson.core.JsonProcessingException
Helper function to calculate object size in bytes in utf-8 encoding- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
setStartNewOrderIndex
public void setStartNewOrderIndex(int index)
Sets the index of the earliest changed historyOrder record- Parameters:
index- of the earliest changed record
-
setStartNewDealIndex
public void setStartNewDealIndex(int index)
Sets the index of the earliest changed deal record- Parameters:
index- of the earliest changed record
-
getHistoryFromDisk
public CompletableFuture<HistoryFileManager.History> getHistoryFromDisk()
Retrieves history from saved file- Returns:
- completable future resolving with history of deals and orders
-
updateDiskStorage
public CompletableFuture<Void> updateDiskStorage()
Saves unsaved history items to disk storage- Returns:
- completable future which resolves when disk storage is updated
-
deleteStorageFromDisk
public CompletableFuture<Void> deleteStorageFromDisk()
Deletes storage files from disk- Returns:
- completable future which resolves when the storage is deleted
-
-