Interface PositionRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Position,Long>, org.springframework.data.jpa.repository.JpaRepository<Position, Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<Position>, org.springframework.data.repository.ListCrudRepository<Position, Long>, org.springframework.data.repository.ListPagingAndSortingRepository<Position, Long>, org.springframework.data.repository.PagingAndSortingRepository<Position, Long>, org.springframework.data.repository.query.QueryByExampleExecutor<Position>, org.springframework.data.repository.Repository<Position, Long>
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<T> -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteBySymbol(Symbol symbol) Deletes all positions associated with the givenSymbol.booleanexistsByPositionNumber(long positionNumber) Returns whether the given position number already exists.findAllByAccount(Account account) Returns all positions for the givenAccount.findByAccountAndSourceSystemAndExternalPositionKey(Account account, String sourceSystem, String externalPositionKey) Returns an importedPositionby its external identity fields.findByIdAndAccount(Long id, Account account) findByPositionNumberAndAccount(long positionNumber, Account account) findClosedPositionsByAccount(Account account) Returns all closed positions for the given account.findClosedPositionsByAccounts(Collection<Account> accounts) findClosedPositionsWithinTimespan(Account account, LocalDateTime start, LocalDateTime end) Returns closed positions for the given account within the requested closed-time span.findOwnedByPositionNumber(String accountNumber, long positionNumber, Long userId) Returns a position owned by the given user.findOwnedDetailByPositionNumber(long positionNumber, String accountNumber, Long userId) Returns a position with the associations the detail payload requires, scoped to its account.findPositionsByAccountAndOpenState(Account account, boolean open) Returns positions for the given account filtered by open state.findPositionsForLedgerSnapshots(Account account, LocalDateTime start, LocalDateTime end) Returns positions and orders that can contribute pending realized results at a requested ledger snapshot.voidmigrateSymbol(Symbol previousSymbol, Symbol newSymbol, LocalDateTime modifiedAt) Migrates positions associated with oneSymbolto another.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
count, count, delete, delete, exists, exists, findAll, findAll, findAll, findAll, findAll, findBy, findBy, findOne, findOne, updateMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findAllByAccount
-
findPositionsForLedgerSnapshots
@EntityGraph(attributePaths="positionOrders") @Query("SELECT DISTINCT p\nFROM Position p\nWHERE p.account = :account\nAND p.positionOpened <= :end\nAND (p.positionClosed IS NULL OR p.positionClosed >= :start)\nORDER BY p.positionOpened ASC, p.id ASC\n") List<Position> findPositionsForLedgerSnapshots(@Param("account") Account account, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end) Returns positions and orders that can contribute pending realized results at a requested ledger snapshot.- Parameters:
account- account that owns the positionsstart- earliest requested snapshotend- latest requested snapshot- Returns:
- positions with their orders initialized
-
existsByPositionNumber
boolean existsByPositionNumber(long positionNumber) Returns whether the given position number already exists.- Parameters:
positionNumber- position number- Returns:
- true when taken
-
findByPositionNumberAndAccount
-
findOwnedByPositionNumber
@Query("SELECT p\nFROM Position p\nJOIN p.account a\nWHERE p.positionNumber = :positionNumber\n AND a.accountNumber = :accountNumber\n AND a.user.id = :userId\n AND a.portfolio.active = true\n") Optional<Position> findOwnedByPositionNumber(@Param("accountNumber") String accountNumber, @Param("positionNumber") long positionNumber, @Param("userId") Long userId) Returns a position owned by the given user. -
findOwnedDetailByPositionNumber
@EntityGraph(attributePaths={"account","strategy","symbol","positionOrders"}) @Query("SELECT p FROM Position p\nWHERE p.positionNumber = :positionNumber\n AND p.account.accountNumber = :accountNumber\n AND p.account.user.id = :userId\n AND p.account.portfolio.active = true\n") Optional<Position> findOwnedDetailByPositionNumber(@Param("positionNumber") long positionNumber, @Param("accountNumber") String accountNumber, @Param("userId") Long userId) Returns a position with the associations the detail payload requires, scoped to its account. -
findByIdAndAccount
-
findByAccountAndSourceSystemAndExternalPositionKey
-
findPositionsByAccountAndOpenState
@Query("SELECT p\nFROM Position p\nWHERE p.account = :account\nAND (\n (:open = true AND p.positionClosed IS NULL)\n OR (:open = false AND p.positionClosed IS NOT NULL)\n)\nORDER BY p.positionOpened DESC\n") List<Position> findPositionsByAccountAndOpenState(@Param("account") Account account, @Param("open") boolean open) Returns positions for the given account filtered by open state. -
findClosedPositionsWithinTimespan
@Query("SELECT p\nFROM Position p\nWHERE p.account = :account\nAND p.positionClosed IS NOT NULL\nAND p.positionClosed >= :start\nAND p.positionClosed < :end\nORDER BY p.positionClosed ASC, p.id ASC\n") List<Position> findClosedPositionsWithinTimespan(@Param("account") Account account, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end) Returns closed positions for the given account within the requested closed-time span. -
findClosedPositionsByAccount
-
findClosedPositionsByAccounts
@Query("SELECT p\nFROM Position p\nWHERE p.account IN :accounts\nAND p.positionClosed IS NOT NULL\nORDER BY p.positionClosed ASC, p.id ASC\n") List<Position> findClosedPositionsByAccounts(@Param("accounts") Collection<Account> accounts) - Parameters:
accounts-CollectionofAccounts- Returns:
ListofPositions
-
deleteBySymbol
-
migrateSymbol
@Modifying @Query("UPDATE Position p\nSET p.symbol = :newSymbol,\n p.modifiedAt = CASE\n WHEN p.createdAt > :modifiedAt THEN p.createdAt\n ELSE :modifiedAt\n END\nWHERE p.symbol = :previousSymbol\n") void migrateSymbol(@Param("previousSymbol") Symbol previousSymbol, @Param("newSymbol") Symbol newSymbol, @Param("modifiedAt") LocalDateTime modifiedAt) Migrates positions associated with oneSymbolto another.
-