Giter Club home page Giter Club logo

stakelimiterservice's Introduction

Installation Guide

Live demo: https://stake-limiter.herokuapp.com/

With Docker

Clone the repo
cd into project folder
run docker-compose up -d
run docker-compose run app php artisan migrate:fresh --seed
visit localhost:8080

Server requirements

PHP >= 7.2.5
BCMath PHP Extension
Ctype PHP Extension
Fileinfo PHP extension
JSON PHP Extension
Mbstring PHP Extension
OpenSSL PHP Extension
PDO PHP Extension
Tokenizer PHP Extension
XML PHP Extension

Installation steps

Clone this repo
Create a database which you will use for the project
cd into the project folder
rename .env.example into .env
populate the .env with your db info
run composer install (post install script will migrate the tables and seed the db)
run php artisan key:generate
run npm install
run php artisan serve

API documentation

Get the status for a specific device based on the global configuration.

URL : /api/device/check-limits

Method : POST

Request examples

{
    "id": "ef65ef3e-d212-3137-7f56-ec533cb7759d",
    "deviceId": "6c834452-d73f-3e63-9cf6-31372da42078",
    "stake": 300.99
}

Data constraints

{
    "id": "(uuid)",
    "deviceId": "(uuid)",
    "stake": "(double)"
}

Success Response

Code : 200

Content examples

For a device which is below all limits.

{
    "status": "OK"
}

For a device which has sum of stakes higher or equal {config hot amount} in the last {config time duration}

{
   "status": "HOT"
}

For a device which has sum of stakes higher or equal {config stake limit} in the last {config time duration}

{
   "status": "BLOCKED"
}

Notes

  • If the device sent in the request body is not in the database, it will be created for future tracking.

Change the global configuration.

URL : /api/config/update

Method : POST

Request examples

{
    "stakeLimit": 1000,
    "timeDuration": 500,
    "hotAmountPctg": 80,
    "restrExpiry": 1800
}

Data constraints

{
    "stakeLimit": "required|numeric|min:1|max:10000000",
    "timeDuration": "required|numeric|min:300|max:86400",
    "hotAmountPctg": "required|numeric|min:1|max:100",
    "restrExpiry": "required|numeric"
}

Success Response

Code : 200

Content examples

{
    "Configuration updated."
}

Validation error response

Code : 422

Content examples

{
    "message": "The given data was invalid.",
    "errors": {
        "stakeLimit": [
            "The stake limit must be at least 1."
        ],
        "timeDuration": [
            "The time duration must be at least 300."
        ],
        "hotAmountPctg": [
            "The hot amount pctg must be at least 1."
        ],
        "restrExpiry": [
            "The restr expiry must be a number."
        ]
    }
}

Notes

  • If the restrExpiry is 0 device will not be unblocked automatically.

stakelimiterservice's People

Contributors

nerminkarapandzic avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.