hikyuu2/hikyuu/__init__.py

138 lines
4.4 KiB
Python
Raw Normal View History

2015-01-07 01:26:14 +08:00
#!/usr/bin/python
# -*- coding: utf8 -*-
# cp936
#
# The MIT License (MIT)
#
# Copyright (c) 2010-2017 fasiondog
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
__copyright__ = """
MIT License
Copyright (c) 2010-2017 fasiondog
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2015-01-07 01:26:14 +08:00
"""
2024-02-28 16:10:03 +08:00
import traceback
import sys
import pickle
2020-11-30 00:17:27 +08:00
from .util import *
2024-02-28 16:10:03 +08:00
try:
from .extend import *
# from .deprecated import * # pybind getattr 会被递归,无法使用
from .indicator import *
from .trade_manage import *
from .trade_sys import *
from .analysis import *
from .hub import *
except Exception as e:
info = sys.exc_info()
hku_fatal("{}: {}".format(info[0].__name__, info[1]))
hku_fatal(traceback.format_exc())
print("""请使用 pipdeptree -p hikyuu 检查是否存在缺失的依赖包。
如果没有问题可以在 https://gitee.com/fasiondog/hikyuu https://github.com/fasiondog/hikyuu
上提交 issue同时附上 "用户目录/.hikyuu" 下的 hikyuu_py.log hikyuu.log 日志文件 """)
raise e
2024-03-26 01:46:26 +08:00
__version__ = get_version()
sm = StockManager.instance()
class iodog:
# Only for compatibility with old code
@staticmethod
def open():
open_ostream_to_python()
@staticmethod
def close():
close_ostream_to_python()
if in_interactive_session():
set_python_in_interactive(True)
2024-03-26 01:46:26 +08:00
# 如果是在 jupyter 环境中运行重定向C++ stdout/stderr输出至python
if in_ipython_frontend():
2024-03-27 16:18:41 +08:00
set_python_in_jupyter(True)
2024-03-26 01:46:26 +08:00
hku_info("hikyuu version: {}", get_version_with_build())
iodog.open()
def hku_save(var, filename):
"""
序列化将hikyuu内建类型的变量如StockTradeManager等保存在指定的文件中格式为XML
:param var: hikyuu内建类型的变量
:param str filename: 指定的文件名
"""
with open(filename, 'wb') as f:
pickle.dump(var, f)
def hku_load(filename):
"""
将通过 hku_save 保存的变量读取到var中
:param str filename: 待载入的序列化文件
:return: 之前被序列化保存的文件
"""
with open(filename, 'rb') as f:
out = pickle.load(f)
return out
2021-02-08 00:49:36 +08:00
# ==============================================================================
#
# 设置关键类型简称
#
# ==============================================================================
O = OPEN()
C = CLOSE()
H = HIGH()
L = LOW()
A = AMO()
V = VOL()
D = Datetime
K = None
Q = Query