Code Monkey home page Code Monkey logo

microsoft / qlib-server Goto Github PK

View Code? Open in Web Editor NEW
221.0 221.0 68.0 118 KB

Qlib-Server is the data server system for Qlib. It enable Qlib to run in online mode. Under online mode, the data will be deployed as a shared data service. The data and their cache will be shared by all the clients. The data retrieval performance is expected to be improved due to a higher rate of cache hits. It will consume less disk space, too.

License: MIT License

Python 93.43% Shell 4.19% Dockerfile 2.38%
data finance investment platform python qlib quant server stock

qlib-server's Introduction

Qlib-Server is the data server system for Qlib. It enable Qlib to run in online mode. Under online mode, the data will be deployed as a shared data service. The data and their cache will be shared by all the clients. The data retrieval performance is expected to be improved due to a higher rate of cache hits. It will consume less disk space, too.

To sum up, Qlib-Server is designed to solve the following problems:

  • Manage the data in a centralized way, which makes data management (including cache management, date updating) much easier.
  • Reduce the amount of cache to be generated.
  • Make the client light-weighted and leverage the powerful computing resources of remote server

Framework of Qlib-Server

The Client/Server framework of Qlib is based on WebSocket considering its capability of bidirectional communication between client and server in async mode.

Qlib-Server is based on Flask, which is a micro-framework for Python and here Flask-SocketIO is used for websocket connection.

Quick start

Deployment

One-click Deployment

One-click deployment of Qlib-Server is supported, you can choose either of the following two methods for one-click deployment:

  • Deployment with docker-compose
  • Deployment in Azure

One-click Deployment with docker-compose

Deploy Qlib-Server with docker-compose according to the following processes:

  • Install docker, please refer to Docker Installation.

  • Install docker-compose, please refer to Docker-compose Installation.

  • Run the following command to deploy Qlib-Server:

      git clone https://github.com/microsoft/qlib-server
      cd qlib-server
      sudo docker-compose -f docker_support/docker-compose.yaml --env-file docker_support/docker-compose.env build
      sudo docker-compose -f docker_support/docker-compose.yaml --env-file docker_support/docker-compose.env up -d
      # Use the following command to track the log
      sudo docker-compose -f docker_support/docker-compose.yaml --env-file docker_support/docker-compose.env logs -f

One-click Deployment in Azure

Firstly, You need to have an Azure account to deploy Qlib-Server in Azure. Then you can deploy Qlib-Server in Azure according to the following processes:

  • Install azure-cli, please refer to install-azure-cli.

  • Add the Azure account to the configuration file azure_conf.yaml

        sub_id: Your Subscription ID
        username: azure user name
        password: azure password
        # The resource group where the VM is located
        resource_group: Resource group name
  • Execute the deployment script by running the following command:

        git clone https://github.com/microsoft/qlib-server
        cd qlib-server/scripts
        python azure_manager.py create_qlib_cs_vm \
            --qlib_server_name test_server01 \
            --qlib_client_names test_client01 \
            --admin_username test_user \
            --ssh_key_value ~/.ssh/id_rsa.pub \
            --size standard_NV6_Promo\
            --conf_path azure_conf.yaml

To know more about one-click Deployment, please refer to Qlib-Server One-click Deployment.

Step-by-step Deployment

To know more about step-by-step Deployment, please refer to [Qlib-Server Step-by-step Deplyment]https://qlib-server.readthedocs.io/en/latest/build.html#step-by-step-deployment).

Using Qlib in Online Mode

In the Qlib Document, the Offline mode has been introduced.

With Qlib-Server, you can use Qlib in Online mode, please initialize Qlib with the following code:

import qlib
ONLINE_CONFIG = {
    # data provider config
    "calendar_provider": {"class": "LocalCalendarProvider", "kwargs": {"remote": True}},
    "instrument_provider": "ClientInstrumentProvider",
    "feature_provider": {"class": "LocalFeatureProvider", "kwargs": {"remote": True}},
    "expression_provider": "LocalExpressionProvider",
    "dataset_provider": "ClientDatasetProvider",
    "provider": "ClientProvider",
    # config it in user's own code
    "provider_uri": "127.0.0.1:/",
    # cache
    # Using parameter 'remote' to announce the client is using server_cache, and the writing access will be disabled.
    "expression_cache": None,
    "dataset_cache": None,
    "calendar_cache": None,
    "mount_path": "/data/stock_data/qlib_data",
    "auto_mount": True,  # The nfs is already mounted on our server[auto_mount: False].
    "flask_server": "127.0.0.1",
    "flask_port": 9710,
    "region": "cn",
}

qlib.init(**client_config)
ins = D.list_instruments(D.instruments("all"), as_list=True)

For more details, please refer to Qlib-Server Client.

More About Qlib-Server

The detailed documents are organized in docs. Sphinx and the readthedocs theme is required to build the documentation in html formats.

cd docs/
conda install sphinx sphinx_rtd_theme -y
# Otherwise, you can install them with pip
# pip install sphinx sphinx_rtd_theme
make html

You can also view the latest document online directly.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

qlib-server's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qlib-server's Issues

confusion with config in online mode

I was already using QLIB without the server.
my provider_uri was QLIB_DS2_DATA_DIR

Now I installed the qlib server and it is running. I checked the logs
My config is as follows
`ONLINE_CONFIG = {
# data provider config

"calendar_provider": {"class": "LocalCalendarProvider", "kwargs": {"remote": True}},
"instrument_provider": "ClientInstrumentProvider",
"feature_provider": {"class": "LocalFeatureProvider", "kwargs": {"remote": True}},
"expression_provider": "LocalExpressionProvider",
"dataset_provider": "ClientDatasetProvider",
"provider": "ClientProvider",

# config it in user's own code
"provider_uri": "127.0.0.1:/",
# cache
# Using parameter 'remote' to announce the client is using server_cache, and the writing access will be disabled.

"expression_cache": None,
"dataset_cache": None,
"calendar_cache": None,
"mount_path": QLIB_DS2_DATA_DIR,
"auto_mount": True,  # The nfs is already mounted on our server[auto_mount: False].
"flask_server": "127.0.0.1",
"flask_port": 9710,
"region": "cn",

}`

Now Im not able to query any data.

KeyError from config file of qlib

There's no default key in _default_config struction:

Traceback (most recent call last):
File "main.py", line 64, in
init(config)
File "/code/qlib-server/qlib_server/config.py", line 127, in init
redis_host=C["redis_host"],
File "/opt/conda/lib/python3.7/site-packages/qlib/init.py", line 59, in init
if C["auto_mount"]:
File "/opt/conda/lib/python3.7/site-packages/qlib/config.py", line 37, in getitem
return self.dict["_config"][key]
KeyError: 'auto_mount'

client raise exception when read from dataset cache

Hi Team,

we are getting an error when we run qlib online.

Environment

  • qlib-server
    • version: master branch of commit cfd3e4b
    • host ip: 192.168.0.165
    • OS Version: Ubuntu20.04
    • erlang: 23.3.1
    • rabbitmq: 3.9.13
    • redis: 5.0.4
  • qlib client
    • version: 0.7.1.99
    • host ip: 192.168.0.168
    • OS Version: Ubuntu20.04

Steps to reproduce

qlib-server(192.168.0.165)

  1. deploy qlib server step-by-step https://qlib-server.readthedocs.io/en/latest/build.html#step-by-step-deployment
  2. pice of config.yaml
provider_uri: /qlib/bin_data/cn_data
flask_server: 127.0.0.1
flask_port: 9710
queue_host: 127.0.0.1
queue_user: admin
queue_pwd: ####
task_queue: qlib_task_queue
message_queue: qlib_msg_queue
max_concurrency: 10
max_process: 30
redis_host: 127.0.0.1
redis_port: 6379
redis_task_db: 1
auto_update: 0
update_time: '23:45'
client_version: '>=0.4.0'
server_version: '>=0.4.0'
dataset_cache_dir_name: dataset_cache
features_cache_dir_name: features_cache
  1. exported uri to NFS clients
/qlib/bin_data/cn_data *(rw,sync,no_subtree_check,no_root_squash)
  1. run the command as user dev
python main.py -c config.yaml
  1. check the files permission in dataset cache
 ls -l /qlib/bin_data/cn_data/dataset_cache/
总用量 1936852
-rw-rw---- 1 dev   dev     344595812 3月   9 18:47 8d1f1755a8b65351ae4fe43016cdf52d
-rwxr--r-- 1 dev   dev        183303 3月   9 18:47 8d1f1755a8b65351ae4fe43016cdf52d.index
-rwxr--r-- 1 dev   dev           235 3月   9 18:47 8d1f1755a8b65351ae4fe43016cdf52d.meta 

qlib-client(192.168.0.168)

  1. pip install qlib
  2. mount data cache path manually
sudo mount 192.168.0.165:/qlib/bin_data/cn_data /remote_qlib_data/
  1. modify the config section official example https://github.com/microsoft/qlib/blob/main/examples/workflow_by_code.py
{
                # data provider config
                "calendar_provider": {"class": "LocalCalendarProvider", "kwargs": {"remote": True}},
                "instrument_provider": "ClientInstrumentProvider",
                "feature_provider": {"class": "LocalFeatureProvider", "kwargs": {"remote": True}},
                "expression_provider": "LocalExpressionProvider",
                "dataset_provider": "ClientDatasetProvider",
                "provider": "ClientProvider",
                # config it in user's own code
                #"provider_uri": "192.168.0.165:/qlib/bin_data/cn_data",
                # cache
                # Using parameter 'remote' to announce the client is using server_cache, and the writing access will be disabled.
                "expression_cache": None,
                "dataset_cache": None,
                "calendar_cache": None,
                "mount_path": "/remote_qlib_data",
                "auto_mount": False,  # The nfs is already mounted on our server[auto_mount: False].
                "flask_server": "192.168.0.165",
                "flask_port": 9710,
                "region": "cn",
  1. run the sample code as user robin, raise the exception
File "/workspace/qlib/data/data.py", line 967, in dataset
    df = DiskDatasetCache.read_data_from_cache(mnt_feature_uri, start_time, end_time, fields)
  File "/workspace/qlib/data/cache.py", line 683, in read_data_from_cache
    with pd.HDFStore(cache_path, mode="r") as store:
  File "/workspace/venv/lib/python3.8/site-packages/pandas/io/pytables.py", line 537, in __init__
    self.open(mode=mode, **kwargs)
  File "/workspace/venv/lib/python3.8/site-packages/pandas/io/pytables.py", line 655, in open
    self._handle = tables.open_file(self._path, self._mode, **kwargs)
  File "/workspace/venv/lib/python3.8/site-packages/tables/file.py", line 315, in open_file
    return File(filename, mode, title, root_uep, filters, **kwargs)
  File "/workspace/venv/lib/python3.8/site-packages/tables/file.py", line 778, in __init__
    self._g_new(filename, mode, **params)
  File "tables/hdf5extension.pyx", line 374, in tables.hdf5extension.File._g_new
  File "/workspace/venv/lib/python3.8/site-packages/tables/utils.py", line 158, in check_file_access
    raise IOError("file ``%s`` exists but it can not be read"
OSError: file ``/remote_qlib_data/dataset_cache/8d1f1755a8b65351ae4fe43016cdf52d`` exists but it can not be read

Seems like the server is not starting correctly.

All logs of the qlib-server container are as follows

docker_support-qlib-server-1  | wait-for-it.sh: waiting 15 seconds for rabbitmq:15672
docker_support-qlib-server-1  | wait-for-it.sh: rabbitmq:15672 is available after 0 seconds
docker_support-qlib-server-1  | [1:MainThread](2023-06-01 05:02:42,283) INFO - qlib.Initialization - [config.py:417] - default_conf: server.

Add CI

Hi, this issue tracks the process of adding CI to the library.

  • Add test scripts for installing the library.
  • Add CI script for testing.
  • Add CI script for docker.

Running docker-compose on windows10 failed

C:\Users\Administrator\Downloads\qlib-server-main>docker-compose -f docker_support/docker-compose.yaml --env-file docker_support/docker-compose.env up -d
: Host is already in use by another container
Starting docker_support_redis_1 ... done
Starting 98d81b3aaeec_docker_support_nfs-server_1 ...
Starting 98d81b3aaeec_docker_support_nfs-server_1 ... error

ERROR: for 98d81b3aaeec_docker_support_nfs-server_1 Cannot start service nfs-server: driver failed programming externalRecreating docker_support_rabbitmq_1 ... done
f1c4eec6d8e1): Error starting userland proxy: listen udp4 0.0.0.0:111: bind: address already in use

ERROR: for nfs-server Cannot start service nfs-server: driver failed programming external connectivity on endpoint 98d81b3aaeec_docker_support_nfs-server_1 (345188e9c48d20701a06d4fb86c05435c010915a2069d347a50ef1c4eec6d8e1): Error starting userland proxy: listen udp4 0.0.0.0:111: bind: address already in use
ERROR: Encountered errors while bringing up the project.

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.