| | |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module.log import hx_logger_l2_transaction, logger_debug |
| | | from strategy import data_cache |
| | | from strategy.trade_setting import TradeSetting |
| | | from trade import huaxin_trade_api, huaxin_trade_data_update |
| | | from trade.huaxin_trade_record_manager import DelegateRecordManager, DealRecordManager, MoneyManager, PositionManager |
| | | from utils import tool, huaxin_util, socket_util |
| | |
| | | # 获取每次买入的金额 |
| | | money = data_cache.BUY_MONEY_PER_CODE |
| | | response_data = json.dumps({"code": 0, "data": {"money": money}}) |
| | | elif url.path == "/get_trade_settings": |
| | | fdata = {"running": TradeSetting().get_running(), "auto_sell": TradeSetting().get_auto_sell(), |
| | | "auto_buy": TradeSetting().get_auto_buy()} |
| | | response_data = json.dumps({"code": 0, "data": fdata}) |
| | | |
| | | elif url.path == "/set_trade_settings": |
| | | running = params_dict.get("running") |
| | | auto_sell = params_dict.get("auto_sell") |
| | | auto_buy = params_dict.get("auto_buy") |
| | | if running is not None: |
| | | TradeSetting().set_running(int(running)) |
| | | if auto_sell is not None: |
| | | TradeSetting().set_auto_sell(int(auto_sell)) |
| | | if auto_buy is not None: |
| | | TradeSetting().set_auto_buy(int(auto_buy)) |
| | | response_data = json.dumps({"code": 0, "data": {}}) |
| | | |
| | | elif url.path == "/get_env": |
| | | try: |
| | | fdata = {} |
| | |
| | | import constant |
| | | # 引入掘金桥梁API |
| | | import utils.juejin_api |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from log_module.log import logger_common, logger_kpl_jingxuan_in, logger_system |
| | | # 引入开盘啦API模块 |
| | | # 引入全局变量模块 |
| | |
| | | # 启动异步日志 |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | |
| | | # redis 数据同步 |
| | | threading.Thread(target=RedisUtils.run_loop, daemon=True).start() |
| | | |
| | | # 启动交易 |
| | | order_methods.run() |
| | | |
New file |
| | |
| | | """ |
| | | 交易设置 |
| | | """ |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from utils import tool |
| | | |
| | | |
| | | @tool.singleton |
| | | class TradeSetting: |
| | | __db = 2 |
| | | __redis_manager = redis_manager.RedisManager(2) |
| | | # 运行状态 |
| | | __TYPE_RUNNING_STATE = "running" |
| | | # 自动买 |
| | | __TYPE_AUTO_BUY = "auto_buy" |
| | | # 自动卖 |
| | | __TYPE_AUTO_SELL = "auto_sell" |
| | | |
| | | def __init__(self): |
| | | # 赋初始值 |
| | | self.auto_buy = 1 |
| | | self.auto_sell = 1 |
| | | self.running = 1 |
| | | self.__load_data() |
| | | |
| | | def __get_redis(self): |
| | | return self.__redis_manager.getRedis() |
| | | |
| | | def __load_data(self): |
| | | result = RedisUtils.get(self.__get_redis(), self.__TYPE_RUNNING_STATE) |
| | | if result is not None: |
| | | self.running = int(result) |
| | | |
| | | result = RedisUtils.get(self.__get_redis(), self.__TYPE_AUTO_BUY) |
| | | if result is not None: |
| | | self.auto_buy = int(result) |
| | | |
| | | result = RedisUtils.get(self.__get_redis(), self.__TYPE_AUTO_SELL) |
| | | if result is not None: |
| | | self.auto_sell = int(result) |
| | | |
| | | def set_auto_buy(self, auto_buy): |
| | | self.auto_buy = 1 if auto_buy else 0 |
| | | RedisUtils.setex_async(self.__db, self.__TYPE_AUTO_BUY, tool.get_expire(), self.auto_buy) |
| | | |
| | | def set_auto_sell(self, auto_sell): |
| | | self.auto_sell = 1 if auto_sell else 0 |
| | | RedisUtils.setex_async(self.__db, self.__TYPE_AUTO_SELL, tool.get_expire(), self.auto_sell) |
| | | |
| | | def set_running(self, running): |
| | | self.running = 1 if running else 0 |
| | | RedisUtils.setex_async(self.__db, self.__TYPE_RUNNING_STATE, tool.get_expire(), self.running) |
| | | |
| | | def get_running(self): |
| | | return self.running |
| | | |
| | | def get_auto_buy(self): |
| | | return self.auto_buy |
| | | |
| | | def get_auto_sell(self): |
| | | return self.auto_sell |