[Add] add support for mysql
This commit is contained in:
parent
97ebd032e1
commit
7490a5c0ad
@ -1,4 +1,5 @@
|
|||||||
PyQt5<5.12
|
PyQt5<5.12
|
||||||
|
pyqtgraph
|
||||||
dataclasses; python_version<="3.6"
|
dataclasses; python_version<="3.6"
|
||||||
qdarkstyle
|
qdarkstyle
|
||||||
requests
|
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 .constant import Exchange, Interval
|
||||||
from .object import BarData, TickData
|
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):
|
class DbBarData(Model):
|
||||||
|
@ -197,7 +197,7 @@ class BaseEngine(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LogEngine(BaseEngine, metaclass=Singleton):
|
class LogEngine(BaseEngine):
|
||||||
"""
|
"""
|
||||||
Processes log event and output with logging module.
|
Processes log event and output with logging module.
|
||||||
"""
|
"""
|
||||||
|
@ -23,9 +23,16 @@ SETTINGS = {
|
|||||||
"email.receiver": "",
|
"email.receiver": "",
|
||||||
|
|
||||||
"rqdata.username": "",
|
"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.
|
# Load global setting from json file.
|
||||||
SETTING_FILENAME = "vt_setting.json"
|
SETTING_FILENAME = "vt_setting.json"
|
||||||
|
@ -3,6 +3,7 @@ General utility functions.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
@ -31,6 +32,12 @@ class Singleton(type):
|
|||||||
return cls._instances[cls]
|
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):
|
def _get_trader_dir(temp_name: str):
|
||||||
"""
|
"""
|
||||||
Get path where trader is running in.
|
Get path where trader is running in.
|
||||||
|
Loading…
Reference in New Issue
Block a user