# Path: fooltrader/settings.py
# BOT_NAME = 'fooltrader'
# SPIDER_MODULES = ['fooltrader.spiders']
# NEWSPIDER_MODULE = 'fooltrader.spiders'
# COMPRESSION_ENABLED = True
# DOWNLOADER_MIDDLEWARES = {
#     'fooltrader.middlewares.ForbiddenHandleMiddleware': 1000,
# }
# AUTOTHROTTLE_DEBUG = False
# FOOLTRADER_STORE_PATH = os.environ.get('FOOLTRADER_STORE_PATH')
#     FOOLTRADER_STORE_PATH = '/home/xuanqi/workspace/github/fooltrader/data'
# STOCK_START_CODE = '000001'
# STOCK_END_CODE = '666666'
# US_STOCK_CODES = ['MSFT', 'AMZN', 'NVDA', 'SINA', 'AAPL']
# AVAILABLE_TICK_DATE = '2004-10-8'
# START_TICK_DATE = '2013-1-1'
# FORCE_DOWNLOAD_SECURITY_LIST = False
# DOWNLOAD_TXT_ENCODING = 'GB2312'
# AUTO_KAFKA = False
# KAFKA_HOST = 'localhost:9092'
# KAFKA_PATH = '/home/xuanqi/software/kafka_2.11-0.11.0.1'
# ZK_KAFKA_HOST = 'localhost:2181'
# DG_PATH = '/Users/xuanqi/software/delegate/DGROOT/bin/delegate'
# SUPPORT_SOCKS2HTTP = False
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"
# TIME_FORMAT_SEC = '%Y-%m-%d %H:%M:%S'
# TIME_FORMAT_DAY = '%Y-%m-%d'
# ES_HOSTS = ['localhost:9200']
# SMTP_HOST = 'smtpdm.aliyun.com'
# SMTP_PORT = '80'
# EMAIL_USER_NAME = ''
#     EMAIL_USER_NAME = os.environ.get('EMAIL_USER_NAME')
# EMAIL_PASSWORD = ''
#     EMAIL_PASSWORD = os.environ.get('EMAIL_PASSWORD')
# WEIXIN_APP_ID = ""
#     WEIXIN_APP_ID = os.environ.get("WEIXIN_APP_ID")
# WEIXIN_APP_SECRECT = ""
#     WEIXIN_APP_SECRECT = os.environ.get("WEIXIN_APP_SECRECT")
# EOS_MONGODB_URL = ""
#     EOS_MONGODB_URL = os.environ.get("EOS_MONGODB_URL")
# 
# Path: fooltrader/api/technical.py
# def convert_to_list_if_need(input):
# def get_security_list(security_type='stock', exchanges=None, start_code=None, end_code=None,
#                       mode='simple', start_list_date=None, codes=None):
# def _get_security_item(security_type, exchanges, code=None):
# def to_security_item(security_item, exchange=None):
# def get_ticks(security_item, the_date=None, start_date=None, end_date=None):
# def _parse_tick(tick_path, security_item):
# def get_available_tick_dates(security_item):
# def get_kdata(security_item, exchange=None, the_date=None, start_date=None, end_date=None, fuquan='bfq', source=None,
#               level='day', generate_id=False):
# def get_latest_download_trading_date(security_item, return_next=True, source=None):
# def get_trading_calendar(security_type='future', exchange='shfe'):
# def get_trading_dates(security_item, dtype='list', ignore_today=False, source='163', fuquan='bfq'):
# def kdata_exist(security_item, year, quarter, fuquan=None, source='163'):
# def parse_shfe_day_data(force_parse=False):
# def parse_shfe_data(force_parse=False):
#             KDATA_COLUMN_FUTURE = ['timestamp', 'code', 'name', 'low', 'open', 'close', 'high', 'volume', 'turnover',
#                                    'securityId',
#                                    'preClose', 'change', 'changePct', 'openInterest', 'settlement', 'preSettlement',
#                                    'change1',
#                                    'changePct1']


from fooltrader import settings
from fooltrader.api import technical


def test_get_china_stock_list():
    print(settings.FOOLTRADER_STORE_PATH)
    df = technical.get_security_list('stock', exchanges=['sh', 'sz'])
    assert '000001' in df.index
    assert '金融行业' == df.loc['000001', 'sinaIndustry']

    df = technical.get_security_list('stock', exchanges=['sh'])
    assert '600000' in df.index
    assert '金融行业' == df.loc['600000', 'sinaIndustry']

    df = technical.get_security_list('stock', exchanges=['sh', 'sz'], start_code='000338', end_code='600388')
    assert '000338' in df.index
    assert '600388' in df.index
    assert '600389' not in df.index

    df = technical.get_security_list('stock', exchanges=['sh', 'sz'], codes=['300027', '000002'])
    assert len(df.index) == 2


# Path: fooltrader/settings.py
# BOT_NAME = 'fooltrader'
# SPIDER_MODULES = ['fooltrader.spiders']
# NEWSPIDER_MODULE = 'fooltrader.spiders'
# COMPRESSION_ENABLED = True
# DOWNLOADER_MIDDLEWARES = {
#     'fooltrader.middlewares.ForbiddenHandleMiddleware': 1000,
# }
# AUTOTHROTTLE_DEBUG = False
# FOOLTRADER_STORE_PATH = os.environ.get('FOOLTRADER_STORE_PATH')
#     FOOLTRADER_STORE_PATH = '/home/xuanqi/workspace/github/fooltrader/data'
# STOCK_START_CODE = '000001'
# STOCK_END_CODE = '666666'
# US_STOCK_CODES = ['MSFT', 'AMZN', 'NVDA', 'SINA', 'AAPL']
# AVAILABLE_TICK_DATE = '2004-10-8'
# START_TICK_DATE = '2013-1-1'
# FORCE_DOWNLOAD_SECURITY_LIST = False
# DOWNLOAD_TXT_ENCODING = 'GB2312'
# AUTO_KAFKA = False
# KAFKA_HOST = 'localhost:9092'
# KAFKA_PATH = '/home/xuanqi/software/kafka_2.11-0.11.0.1'
# ZK_KAFKA_HOST = 'localhost:2181'
# DG_PATH = '/Users/xuanqi/software/delegate/DGROOT/bin/delegate'
# SUPPORT_SOCKS2HTTP = False
# TIME_FORMAT_MICRO = "%Y%m%d %H%M%S.%f"
# TIME_FORMAT_SEC = '%Y-%m-%d %H:%M:%S'
# TIME_FORMAT_DAY = '%Y-%m-%d'
# ES_HOSTS = ['localhost:9200']
# SMTP_HOST = 'smtpdm.aliyun.com'
# SMTP_PORT = '80'
# EMAIL_USER_NAME = ''
#     EMAIL_USER_NAME = os.environ.get('EMAIL_USER_NAME')
# EMAIL_PASSWORD = ''
#     EMAIL_PASSWORD = os.environ.get('EMAIL_PASSWORD')
# WEIXIN_APP_ID = ""
#     WEIXIN_APP_ID = os.environ.get("WEIXIN_APP_ID")
# WEIXIN_APP_SECRECT = ""
#     WEIXIN_APP_SECRECT = os.environ.get("WEIXIN_APP_SECRECT")
# EOS_MONGODB_URL = ""
#     EOS_MONGODB_URL = os.environ.get("EOS_MONGODB_URL")
# 
# Path: fooltrader/api/technical.py
# def convert_to_list_if_need(input):
# def get_security_list(security_type='stock', exchanges=None, start_code=None, end_code=None,
#                       mode='simple', start_list_date=None, codes=None):
# def _get_security_item(security_type, exchanges, code=None):
# def to_security_item(security_item, exchange=None):
# def get_ticks(security_item, the_date=None, start_date=None, end_date=None):
# def _parse_tick(tick_path, security_item):
# def get_available_tick_dates(security_item):
# def get_kdata(security_item, exchange=None, the_date=None, start_date=None, end_date=None, fuquan='bfq', source=None,
#               level='day', generate_id=False):
# def get_latest_download_trading_date(security_item, return_next=True, source=None):
# def get_trading_calendar(security_type='future', exchange='shfe'):
# def get_trading_dates(security_item, dtype='list', ignore_today=False, source='163', fuquan='bfq'):
# def kdata_exist(security_item, year, quarter, fuquan=None, source='163'):
# def parse_shfe_day_data(force_parse=False):
# def parse_shfe_data(force_parse=False):
#             KDATA_COLUMN_FUTURE = ['timestamp', 'code', 'name', 'low', 'open', 'close', 'high', 'volume', 'turnover',
#                                    'securityId',
#                                    'preClose', 'change', 'changePct', 'openInterest', 'settlement', 'preSettlement',
#                                    'change1',
#                                    'changePct1']


# Path: tests/test_quote.py
from fooltrader import settings
from fooltrader.api import technical



def test_get_china_stock_list():
    print(settings.FOOLTRADER_STORE_PATH)
    df = technical.get_security_list('stock', exchanges=['sh', 'sz'])
    assert '000001' in df.index
    assert '金融行业' == df.loc['000001', 'sinaIndustry']

    df = technical.get_security_list('stock', exchanges=['sh'])
    assert '600000' in df.index
    assert '金融行业' == df.loc['600000', 'sinaIndustry']

    df = technical.get_security_list('stock', exchanges=['sh', 'sz'], start_code='000338', end_code='600388')
    assert '000338' in df.index
    assert '600388' in df.index
    assert '600389' not in df.index

    df = technical.get_security_list('stock', exchanges=['sh', 'sz'], codes=['300027', '000002'])
    assert len(df.index) == 2


    df = technical.get_security_list('stock', exchanges=['sh', 'sz'], mode='es')