Пример #1
0
 def getRepo(self,
             status='openclose',
             portfolio='all',
             custodian='all',
             repo_code='all',
             broker='all',
             has_hair_cut='all'):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     params = {
         "status": status,
         "portfolio": portfolio,
         "custodian": custodian,
         "repo_code": repo_code,
         "broker": broker,
         "has_hair_cut": has_hair_cut
     }
     v = AppValidatorFactory().get_validator("getRepo")
     #-- validate input fields
     if not v.validate(params):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     transactions = self.repo_transaction_services.query(params)
     return transactions
Пример #2
0
 def getUserTranIdsFromRepoName(self, repoName):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     params = {"repo_code": repoName}
     v = AppValidatorFactory().get_validator("getUserTranIdsFromRepoName")
     #-- validate input fields
     if not v.validate(params):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     transaction_ids = self.repo_transaction_services.getUserTranIdsFromRepoName(
         params)
     return transaction_ids
Пример #3
0
 def getRepoTransactionHistory(self, userTranId):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     params = {"transaction_id": userTranId}
     v = AppValidatorFactory().get_validator("getRepoTransactionHistory")
     #-- validate input fields
     if not v.validate(params):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     transaction_histories = self.repo_transaction_history_services.query(
         params)
     return transaction_histories
Пример #4
0
 def cancelRepoTransaction(self, transaction):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     v = AppValidatorFactory().get_validator("cancelRepoTransaction")
     #-- validate input fields
     if not v.validate(transaction):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     #-- create data model
     data_transaction = {"transaction_id": transaction["UserTranId1"]}
     self.repo_transaction_services.cancel(data_transaction)
     return 0
Пример #5
0
 def closeRepoTransaction(self, transaction):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     v = AppValidatorFactory().get_validator("closeRepoTransaction")
     #-- validate input fields
     if not v.validate(transaction):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     #-- data parsing
     #-- maturity_date
     maturity_date = transaction["ActualSettleDate"][0:10]
     #-- create data model
     data_transaction = {
         "transaction_id": transaction["UserTranId1"],
         "maturity_date": maturity_date
     }
     self.repo_transaction_services.close(data_transaction)
     return 0
Пример #6
0
 def addRepoMaster(self, master):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     v = AppValidatorFactory().get_validator("addRepoMaster")
     if not v.validate(master):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     #-- data parsing
     accrualDaysPerMonth = master["AccrualDaysPerMonth"]
     if master["AccrualDaysPerMonth"].lower() == "actual":
         accrualDaysPerMonth = "ACT"
     accrualDaysPerYear = master["AccrualDaysPerYear"]
     if master["AccrualDaysPerYear"].lower() == "actual":
         accrualDaysPerYear = "ACT"
     #-- create data model
     data_master = {
         "code": master["Code"],
         "currency": master["BifurcationCurrency"],
         "date_count": accrualDaysPerMonth + "/" + accrualDaysPerYear
     }
     self.repo_master_services.create(data_master)
     return 0
Пример #7
0
 def addRepoTransaction(self, transaction):
     if self.dbmode is None:
         raise DataStoreNotYetInitializeError(
             "Plase call initializeDatastore to initialize datastore")
     v = AppValidatorFactory().get_validator("addRepoTransaction")
     #-- validate input fields
     if not v.validate(transaction):
         message = "Input validation error. Details: " + str(v.errors)
         self.logger.error(message)
         raise ValueError(message)
     #-- data parsing
     #-- get transaction_type
     transaction_type = ""
     if transaction["TransactionType"] == "Repo_InsertUpdate":
         transaction_type = "RP"
     elif transaction["TransactionType"] == "ReverseRepo_InsertUpdate":
         transaction_type = "RR"
     else:
         message = "Ipput validation error. TransactionType must be either Repo_InsertUpdate or ReverseRepo_InsertUpdate"
         self.logger.error(message)
         raise InvalidRepoTransactionTypeError(message)
     #-- get collaterial type and id
     investment_split = transaction["Investment"].split("=", 1)
     collateral_id_type = investment_split[0].upper()
     collateral_id = investment_split[1]
     is_open_repo = 0
     #-- is_open_repo
     if "OpenEnded" in transaction and transaction["OpenEnded"].lower(
     ) == "calc":
         is_open_repo = 1
     #-- maturity_date
     maturity_date = ""
     if transaction["ActualSettleDate"].lower() == "calc":
         if is_open_repo:
             maturity_date = ""
         else:
             maturity_date = "ERROR"
     else:
         maturity_date = transaction["ActualSettleDate"][0:10]
     #-- create data model
     data_transaction = {
         "transaction_id": transaction["UserTranId1"],
         "transaction_type": transaction_type,
         "portfolio": transaction["Portfolio"],
         "custodian": transaction["LocationAccount"],
         "collateral_id_type": collateral_id_type,
         "collateral_id": collateral_id,
         "collateral_global_id": "",
         "trade_date": transaction["EventDate"][0:10],
         "settle_date": transaction["SettleDate"][0:10],
         "is_open_repo": is_open_repo,
         "maturity_date": maturity_date,
         "quantity": float(transaction["Quantity"]),
         "currency": transaction["CounterInvestment"],
         "price": float(transaction["Price"]),
         "collateral_value": float(transaction["NetCounterAmount"]),
         "repo_code": transaction["RepoName"],
         "interest_rate": float(transaction["Coupon"]),
         "loan_amount": float(transaction["LoanAmount"]),
         "broker": transaction["Broker"],
         "haircut": 0,
         "status": Constants.REPO_TRANS_HISTORY_ACTION_OPEN
     }
     #-- add to repo_transaction and repo_transaction_history
     self.repo_transaction_services.create(data_transaction)
     return 0