Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_csvio():
hs300 = xa.fundinfo("000311", **ioconf)
len1 = len(hs300.price)
hs300 = xa.fundinfo("000311", **ioconf)
len2 = len(hs300.price)
delete_csvlines(path=ioconf["path"] + "000311.csv")
hs300 = xa.fundinfo("000311", **ioconf)
len3 = len(hs300.price)
assert (len1 == len2) or (len1 - len2 == -1) # temp fixup
# there may be time lag for update of .js API, i.e. 天天基金的该 API 不一定能保证更新昨天的净值,即使不是 QDII
assert (len1 == len3) or (len1 - len3 == -1)
delete_csvlines(path=ioconf["path"] + "001211.csv")
zogqb2 = xa.mfundinfo("001211", **ioconf)
assert round(zogqb.price.iloc[-1].netvalue, 5) in [
round(zogqb2.price.iloc[-1].netvalue, 5),
round(zogqb2.price.iloc[-2].netvalue, 5),
]
delete_csvlines(path=ioconf["path"] + "0000827.csv")
zzhb2 = xa.indexinfo("0000827", **ioconf)
assert (len(zzhb2.price) == len(zzhb.price)) or (
(len(zzhb2.price) - len(zzhb.price)) == 1
)
100,
"2014-01-04",
[[pd.Timestamp("2014-01-03"), 200], [pd.Timestamp("2017-01-03"), 200]],
)
assert str(excinfo.value) == "One cannot move share before the lastest operation"
assert (
hs300.shuhui(
320,
"2018-01-01",
[[pd.Timestamp("2011-01-03"), 200], [pd.Timestamp("2017-12-29"), 200]],
)[1]
== 685.72
)
assert hs300.shengou(200, "2018-07-20")[2] == 105.24
with pytest.raises(FundTypeError) as excinfo:
xa.mfundinfo("000311")
assert str(excinfo.value) == "This code seems to be a fund, use fundinfo instead"
hs300.info()
dax = xa.fundinfo("510030") # test empty shuhuifei and shengoufei case
assert dax.feeinfo == ["小于7天", "1.50%", "大于等于7天", "0.00%"]
def test_fund_update():
zghl = xa.fundinfo(
"501029", **ioconf
) # 164906 maybe possible remainning issue for qdii?
len1 = len(zghl.price)
delete_csvlines(path=ioconf["path"] + "501029.csv", lines=83)
zghl = xa.fundinfo("501029", **ioconf)
len2 = len(zghl.price)
assert (len1 == len2) or (len1 - len2 == -1) # similar fix up
jxzl = xa.mfundinfo("002758", **ioconf)
netvalue = jxzl.price.iloc[-1]["netvalue"]
len3 = len(jxzl.price)
delete_csvlines(path=ioconf["path"] + "002758.csv", lines=9)
jxzl = xa.mfundinfo("002758", **ioconf)
netvaluel = [
round(jxzl.price.iloc[-1]["netvalue"], 4),
round(jxzl.price.iloc[-2]["netvalue"], 4),
]
len4 = len(jxzl.price)
assert (len3 == len4) or (len3 - len4 == -1)
assert round(netvalue, 4) in netvaluel ##天天基金的总量 API 更新越来越慢了。。。
import sys
sys.path.insert(0, "../")
import xalpha as xa
from xalpha.exceptions import FundTypeError
import pandas as pd
import pytest
ioconf = {"save": True, "fetch": True, "path": "pytest", "form": "csv"}
ca = xa.cashinfo(interest=0.0002, start="2015-01-01")
zzhb = xa.indexinfo("0000827", **ioconf)
hs300 = xa.fundinfo("000311")
zogqb = xa.mfundinfo("001211", **ioconf)
def test_fundreport():
# somehow fragile, to be checked
r = xa.FundReport("000827")
assert r.get_report()[0][:2] == "广发"
assert r.analyse_report(1)["bank"][:2] == "兴业"
assert r.show_report_list(type_=0)[0]["FUNDCODE"] == "000827"
assert r.get_report(id_="AN202003171376532533")[0][:2] == "广发"
def test_cash():
assert (
round(ca.price[ca.price["date"] == "2018-01-02"].iloc[0].netvalue, 4) == 1.2453
)
assert ca.code == "mf"