def test_get_price():
    # 传入两个重复股票
    get_price(['000001.XSHE', '000001.XSHE'],
              start_date=datetime.date(2015, 1, 1),
              end_date=datetime.date(2015, 2, 1),
              frequency='daily',
              fields=(u'open', 'close', 'paused'))

    get_price('000300.XSHG')
    get_price(u'000300.XSHG')
    get_price('000001.XSHE',
              start_date=datetime.date(2015, 1, 1),
              end_date=datetime.date(2015, 2, 1),
              frequency='daily',
              fields=(u'open', 'close', 'paused', 'factor'))
    get_price('000001.XSHE',
              start_date=datetime.datetime(2015, 1, 1),
              end_date=datetime.datetime(2015, 2, 1),
              frequency='daily',
              fields=[u'open', 'close'])
    get_price('000001.XSHE',
              start_date=datetime.datetime(2015, 1, 1),
              end_date=datetime.datetime(2015, 2, 1),
              frequency='daily',
              fields='open')
    assert get_price('000001.XSHE', start_date='2015-01-01', end_date='2015-02-01', frequency='1d',
                     fq=None).to_csv().replace('\r', '') == \
        """,open,close,high,low,volume,money
2015-01-05,15.99,16.02,16.28,15.6,286043648.0,4565387776.0
2015-01-06,15.85,15.78,16.39,15.55,216642144.0,3453446144.0
2015-01-07,15.56,15.48,15.83,15.3,170012064.0,2634796288.0
2015-01-08,15.5,14.96,15.57,14.9,140771424.0,2128003456.0
2015-01-09,14.9,15.08,15.87,14.71,250850016.0,3835378176.0
2015-01-12,14.87,14.77,15.05,14.5,155329088.0,2293104640.0
2015-01-13,14.65,14.68,14.9,14.61,81687480.0,1204987136.0
2015-01-14,14.78,14.81,15.2,14.7,126302960.0,1889296640.0
2015-01-15,14.85,15.35,15.35,14.71,124217032.0,1868795904.0
2015-01-16,15.4,15.37,15.62,15.18,155584640.0,2403346176.0
2015-01-19,14.01,13.83,14.57,13.83,213712368.0,3016203008.0
2015-01-20,13.83,13.83,14.06,13.56,149101808.0,2064280576.0
2015-01-21,13.88,14.42,14.6,13.75,194053040.0,2758192640.0
2015-01-22,14.34,14.3,14.52,14.16,125501608.0,1801436288.0
2015-01-23,14.36,14.4,14.63,14.3,145918192.0,2108746752.0
2015-01-26,14.36,14.34,14.44,14.16,105760576.0,1508446592.0
2015-01-27,14.35,13.99,14.37,13.83,133949464.0,1881058944.0
2015-01-28,13.87,14.06,14.3,13.8,124087752.0,1742175744.0
2015-01-29,13.82,13.9,14.01,13.75,101675328.0,1408825344.0
2015-01-30,13.93,13.93,14.12,13.76,93011672.0,1298735744.0
"""
    day_columns = 'open close high low volume money pre_close high_limit low_limit paused avg factor'.split()
    assert round_df(get_price('000002.XSHE', fields=day_columns, start_date='2014-12-30',
                              end_date='2015-01-06', fq=None), 12).to_csv().replace('\r', '') == \
        """,open,close,high,low,volume,money,pre_close,high_limit,low_limit,paused,avg,factor
2014-12-30,12.45,12.64,13.15,12.19,386124416.0,4894974976.0,12.43,13.67,11.19,0.0,12.68,1.0
2014-12-31,12.6,13.9,13.9,12.46,489954464.0,6494929920.0,12.64,13.9,11.38,0.0,13.26,1.0
2015-01-05,14.39,14.91,15.29,14.22,656083584.0,9700711424.0,13.9,15.29,12.51,0.0,14.79,1.0
2015-01-06,14.6,14.36,14.99,14.05,334634688.0,4839616000.0,14.91,16.4,13.42,0.0,14.46,1.0
"""
    assert get_price(['000001.XSHE', '000002.XSHE'], fields='close', start_date='2014-12-30',
                     end_date='2015-01-06', fq=None, panel=False).to_csv().replace('\r', '') == \
        """,time,code,close
0,2014-12-30,000001.XSHE,15.5
1,2014-12-31,000001.XSHE,15.84
2,2015-01-05,000001.XSHE,16.02
3,2015-01-06,000001.XSHE,15.78
4,2014-12-30,000002.XSHE,12.64
5,2014-12-31,000002.XSHE,13.9
6,2015-01-05,000002.XSHE,14.91
7,2015-01-06,000002.XSHE,14.36
"""
    df = get_price('000001.XSHE', frequency='5d', start_date='2014-12-01', end_date='2015-01-20', fq=None)
    assert df.to_csv().replace('\r', '') == \
        """,open,close,high,low,volume,money
2014-12-05,12.6,14.53,15.23,12.08,1981703360.0,26377940992.0
2014-12-12,14.21,13.94,15.53,13.02,1538351152.0,22132453632.0
2014-12-19,13.75,15.0,15.67,13.27,1307583232.0,19036847360.0
2014-12-26,14.9,15.1,16.16,13.68,1170986224.0,17439384832.0
2015-01-06,15.61,15.78,16.39,14.75,1237915024.0,19400459776.0
2015-01-13,15.56,14.68,15.87,14.5,798650072.0,12096269696.0
2015-01-20,14.78,13.83,15.62,13.56,768918808.0,11241922304.0
"""

    fields = ['open', 'close', 'low', 'high', 'volume', 'money', 'factor',
              'high_limit','low_limit', 'avg', 'pre_close', 'paused']
    data = get_price('000300.XSHG', fields=fields)
    print(data.dtypes)
,open,close,high,low,volume,money
2015-01-05,15.99,16.02,16.28,15.6,286043648.0,4565387776.0
2015-01-06,15.85,15.78,16.39,15.55,216642144.0,3453446144.0
2015-01-07,15.56,15.48,15.83,15.3,170012064.0,2634796288.0
2015-01-08,15.5,14.96,15.57,14.9,140771424.0,2128003456.0
2015-01-09,14.9,15.08,15.87,14.71,250850016.0,3835378176.0
2015-01-12,14.87,14.77,15.05,14.5,155329088.0,2293104640.0
2015-01-13,14.65,14.68,14.9,14.61,81687480.0,1204987136.0
2015-01-14,14.78,14.81,15.2,14.7,126302960.0,1889296640.0
2015-01-15,14.85,15.35,15.35,14.71,124217032.0,1868795904.0
2015-01-16,15.4,15.37,15.62,15.18,155584640.0,2403346176.0
2015-01-19,14.01,13.83,14.57,13.83,213712368.0,3016203008.0
2015-01-20,13.83,13.83,14.06,13.56,149101808.0,2064280576.0
2015-01-21,13.88,14.42,14.6,13.75,194053040.0,2758192640.0
2015-01-22,14.34,14.3,14.52,14.16,125501608.0,1801436288.0
2015-01-23,14.36,14.4,14.63,14.3,145918192.0,2108746752.0
2015-01-26,14.36,14.34,14.44,14.16,105760576.0,1508446592.0
2015-01-27,14.35,13.99,14.37,13.83,133949464.0,1881058944.0
2015-01-28,13.87,14.06,14.3,13.8,124087752.0,1742175744.0
2015-01-29,13.82,13.9,14.01,13.75,101675328.0,1408825344.0
2015-01-30,13.93,13.93,14.12,13.76,93011672.0,1298735744.0
tests/test_api.py