try insight_sdk

This commit is contained in:
fasiondog 2022-08-22 01:25:04 +08:00
parent bd1fc07bca
commit a4f57f7d76
3 changed files with 559 additions and 3 deletions

View File

@ -0,0 +1,51 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# Create on: 2022-08-22
# Author: fasiondog
import datetime
from hikyuu.util import *
@hku_catch(trace=True, callback=lambda stk: hku_warn("Failed parse stk: {}", stk))
def parse_one_result_huatai(stk):
result = {}
if 'OpenPx' not in stk:
return result
bids = [x / 10000.0 for x in stk['BuyPriceQueue']]
bids_amount = [x / 100.0 for x in stk['BuyOrderQtyQueue']]
asks = [x / 10000.0 for x in stk['SellPriceQueue']]
asks_amount = [x / 100.0 for x in stk['SellOrderQtyQueue']]
result['market'] = stk['HTSCSecurityID'][7:]
result['code'] = stk['HTSCSecurityID'][:6]
result['name'] = ''
result['open'] = stk['OpenPx'] / 10000.0 #
result['yesterday_close'] = stk['PreClosePx'] / 10000.0 #
result['close'] = stk['ClosePx'] / 10000.0 #
result['high'] = stk['HighPx'] / 10000.0 #
result['low'] = stk['LowPx'] / 10000.0 #
result['bid'] = bids[0] #
result['ask'] = asks[0] #
result['volumn'] = stk['TotalVolumeTrade'] / 100.0 # 使
result['amount'] = stk['TotalValueTrade'] #
# 买入委托
for i in range(len(bids)):
result[f'bid{i}'] = bids[i]
for i in range(len(bids_amount)):
result[f'bid{i}_amount'] = bids_amount[i]
# 卖出委托
for i in range(len(asks)):
result[f'ask{i}'] = asks[i]
for i in range(len(asks_amount)):
result[f'ask{i}_amount'] = asks_amount[i]
d = str(stk['MDDate'])
t = str(stk['MDTime'])
result['datetime'] = datetime.datetime(int(d[:4]), int(d[4:6]), int(d[6:8]), int(t[:2]), int(t[2:4]), int(t[4:6]))
return result

View File

@ -0,0 +1,502 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
try:
from insight_sdk.com.interface.mdc_gateway_base_define import ESubscribeActionType, ESecurityIDSource, ESecurityType, \
EMarketDataType, MDPlaybackExrightsType
from insight_sdk.com.insight import common, query, playback, subscribe
from insight_sdk.com.insight.market_service import market_service
except Exception as e:
print(e)
print('You must "pip install insgith_sdk"!')
exit(-1)
from hikyuu.fetcher.stock.zh_stock_a_huatai import parse_one_result_huatai
# ************************************用户登录************************************
# 登陆
# user 用户名
# password 密码
def login(user, password):
markets = insightmarketservice()
# 登陆前 初始化
# result格式为string格式
result = common.login(markets, user, password)
print("login result: ", result)
class insightmarketservice(market_service):
def __init__(self):
pass
# ************************************处理数据订阅************************************
# 处理订阅的股票Tick数据mdStock格式为json格式
# 订阅的证券类型为ESecurityType.StockType
def onSubscribe_StockType_MD_TICK(self, mdStock):
# print(mdStock)
result = parse_one_result_huatai(mdStock)
print("{}{}".format(result['market'], result['code']))
# pass
# 处理订阅的指数Tick数据mdIndex格式为json格式
# 订阅的证券类型为ESecurityType.IndexType
def onSubscribe_IndexType_MD_TICK(self, mdIndex):
#print(mdIndex)
pass
# 处理订阅的债券Tick数据mdBond格式为json格式
# 订阅的证券类型为ESecurityType.BondType
def onSubscribe_BondType_MD_TICK(self, mdBond):
pass
# print(mdBond)
# 处理订阅的基金Tick数据mdFund格式为json格式
# 订阅的证券类型为ESecurityType.FundType
def onSubscribe_FundType_MD_TICK(self, mdFund):
#print(mdFund)
pass
# 处理订阅的逐笔成交marketdatajson格式为json格式
# 订阅的证券类型为ESecurityType.MD_TRANSACTION
# 处理订阅的逐笔委托格式为json格式
# 订阅的证券类型为ESecurityType.MD_ORDER
def onSubscribe_MD_TRANSACTION_and_MD_ORDER(self, marketdatajson):
if marketdatajson["marketDataType"] == EMarketDataType.MD_TRANSACTION: #
mdtransaction = marketdatajson["mdTransaction"]
pass
# print(mdtransaction)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_ORDER: #
mdorder = marketdatajson["mdOrder"]
pass
# print(mdorder)
# print(marketdatajsons)
# 处理订阅的K线指标模型marketdatajson格式为json格式
# 订阅的数据类型为EMarketDataType.MD_KLINE_15S 返回#15秒钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_1MIN 返回#1分钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_5MIN 返回#5分钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_15MIN 返回#15分钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_30MIN 返回#30分钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_60MIN 返回#60分钟K线
# 订阅的数据类型为EMarketDataType.MD_KLINE_1D 返回#日K线
def onSubscribe_MD_KLINE(self, marketdatajson):
if marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_15S: # 15K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_1MIN: # 1K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_5MIN: # 5K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_15MIN: # 15K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_30MIN: # 30K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_60MIN: # 60K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_1D: # K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
# print(marketdatajson)
# 处理订阅的资金流向数据mdFundFlowAnalysis格式为json格式
# 订阅的证券类型为ESecurityType.AD_FUND_FLOW_ANALYSIS
def onSubscribe_AD_FUND_FLOW_ANALYSIS(self, mdFundFlowAnalysis):
pass
# print(mdFundFlowAnalysis)
# 处理订阅的融券通数据mdSecurityLending格式为json格式
# 订阅的证券类型为ESecurityType.MD_SECURITY_LENDING
def onSubscribe_MD_SECURITY_LENDING(self, mdSecurityLending):
pass
# print(mdSecurityLending)
# ************************************处理回放数据************************************
# 处理回放的股票Tick数据mdStock格式为json格式
# 回放的证券类型为ESecurityType.StockType
def onPlayback_StockType_MD_TICK(self, mdStock):
pass
# print(mdStock)
# 处理回放的指数Tick数据mdIndex格式为json格式
# 回放的证券类型为ESecurityType.IndexType
def onPlayback_IndexType_MD_TICK(self, mdIndex):
pass
# print(mdIndex)
# 处理回放的债券Tick数据mdBond格式为json格式
# 回放的证券类型为ESecurityType.BondType
def onPlayback_BondType_MD_TICK(self, mdBond):
pass
# print(mdBond)
# 处理回放的基金Tick数据mdFund格式为json格式
# 回放的证券类型为ESecurityType.FundType
def onPlayback_FundType_MD_TICK(self, mdFund):
pass
# print(mdFund)
# 处理回放的期权Tick数据mdOption格式为json格式
# 回放的证券类型为ESecurityType.OptionType
def onPlayback_OptionType_MD_TICK(self, mdOption):
pass
# print(mdOption)
# 处理回放的期货Tick数据mdFuture格式为json格式
# 回放的证券类型为ESecurityType.OptionType
def onPlayback_FuturesType_MD_TICK(self, mdFuture):
pass
# print(mdFuture)
# 处理回放的逐笔成交marketdatajson格式为json格式
# 回放的证券类型为ESecurityType.MD_TRANSACTION
# 处理回放的逐笔委托格式为json格式
# 回放的证券类型为ESecurityType.MD_ORDER
def onPlayback_MD_TRANSACTION_and_MD_ORDER(self, marketdatajson):
if marketdatajson["marketDataType"] == EMarketDataType.MD_TRANSACTION: #
mdtransaction = marketdatajson["mdTransaction"]
pass
# print(mdtransaction)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_ORDER: #
mdorder = marketdatajson["mdOrder"]
pass
# print(mdorder)
# print(marketdatajsons)
# 处理回放的K线指标模型marketdatajson格式为json格式
# 回放的数据类型为EMarketDataType.MD_KLINE_15S 返回#15秒钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_1MIN 返回#1分钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_5MIN 返回#5分钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_15MIN 返回#15分钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_30MIN 返回#30分钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_60MIN 返回#60分钟K线
# 回放的数据类型为EMarketDataType.MD_KLINE_1D 返回#日K线
def onPlayback_MD_KLINE(self, marketdatajson):
if marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_15S: # 15K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_1MIN: # 1K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_5MIN: # 5K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_15MIN: # 15K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_30MIN: # 30K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_60MIN: # 60K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
elif marketdatajson["marketDataType"] == EMarketDataType.MD_KLINE_1D: # K线
mdKLine = marketdatajson["mdKLine"]
pass
# print(mdKLine)
# print(marketdatajson)
# 处理回放的资金流向数据mdFundFlowAnalysis格式为json格式
# 回放的证券类型为ESecurityType.AD_FUND_FLOW_ANALYSIS
def onPlayback_AD_FUND_FLOW_ANALYSIS(self, mdFundFlowAnalysis):
pass
# print(mdFundFlowAnalysis)
# 处理回放的融券通数据mdSecurityLending格式为json格式
# 回放的证券类型为ESecurityType.MD_SECURITY_LENDING
def onPlayback_MD_SECURITY_LENDING(self, mdSecurityLending):
pass
# print(mdSecurityLending)
# 处理回放的状态status格式为string格式
def onPlaybackStatus(self, status):
pass
# print(status)
# 处理回放请求返回结果response格式为string格式
def onPlaybackResponse(self, response):
pass
# print(response)
# 处理回放控制请求返回结果response格式为string格式
def onPlaybackControlResponse(self, response):
pass
# print(response)
# ************************************处理查询请求返回结果************************************
# 处理查询历史上所有的指定证券的基础信息 query_mdcontant_by_type()的返回结果queryresponse格式为list[json]
# 处理查询今日最新的指定证券的基础信息 query_last_mdcontant_by_type()的返回结果queryresponse格式为list[json]
# 处理查询历史上所有的指定证券的基础信息 query_mdcontant_by_id()的返回结果queryresponse格式为list[json]
# 处理查询今日最新的指定证券的基础信息 query_last_mdcontant_by_id()的返回结果queryresponse格式为list[json]
# 处理查询指定证券的ETF的基础信息 query_ETFinfo()的返回结果queryresponse格式为list[json]
# 处理查询指定证券的最新一条Tick数据 query_last_mdtick()的返回结果queryresponse格式为list[json]
def onQueryResponse(self, queryresponse):
pass
for resonse in iter(queryresponse):
# response格式为json格式
print(resonse)
# 配置日志打开
# open_trace trace日志开关 True为打开日志False关闭日志
# open_file_log 本地file日志开关 True为打开日志False关闭日志
# open_cout_log 控制台日志开关 True为打开日志False关闭日志
def config(open_trace=True, open_file_log=True, open_cout_log=True):
common.config(open_trace, open_file_log, open_cout_log)
# ************************************数据订阅************************************
# 根据证券数据来源订阅行情数据,由三部分确定行情数据
# 行情源(SecurityIdSource):XSHG(沪市)|XSHE(深市)|...
# 证券类型(SecurityType):BondType(债)|StockType(股)|FundType(基)|IndexType(指)|OptionType(期权)|...
# 数据类型(MarketDataTypes):MD_TICK(快照)|MD_TRANSACTION(逐笔成交)|MD_ORDER(逐笔委托)|...
# 异步接口返回函数在functional_test.py
# 结果返回 onSubscribe_StockType_MD_TICK 处理订阅的股票Tick数据
# 结果返回 onSubscribe_IndexType_MD_TICK 处理订阅的指数Tick数据
# 结果返回 onSubscribe_BondType_MD_TICK 处理订阅的债券Tick数据
# 结果返回 onSubscribe_FundType_MD_TICK 处理订阅的基金Tick数据
# 结果返回 onSubscribe_OptionType_MD_TICK 处理订阅的期权Tick数据
# 结果返回 onSubscribe_FuturesType_MD_TICK 处理订阅的期货Tick数据
# 结果返回 onSubscribe_MD_TRANSACTION_and_MD_ORDER 处理订阅的逐笔成交和逐笔委托的数据
# 结果返回 onSubscribe_MD_KLINE 处理订阅的K线指标模型数据
# 结果返回 onSubscribe_AD_FUND_FLOW_ANALYSIS 处理订阅的资金流向数据
# 结果返回 onSubscribe_MD_SECURITY_LENDING 处理订阅的融券通数据
def subscribe_by_type():
# element
# params1: ESecurityIDSource枚举值 --行情源
# params2: ESecurityType的枚举值 --证券类型
# params3: EMarketDataType的枚举值集合 --数据类型
datatype = ESubscribeActionType.COVERAGE
marketdatatypes = []
marketdatatype = {
"ESecurityIDSource": ESecurityIDSource.XSHG,
"ESecurityType": ESecurityType.StockType,
"EMarketDataType": EMarketDataType.MD_SECURITY_LENDING
}
marketdatatypes.append(marketdatatype)
marketdatatype1 = {
"ESecurityIDSource": ESecurityIDSource.XSHE,
"ESecurityType": ESecurityType.StockType,
"EMarketDataType": EMarketDataType.MD_TICK
}
marketdatatypes.append(marketdatatype1)
subscribe.subscribe_by_type(marketdatatypes, datatype)
# 根据证券ID来源订阅行情数据
# 异步接口返回函数在functional_test.py
# 结果返回 onSubscribe_StockType_MD_TICK 处理订阅的股票Tick数据
# 结果返回 onSubscribe_IndexType_MD_TICK 处理订阅的指数Tick数据
# 结果返回 onSubscribe_BondType_MD_TICK 处理订阅的债券Tick数据
# 结果返回 onSubscribe_FundType_MD_TICK 处理订阅的基金Tick数据
# 结果返回 onSubscribe_OptionType_MD_TICK 处理订阅的期权Tick数据
# 结果返回 onSubscribe_FuturesType_MD_TICK 处理订阅的期货Tick数据
# 结果返回 onSubscribe_MD_TRANSACTION_and_MD_ORDER 处理订阅的逐笔成交和逐笔委托的数据
# 结果返回 onSubscribe_MD_KLINE 处理订阅的K线指标模型数据
# 结果返回 onSubscribe_AD_FUND_FLOW_ANALYSIS 处理订阅的资金流向数据
# 结果返回 onSubscribe_MD_SECURITY_LENDING 处理订阅的融券通数据
def subscribe_by_id():
# params1:HTSCSecurityID华泰内部证券标string --证券代码
# params2: EMarketDataType的枚举值集合 --数据类型
datatype = ESubscribeActionType.COVERAGE
HTSCSecurityIDs = []
HTSCSecurityID = {"HTSCSecurityID": "002371.SZ", "EMarketDataType": EMarketDataType.MD_TICK}
HTSCSecurityIDs.append(HTSCSecurityID)
HTSCSecurityID1 = {"HTSCSecurityID": "002714.SZ", "EMarketDataType": EMarketDataType.MD_TICK}
HTSCSecurityIDs.append(HTSCSecurityID1)
subscribe.subscribe_by_id(HTSCSecurityIDs, datatype)
# ************************************数据查询************************************
# 查询findata数据返回结果list[json]
# 同步接口返回结果为result格式为list[json]
def query_fin_info():
# params1:Hquery_type int
# params2:params dict{}
query_type = 1102010003
params = {"HTSC_SECURITY_ID": "510050.SH", "START_DATE": "20210101", "END_DATE": "20210107"}
# query_type = 1002010001
# params = {"HTSC_SECURITY_ID": "601688.SH", "START_DATE": "20191211", "END_DATE": "20201010"}
# query_type = 1002070003
# params = {"HTSC_SECURITY_ID": "600498.SH", "START_TIME": "20200101000000", "END_TIME": "20210107000000", "EXRIGHTS_TYPE": "NoExrights", "EMD_PERIOD_TYPE":"Period1D"}
result = query.query_fin_info(query_type, params)
if isinstance(result, list):
for response in iter(result):
print(response)
else:
print(result)
# 查询历史上所有的指定证券的基础信息
# params:securityIdSource 为市场ESecurityIDSource 枚举值;securityType 为 ESecurityType枚举值
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_mdcontant_by_type():
# params:security_idsource 为 ESecurityIDSource枚举值
# params:security_type 为 ESecurityType枚举值
# 沪市 股票
idsource_and_types = []
security_idsource = ESecurityIDSource.XSHG
security_type = ESecurityType.StockType
idsource_and_type = {"ESecurityIDSource": security_idsource, "ESecurityType": security_type}
idsource_and_types.append(idsource_and_type)
security_idsource1 = ESecurityIDSource.XSHE
security_type1 = ESecurityType.IndexType
idsource_and_type1 = {"ESecurityIDSource": security_idsource1, "ESecurityType": security_type1}
idsource_and_types.append(idsource_and_type1)
query.query_basicInfo_by_type(idsource_and_types, False)
# 查询今日最新的指定证券的基础信息
# params:securityIdSource 为市场ESecurityIDSource 枚举值;securityType 为 ESecurityType枚举值
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_last_mdcontant_by_type():
# 按市场查询
# 沪市 股票
idsource_and_types = []
security_idsource = ESecurityIDSource.XSHG
security_type = ESecurityType.StockType
idsource_and_type = {"ESecurityIDSource": security_idsource, "ESecurityType": security_type}
idsource_and_types.append(idsource_and_type)
security_idsource1 = ESecurityIDSource.XSHE
security_type1 = ESecurityType.IndexType
idsource_and_type1 = {"ESecurityIDSource": security_idsource1, "ESecurityType": security_type1}
idsource_and_types.append(idsource_and_type1)
query.query_basicInfo_by_type(idsource_and_types, True)
# 查询历史上所有的指定证券的基础信息 -- 结果返回在onQueryResponse
# param:HTSCSecurityID华泰内部证券标string --证券代码
# params:list[HTSCSecurityID]
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_mdcontant_by_id():
# params:security_idsource 为 ESecurityIDSource枚举值
# params:security_type 为 ESecurityType枚举值
# params:security_id_list 为 标的集合
security_id_list = ["601688.SH", "002714.SZ"] #
query.query_basicInfo_by_id(security_id_list, False)
# 查询今日最新的指定证券的基础信息 -- 结果返回在onQueryResponse
# param:HTSCSecurityID华泰内部证券标string --证券代码
# params:list[HTSCSecurityID]
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_last_mdcontant_by_id():
# 按市场查询
# 沪市 股票
# params:security_id_list 为 标的集合
security_id_list = ["601688.SH"] #
query.query_basicInfo_by_id(security_id_list, True)
# 查询指定证券的ETF的基础信息 -- 结果返回在onQueryResponse
# params:securityIdSource 为市场ESecurityIDSource 枚举值;securityType 为 ESecurityType枚举值
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_ETFinfo():
# params:securityIDSource 为 ESecurityIDSource枚举值
# params:securityType 为 ESecurityType枚举值
query.query_ETFinfo(ESecurityIDSource.XSHG, ESecurityType.FundType)
# 查询指定证券的最新一条Tick数据 -- 结果返回在onQueryResponse
# params:securityIdSource 为市场ESecurityIDSource 枚举值;securityType 为 ESecurityType枚举值
# 异步接口返回函数在functional_test.py
# 结果返回在onQueryResponse函数
def query_last_mdtick():
# params:security_idsource 为 ESecurityIDSource枚举值
# params:security_type 为 ESecurityType枚举值
# 沪市 股票
query.query_last_tick_by_type(ESecurityIDSource.XSHG, ESecurityType.StockType)
# 获取当前版本号
def get_version():
print(common.get_version())
# 释放资源
def fini():
common.fini()
def subscribe_by_hikyuu():
datatype = ESubscribeActionType.COVERAGE
marketdatatypes = [
{
"ESecurityIDSource": ESecurityIDSource.XSHE,
"ESecurityType": ESecurityType.StockType,
"EMarketDataType": EMarketDataType.MD_TICK
},
{
"ESecurityIDSource": ESecurityIDSource.XSHE,
"ESecurityType": ESecurityType.IndexType,
"EMarketDataType": EMarketDataType.MD_TICK
},
{
"ESecurityIDSource": ESecurityIDSource.XSHE,
"ESecurityType": ESecurityType.FundType,
"EMarketDataType": EMarketDataType.MD_TICK
},
{
"ESecurityIDSource": ESecurityIDSource.XSHG,
"ESecurityType": ESecurityType.StockType,
"EMarketDataType": EMarketDataType.MD_TICK
},
{
"ESecurityIDSource": ESecurityIDSource.XSHG,
"ESecurityType": ESecurityType.IndexType,
"EMarketDataType": EMarketDataType.MD_TICK
},
{
"ESecurityIDSource": ESecurityIDSource.XSHG,
"ESecurityType": ESecurityType.FundType,
"EMarketDataType": EMarketDataType.MD_TICK
},
]
subscribe.subscribe_by_type(marketdatatypes, datatype)
if __name__ == "__main__":
# 登陆部分调用
get_version()
login(user="", password="")
config(False, False, False)
# 订阅部分接口调用
subscribe_by_type()
# 退出释放资源
fini()

View File

@ -118,15 +118,18 @@ def hku_catch(ret=None, trace=False, callback=None, retry=1, with_msg=False, re_
hku_logger.error(errmsg)
if trace:
traceback.print_exc()
if callback and i == (retry - 1):
callback(*args, **kargs)
if i == (retry - 1):
if callback is not None:
callback(*args, **kargs)
if re_raise:
raise Exception(errmsg)
except:
errmsg = "Unknown error! {} [{}.{}]".format(get_exception_info(), func.__module__, func.__name__)
hku_logger.error(errmsg)
if trace:
traceback.print_exc()
if i == (retry - 1):
if callback:
if callback is not None:
callback(*args, **kargs)
if re_raise:
raise Exception(errmsg)