[Add] add support for mysql
This commit is contained in:
parent
97ebd032e1
commit
7490a5c0ad
@ -1,4 +1,5 @@
|
||||
PyQt5<5.12
|
||||
pyqtgraph
|
||||
dataclasses; python_version<="3.6"
|
||||
qdarkstyle
|
||||
requests
|
||||
|
@ -1,13 +1,47 @@
|
||||
""""""
|
||||
|
||||
from peewee import SqliteDatabase, Model, CharField, DateTimeField, FloatField
|
||||
from peewee import CharField, DateTimeField, FloatField, Model, MySQLDatabase, PostgresqlDatabase, \
|
||||
SqliteDatabase
|
||||
|
||||
from .constant import Exchange, Interval
|
||||
from .object import BarData, TickData
|
||||
from .utility import get_file_path
|
||||
from .setting import SETTINGS
|
||||
from .utility import resolve_path
|
||||
|
||||
DB_NAME = "database.db"
|
||||
DB = SqliteDatabase(str(get_file_path(DB_NAME)))
|
||||
|
||||
def init():
|
||||
db_settings = SETTINGS['database']
|
||||
driver = db_settings["driver"]
|
||||
|
||||
init_funcs = {
|
||||
"sqlite": init_sqlite,
|
||||
"mysql": init_mysql,
|
||||
"postgresql": init_postgresql,
|
||||
}
|
||||
|
||||
assert driver in init_funcs
|
||||
del db_settings['driver']
|
||||
return init_funcs[driver](db_settings)
|
||||
|
||||
|
||||
def init_sqlite(settings: dict):
|
||||
global DB
|
||||
database = settings['database']
|
||||
|
||||
DB = SqliteDatabase(str(resolve_path(database)))
|
||||
|
||||
|
||||
def init_mysql(settings: dict):
|
||||
global DB
|
||||
DB = MySQLDatabase(**settings)
|
||||
|
||||
|
||||
def init_postgresql(settings: dict):
|
||||
global DB
|
||||
DB = PostgresqlDatabase(**settings)
|
||||
|
||||
|
||||
init()
|
||||
|
||||
|
||||
class DbBarData(Model):
|
||||
|
@ -197,7 +197,7 @@ class BaseEngine(ABC):
|
||||
pass
|
||||
|
||||
|
||||
class LogEngine(BaseEngine, metaclass=Singleton):
|
||||
class LogEngine(BaseEngine):
|
||||
"""
|
||||
Processes log event and output with logging module.
|
||||
"""
|
||||
|
@ -23,10 +23,17 @@ SETTINGS = {
|
||||
"email.receiver": "",
|
||||
|
||||
"rqdata.username": "",
|
||||
"rqdata.password": ""
|
||||
"rqdata.password": "",
|
||||
"database": {
|
||||
"driver": "sqlite",
|
||||
"database": "{VNPY_TEMP}/database.db", # for sqlite, use this as filepath
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"user": "root",
|
||||
"password": ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Load global setting from json file.
|
||||
SETTING_FILENAME = "vt_setting.json"
|
||||
SETTINGS.update(load_json(SETTING_FILENAME))
|
||||
|
@ -3,6 +3,7 @@ General utility functions.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
@ -31,6 +32,12 @@ class Singleton(type):
|
||||
return cls._instances[cls]
|
||||
|
||||
|
||||
def resolve_path(pattern: str):
|
||||
env = dict(os.environ)
|
||||
env.update({"VNPY_TEMP": str(TEMP_DIR)})
|
||||
return pattern.format(**env)
|
||||
|
||||
|
||||
def _get_trader_dir(temp_name: str):
|
||||
"""
|
||||
Get path where trader is running in.
|
||||
|
Loading…
Reference in New Issue
Block a user