diag: Add log level config to py plugins
This commit is contained in:
1 parent
584ec6f7e8
commit
c5b73eaace
6 files changed
+43
-21
No files matched your search
@@ -7,5 +7,9 @@
|
||||
"venue": "VENUE_BYBIT",
|
||||
"api_key": "${BYBIT_API_KEY}",
|
||||
"secret_key": "${BYBIT_SECRET_KEY}",
|
||||
"use_testnet": true
|
||||
"use_testnet": true,
|
||||
"logging": {
|
||||
"console_level": "WARNING",
|
||||
"file_level": "INFO"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"logging": {
|
||||
"console_level": "WARNING",
|
||||
"file_level": "INFO"
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@ import time
|
||||
from typing import Optional
|
||||
import uuid
|
||||
from pybit.unified_trading import WebSocket, WebSocketTrading
|
||||
from py_execution_utils import load_gateway_config
|
||||
from spark_core import (
|
||||
as_bool,
|
||||
configure_logger,
|
||||
format_price,
|
||||
format_quantity,
|
||||
load_config,
|
||||
parse_float,
|
||||
StructuredLog as SLog,
|
||||
)
|
||||
@@ -89,9 +89,11 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
super(BybitExecutionGateway, self).__init__()
|
||||
name = "bybit_1"
|
||||
self.name = name
|
||||
self.logger = configure_logger(logging.getLogger(name), "OrderMan")
|
||||
cfg = load_config(name)
|
||||
self.logger = configure_logger(
|
||||
logging.getLogger(name), "OrderMan", **(cfg.get("logging") or {})
|
||||
)
|
||||
self.logger.info("[bybit_gw_ctr.json]%s" % SLog(name=name))
|
||||
cfg = load_gateway_config(name)
|
||||
self.account: str = cfg["account"]
|
||||
self.api_key: str = cfg["api_key"]
|
||||
self.secret_key: str = cfg["secret_key"]
|
||||
@@ -317,4 +319,3 @@ class BybitExecutionGateway(ExecutionGateway):
|
||||
"[bybit_gw_sec.json][%s]" % ", ".join([str(sec) for sec in securities])
|
||||
)
|
||||
self.securities = {sec.name(): sec for sec in securities}
|
||||
|
||||
@@ -21,6 +21,7 @@ from spark_core import (
|
||||
get_price_info,
|
||||
get_quantity_info,
|
||||
get_security,
|
||||
load_config,
|
||||
)
|
||||
from py_md_utils import PERP_EXP_STRING
|
||||
import requests
|
||||
@@ -94,6 +95,11 @@ class BybitMdProvider(MdProvider):
|
||||
signal.signal(signal.SIGTSTP, signal_handler)
|
||||
|
||||
def start_impl(self, bridge: MdBridge):
|
||||
config = load_config("bybit_md_provider")
|
||||
if not config:
|
||||
logger.error("bybit_md_provider not configured")
|
||||
return
|
||||
configure_logger(logger, "md", **config.get("logging", {}))
|
||||
self.bridge = bridge
|
||||
logger.info("Starting BybitMdProvider")
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import json
|
||||
import string
|
||||
import os
|
||||
|
||||
|
||||
def load_gateway_config(name: str, expand_vars: bool = True):
|
||||
s = ""
|
||||
with open(f"/home/bts/sparkdata/conf/py_{name}.json") as f:
|
||||
s = f.read()
|
||||
if expand_vars:
|
||||
s = string.Template(s).substitute(os.environ)
|
||||
return json.loads(s)
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import Callable, Optional
|
||||
from typing import Any, Callable, Optional
|
||||
import websocket
|
||||
from python_interop_module import (
|
||||
PyContractPriceInfo,
|
||||
@@ -90,17 +90,34 @@ def as_bool(*args):
|
||||
(True if arg else False for arg in args)
|
||||
|
||||
|
||||
def configure_logger(logger: logging.Logger, subsystem: str):
|
||||
def load_config(name: str, expand_vars: bool = True):
|
||||
s = ""
|
||||
with open(f"/home/bts/sparkdata/conf/py_{name}.json") as f:
|
||||
s = f.read()
|
||||
if expand_vars:
|
||||
s = string.Template(s).substitute(os.environ)
|
||||
return json.loads(s)
|
||||
|
||||
|
||||
def configure_logger(
|
||||
logger: logging.Logger,
|
||||
subsystem: str,
|
||||
**kwargs,
|
||||
):
|
||||
# Console
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
stdout_handler.setLevel(kwargs.get("console_level", logging.WARNING))
|
||||
stdout_handler.formatter = ConsoleLogFormatter(subsystem=subsystem)
|
||||
# File
|
||||
file_handler = logging.FileHandler(
|
||||
f"/home/bts/sparkdata/data/logging.sparkd/{logger.name}_log"
|
||||
)
|
||||
stdout_handler.formatter = ConsoleLogFormatter(subsystem=subsystem)
|
||||
file_handler.setLevel(kwargs.get("file_level", logging.INFO))
|
||||
file_handler.formatter = FileLogFormatter(subsystem=subsystem)
|
||||
logger.handlers.clear()
|
||||
logger.addHandler(stdout_handler)
|
||||
logger.addHandler(file_handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.setLevel(min(map(lambda h: h.level, logger.handlers)))
|
||||
return logger
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user