jingedawang / StockPredictor

Predict the stock price with AI models.
http://stockprediction.org/
MIT License
21 stars 6 forks source link

Task 2.1: Web API for front-end #9

Closed jingedawang closed 2 years ago

jingedawang commented 2 years ago

Web API provides following interfaces with HTTP protocol.

Interface 1: Get stock list.

Url: /stock/list
Parameter: None
Response: A JSON string. Example: 
[
    {
        "id": "600479",
        "pinyin": "QJYY",
        "name": "千金药业"
    },
    {
        "id": "600480",
        "pinyin": "LYGF",
        "name": "凌云股份"
    },
    {
        "id": "600481",
        "pinyin": "SLJN",
        "name": "双良节能"
    }
]

Interface 2: Predict.

Url: /stock/<id>
Parameter: <id>: The id of the stock.
Response: A JSON string containing both history prices and predicted price. Example:
{
    "id": "600000",
    "pinyin": "PFYH",
    "name": "浦发银行",
    "qlib_id": "SH600000",
    "enname": null,
    "history": [
        {
            "2020-08-03": 10.40999984741211
        },
        {
            "2020-08-04": 10.65999984741211
        },
        {
            "2020-08-05": 10.510001182556153
        },
        {
            "2020-08-06": 10.529999732971192
        },
        {
            "2020-08-07": 10.430000305175782
        }
    ],
    "predict": 10.01
}
jingedawang commented 2 years ago

The implementation details for API get_stock_list:

  1. Found a stock list text file from internet and add it into this repo with name stock_list.csv.
  2. Load the stock list file into tinydb database, which is a simple JSON based database.
  3. Read the database when web client requests for stock list.

The implementation details for API predict:

  1. Find the date of last 40 trading days.
  2. Query the history prices for the specified stock in last 40 trading days.
  3. TODO: Get the predicted price after 10 trading days.
  4. Generate a JSON string and return.
jingedawang commented 2 years ago

It can be tested locally now.

API 1: http://127.0.0.1:5000/stock/list Image

API 2: http://127.0.0.1:5000/stock/600000 Image

jingedawang commented 2 years ago

It can be accessed anywhere now!

Please try following APIs.

Homepage help url: http://20.205.61.210:5000/

API 1: Get stock list http://20.205.61.210:5000/stock/list

API 2: Predict http://20.205.61.210:5000/stock/600000 Because our data and prediction is not ready, the result contains many NaN and null. Here is the result screenshot. image

API 3: Predict in date http://20.205.61.210:5000/stock/600000/2020-04-19 To make it convenient for front-end test, this API will predict at the given date. So, this request will get the history data correctly, but the prediction is still not available. image

jingedawang commented 2 years ago

Data has been updated to the newest date. Now we can use API 2 to obtain the history of recent 40 days. http://20.205.61.210:5000/stock/600000 image

jingedawang commented 2 years ago

Round the prices to 2 decimals. Add English name to the response. http://20.205.61.210:5000/stock/600000 image