Exemple #1
0
 def validations(self):
     if self.for_date - datetime.datetime.utcnow().date(
     ) != datetime.timedelta(days=2):
         raise ValidationError(
             "for_date and created_at date difference should be equal to two days"
         )
     if self.currency not in BetModel.CRYPTO_CURRENCIES:
         raise ValidationError("Invalid currency")
Exemple #2
0
 def validations(self):
     if self.min_estimate_value >= self.max_estimate_value:
         raise ValidationError("Minimum can't be less than or equal to max")
     difference_in_est = 100 - (self.min_estimate_value /
                                self.max_estimate_value) * 100
     if difference_in_est > 3 or difference_in_est < -3:
         raise ValidationError(
             "Percentage difference between max and min cannot be more than 0.5 %"
         )
     if self.status not in UserBidModel.STATUS:
         raise ValidationError("status has to be one of ".join(
             [str(x) for x in UserBidModel.STATUS]))
     if self.has_claimed is True and not self.status == UserBidModel.WON:
         raise ValidationError("Invalid has_claimed value")
Exemple #3
0
 def executable(*args, **kwargs):
     try:
         if "ETH-Password" in request.headers:
             eth_password = request.headers['ETH-Password']
         else:
             try:
                 eth_password = request.json.get("eth_password", "")
             except BadRequest:
                 eth_password = ""
         if not eth_password.strip():
             raise ValidationError(
                 "eth_password should be present in either json or in headers as ETH-Password"
             )
         eth_account_key = current_identity.blockchain_account_key
         w3.personal.unlockAccount(eth_account_key, eth_password)  # pylint: disable= no-member
         LOGGER.info("Unlocked eth account..")
         response = func(*args, **kwargs)
         w3.personal.lockAccount(eth_account_key)  # pylint: disable= no-member
         LOGGER.info("Locked eth account..")
         return response
     except (ValidationError, ValueError) as error:
         LOGGER.error(error, exc_info=True)
         return jsonify({"message": str(error)}), 400
     except Exception as error:
         LOGGER.error(error, exc_info=True)
         return jsonify({
             "payload": {},
             "message": "Internal Server Error"
         }), 500
Exemple #4
0
 def destroy(self):
     try:
         db.session.delete(self)
         db.session.commit()
     except SQLAlchemyError as e:
         db.session.rollback()
         raise ValidationError(str(e))
Exemple #5
0
    def get_crypto_exchange_rate_on_date(cls, for_date, crypto_currency):
        if not isinstance(for_date, datetime.date):
            raise ValidationError("for_date is not of type date")
        if crypto_currency not in cls.CURRENCY_KEY_WORD_MAP.keys():
            raise ValidationError("invalid value for crypto_currency")
        timestamp = int(time.mktime(for_date.timetuple()))

        LOGGER.info("Requesting url {} for time_stamp {}".format(
            cls.DAY_API, str(for_date)))

        return requests.get(cls.DAY_API,
                            params={
                                "ts": timestamp,
                                "tsyms": "USD",
                                "fsym":
                                cls.CURRENCY_KEY_WORD_MAP[crypto_currency]
                            })
Exemple #6
0
 def save(self):
     session = db.session.begin_nested()
     self.pre_save()
     try:
         db.session.add(self)
         session.commit()
     except SQLAlchemyError as e:
         db.session.rollback()
         raise ValidationError(str(e))
Exemple #7
0
 def schedule(self):
     scheduler = BackgroundScheduler()
     if not getattr(self.__class__, "PAUSE", False):
         if self.__class__.MINUTES < 30:
             raise ValidationError("Minutes can not be less than 30")
         job = scheduler.add_job(self.commit_task,
                                 'interval',
                                 minutes=self.__class__.MINUTES)
         scheduler.start()
         LOGGER.info("Scheduled task {} with a period of {} minutes".format(
             self.__class__.__name__, self.__class__.MINUTES))
Exemple #8
0
    def get_time_range_data(cls, to_date, crypto_currency):
        if not isinstance(to_date, datetime.date):
            raise ValidationError(
                "from_date and to_date should be of type date")
        if crypto_currency not in cls.CURRENCY_KEY_WORD_MAP.keys():
            raise ValidationError("invalid value for crypto_currency")
        to_timestamp = int(time.mktime(to_date.timetuple()))

        LOGGER.info("Requesting url {} for time_stamp {}".format(
            cls.DAY_API, str(to_date)))

        return requests.get(cls.PERIODIC_DAY_API,
                            params={
                                "tsym": "USD",
                                "fsym":
                                cls.CURRENCY_KEY_WORD_MAP[crypto_currency],
                                "limit": 30,
                                "aggregate": 1,
                                "toTs": to_timestamp
                            })
Exemple #9
0
 def update(self, **kwargs):
     for attr, value in kwargs.items():
         setattr(self, attr, value)
     # TODO enable this
     #self.validations()
     session = db.session.begin_nested()
     try:
         db.session.add(self)
         session.commit()
     except SQLAlchemyError as e:
         session.rollback()
         raise ValidationError(str(e))
Exemple #10
0
    def _create_user_account(self, eth_password):
        try:
            account_address = w3.personal.newAccount(eth_password)

            w3.personal.unlockAccount(app.config["ADMIN_ETH_ACCOUNT"],
                                      app.config["ADMIN_ETH_PASSWORD"])

            w3.eth.sendTransaction({
                'to':
                account_address,
                'from':
                app.config.get('ADMIN_ETH_ACCOUNT'),
                'value':
                w3.toWei(app.config['INITIAL_BALANCE'], "ether")
            })

            w3.personal.unlockAccount(account_address, eth_password)

            return account_address

        except ValueError as e:
            raise ValidationError(str(e))
Exemple #11
0
 def validations(self):
     if len(self.password) < 8:
         raise ValidationError(
             "Password length cannot be less than 8 characters")