Example #1
0
    def put(self):
        """
        The update Exchanges endpoint method
        :data_example:{"leverage": 11, "balance_percentage": 50, "id":"1"}
        :return: status code
        """
        json_data = request.get_json()
        if 'id' not in json_data:
            return 'ID is not in request', 400
        current_sm = StockMarket.query.filter_by(id=json_data['id']).first()
        if not current_sm:
            return "Stock Market with current id is not found", 204
        action = ""
        if 'balance_percentage' in json_data:
            balance_percentage = check_0_max(json_data['balance_percentage'], 100)
            if balance_percentage != current_sm.balance_percentage:
                action += "Balance percentage for {2} was changed from {0} to {1}.\n".format(
                    current_sm.balance_percentage, balance_percentage, current_sm.name)
                current_sm.balance_percentage = balance_percentage

        if 'leverage' in json_data:
            leverage = check_0_max(json_data['leverage'], current_sm.max_leverage)
            if leverage != current_sm.leverage:
                action += "Leverage for {2} was changed from {0} to {1}.".format(
                    current_sm.leverage, leverage, current_sm.name)
                current_sm.leverage = leverage

        current_sm.save()
        create_action_log(action, "Exchanges")
        return Response(status=200)
Example #2
0
 def post(self):
     data = request.json
     if "email" not in data:
         return "Email not in request", 422
     if BaseConfig.DEFAULT_EMAIL_DOMAIN not in data['email']:
         return "Invalid email", 422
     if User.query.filter_by(email=data['email']).first():
         return "User with this email already exists.", 409
     new_user = User(email=data['email'])
     if "first_name" in data:
         new_user.first_name = data['first_name']
     if "last_name" in data:
         new_user.last_name = data['last_name']
     if "owner" in data['role']:
         new_user.add_role("owner")
         action = "Added {0} as owner.".format(data['email'])
     else:
         for each in data['role']:
             if not bool(UserRole.query.filter_by(role_name=each).first()):
                 role = UserRole(role_name=each)
                 role.save()
             new_user.add_role(each)
         action = "Added {0} as admin with access to {1}.".format(
             data['email'], ", ".join(new_user.get_user_roles_names_list))
     new_user.save()
     create_action_log(action, "UsersManagement")
     return 200
Example #3
0
 def delete(self):
     data = request.json
     stock_market = get_by_id(cls=StockMarket,
                              object_id=data['stock_market_id'])
     stock_market.is_terminate_all_required = True
     stock_market.save()
     create_action_log("Terminated all orders", data['screen'])
     return 200
Example #4
0
 def delete(self):
     args = request.args
     if "ids" not in args:
         return "ID not in request", 422
     for each in args.getlist("ids"):
         del_email = NotificationEmail.query.filter_by(id=each).first()
         del_email.delete()
         create_action_log("Removed {0}.".format(args['email']),
                           "Notifications")
     return 200
Example #5
0
 def delete(self):
     """
     Method to stop trading
     :return:
     """
     data = request.json
     stock_market = get_by_id(StockMarket, data['stock_market_id'])
     stock_market.is_trading_active = False
     stock_market.save()
     create_action_log("Stopped Trading", data['screen'])
     return 200
Example #6
0
 def post(self):
     """
     Method to start trading
     :return:
     """
     data = request.json
     stock_market = get_by_id(StockMarket, data['stock_market_id'])
     stock_market.is_trading_active = True
     stock_market.save()
     create_action_log("Started Trading", data['screen'])
     return 200
Example #7
0
 def post(self):
     data = request.json
     if "email" not in data:
         return "Email not in request", 422
     if BaseConfig.DEFAULT_EMAIL_DOMAIN not in data['email']:
         return "Invalid email", 422
     if NotificationEmail.query.filter_by(email=data['email']).first():
         return "User with this email already exists.", 409
     notif_email = NotificationEmail(email=data['email'])
     notif_email.save()
     create_action_log("Added {0}.".format(data['email']), "Notifications")
     return 200
Example #8
0
 def delete(self):
     """
     Delete endpoint method
     Remove from db Stock Market object by it's name
     :data_example:{"id":"1"}
     :return: status
     """
     json_data = request.get_json()
     try:
         delete_sm = StockMarket.query.filter_by(id=json_data['id']).first()
         create_action_log("{0} was removed".format(delete_sm.name), "Exchanges")
         delete_sm.delete()
         return Response(status=204)
     except:
         BadRequest(description="Can't delete the object with current name or id")
Example #9
0
    def put(self):
        """
        Method for updating info about user
        :return:
        """
        data = request.json
        try:
            edit_user = get_by_id(User, data['id'])
        except:
            BadRequest("ID not found in request")
        action = ""
        if "email" in data:
            action = "Updated email from {0} to {1} for {2}.".format(
                edit_user.email, data['email'], edit_user.full_name)
            edit_user.email = data['email']

        if "first_name" in data:
            action = "Updated first name from {0} to {1} for {2}.".format(
                edit_user.first_name, data['first_name'], edit_user.email)
            edit_user.first_name = data['first_name']
        if "last_name" in data:
            action = "Updated last name from {0} to {1} for {2}.".format(
                edit_user.last_name, data['last_name'], edit_user.email)
            edit_user.last_name = data['last_name']
        if "first_name" in data or "last_name" in data:
            edit_user.full_name = edit_user.get_full_name()
        edit_user.save()

        if "roles" in data:
            action = "Updated rights from {0} to {1} for {2}.".format(
                ", ".join(edit_user.get_user_roles_names_list),
                ", ".join(data['roles']), edit_user.full_name)
            for role in data['roles']:
                edit_user.add_role(role)
        create_action_log(action, "UsersManagement")
        return 200