diff --git a/akshare/__init__.py b/akshare/__init__.py index 6c9ee2ae8d0..ed185ff58d5 100644 --- a/akshare/__init__.py +++ b/akshare/__init__.py @@ -2564,9 +2564,10 @@ 1.11.48 fix: fix installation.md 1.11.49 add: add aarch64 support 1.11.50 fix: fix amac_fund_abs support +1.11.51 fix: fix stock_zh_a_daily interface """ -__version__ = "1.11.50" +__version__ = "1.11.51" __author__ = "AKFamily" import sys diff --git a/akshare/stock/cons.py b/akshare/stock/cons.py index 4264ecf8044..6d3c85d30c6 100644 --- a/akshare/stock/cons.py +++ b/akshare/stock/cons.py @@ -33,8 +33,7 @@ "_s_r_a": "page" } zh_sina_a_stock_count_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCount?node=hs_a" -zh_sina_a_stock_hist_url = "https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js" -zh_sina_a_stock_hist_url_weekly = "https://finance.sina.com.cn/realstock/company/{}/hisdata_klc2/klc_kl.js" +zh_sina_a_stock_hist_url = "https://finance.sina.com.cn/realstock/company/{}/hisdata_klc2/klc_kl.js" zh_sina_a_stock_amount_url = "https://stock.finance.sina.com.cn/stock/api/jsonp.php/var%20KKE_ShareAmount_{}=/StockService.getAmountBySymbol?_=20&symbol={}" zh_sina_a_stock_hfq_url = "https://finance.sina.com.cn/realstock/company/{}/hfq.js" zh_sina_a_stock_qfq_url = "https://finance.sina.com.cn/realstock/company/{}/qfq.js" @@ -185,292 +184,448 @@ hk_js_decode = """ function d(t) { - var e, i, n, r, a, o, s, l = (arguments, - 864e5), u = 7657, c = [], h = [], d = ~(3 << 30), f = 1 << 30, - p = [0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29, 30], m = Math, g = function () { - var l, u; - for (l = 0; 64 > l; l++) - h[l] = m.pow(2, l), - 26 > l && (c[l] = v(l + 65), + var e, i, n, r, a, o, s, l = (arguments, + 864e5), u = 7657, c = [], d = [], h = ~(3 << 30), f = 1 << 30, m = [0, 3, 5, 6, 9, 10, 12, 15, 17, 18, 20, 23, 24, 27, 29, 30], p = Math, g = function() { + var l, u; + for (l = 0; 64 > l; l++) + d[l] = p.pow(2, l), + 26 > l && (c[l] = v(l + 65), c[l + 26] = v(l + 97), - 10 > l && (c[l + 52] = v(l + 48))); - for (c.push("+", "/"), - c = c.join(""), - i = t.split(""), - n = i.length, - l = 0; n > l; l++) - i[l] = c.indexOf(i[l]); - return r = {}, + 10 > l && (c[l + 52] = v(l + 48))); + for (c.push("+", "/"), + c = c.join(""), + i = t.split(""), + n = i.length, + l = 0; n > l; l++) + i[l] = c.indexOf(i[l]); + return r = {}, e = o = 0, a = {}, u = w([12, 6]), s = 63 ^ u[1], - { - _1479: T, - _136: _, - _200: S, - _139: k, - _197: _mi_run - }["_" + u[0]] || function () { - return [] - } - }, v = String.fromCharCode, b = function (t) { - return t === {}._ - }, N = function () { - var t, e; - for (t = y(), - e = 1; ;) { - if (!y()) - return e * (2 * t - 1); - e++ - } - }, y = function () { - var t; - return e >= n ? 0 : (t = i[e] & 1 << o, + { + _1479: D, + _136: _, + _200: C, + _139: R, + _197: A, + _3466: O + }["_" + u[0]] || function() { + return [] + } + }, v = String.fromCharCode, b = function(t) { + return t === {}._ + }, N = function() { + var t, e; + for (t = y(), + e = 1; ; ) { + if (!y()) + return e * (2 * t - 1); + e++ + } + }, y = function() { + var t; + return e >= n ? 0 : (t = i[e] & 1 << o, o++, - o >= 6 && (o -= 6, + o >= 6 && (o -= 6, e++), !!t) - }, w = function (t, r, a) { - var s, l, u, c, d; - for (l = [], - u = 0, - r || (r = []), - a || (a = []), - s = 0; s < t.length; s++) - if (c = t[s], + }, w = function(t, r, a) { + var s, l, u, c, h; + for (l = [], + u = 0, + r || (r = []), + a || (a = []), + s = 0; s < t.length; s++) + if (c = t[s], u = 0, c) { - if (e >= n) - return l; - if (t[s] <= 0) - u = 0; - else if (t[s] <= 30) { - for (; d = 6 - o, - d = c > d ? d : c, - u |= (i[e] >> o & (1 << d) - 1) << t[s] - c, - o += d, - o >= 6 && (o -= 6, - e++), - c -= d, - !(0 >= c);) - ; - r[s] && u >= h[t[s] - 1] && (u -= h[t[s]]) + if (e >= n) + return l; + if (t[s] <= 0) + u = 0; + else if (t[s] <= 30) { + for (; h = 6 - o, + h = c > h ? h : c, + u |= (i[e] >> o & (1 << h) - 1) << t[s] - c, + o += h, + o >= 6 && (o -= 6, + e++), + c -= h, + !(0 >= c); ) + ; + r[s] && u >= d[t[s] - 1] && (u -= d[t[s]]) + } else + u = w([30, t[s] - 30], [0, r[s]]), + a[s] || (u = u[0] + u[1] * d[30]); + l[s] = u } else - u = w([30, t[s] - 30], [0, r[s]]), - a[s] || (u = u[0] + u[1] * h[30]); - l[s] = u - } else - l[s] = 0; - return l - }, x = function (t) { - var e, i, n; - for (t > 1 && (e = 0), - e = 0; t > e; e++) - r.d++, + l[s] = 0; + return l + }, x = function() { + var t; + return t = w([3])[0], + 1 == t ? (r.d = w([18], [1])[0], + t = 0) : t || (t = w([6])[0]), + t + }, S = function(t) { + var e, i, n; + for (t > 1 && (e = 0), + e = 0; t > e; e++) + r.d++, n = r.d % 7, - (3 == n || 4 == n) && (r.d += 5 - n); - return i = new Date, + (3 == n || 4 == n) && (r.d += 5 - n); + return i = new Date, i.setTime((u + r.d) * l), i - }, S = function () { - var t, i, a, o, l; - if (s >= 1) - return []; - for (r.d = w([18], [1])[0] - 1, - a = w([3, 3, 30, 6]), - r.p = a[0], - r.ld = a[1], - r.cd = a[2], - r.c = a[3], - r.m = m.pow(10, r.p), - r.pc = r.cd / r.m, - i = [], - t = 0; o = { - d: 1 - }, - y() && (a = w([3])[0], - 0 == a ? o.d = w([6])[0] : 1 == a ? (r.d = w([18])[0], - o.d = 0) : o.d = a), - l = { - day: x(o.d) - }, - y() && (r.ld += N()), - a = w([3 * r.ld], [1]), - r.cd += a[0], - l.close = r.cd / r.m, - i.push(l), - !(e >= n) && (e != n - 1 || 63 & (r.c ^ t + 1)); t++) - ; - return i[0].prevclose = r.pc, + }, k = function(t) { + var e, i, n; + for (n = r.wd || 62, + e = 0; t > e; e++) + do + r.d++; + while (!(n & 1 << (r.d % 7 + 10) % 7)); + return i = new Date, + i.setTime((u + r.d) * l), i - }, _ = function () { - var t, i, a, o, l, u, c, h, d, f, p; - if (s > 2) - return []; - for (c = [], - d = { - v: "volume", - p: "price", - a: "avg_price" - }, - r.d = w([18], [1])[0] - 1, - h = { - day: x(1) - }, - a = w(1 > s ? [3, 3, 4, 1, 1, 1, 5] : [4, 4, 4, 1, 1, 1, 3]), - t = 0; 7 > t; t++) - r[["la", "lp", "lv", "tv", "rv", "zv", "pp"][t]] = a[t]; - for (r.m = m.pow(10, r.pp), - s >= 1 ? (a = w([3, 3]), - r.c = a[0], - a = a[1]) : (a = 5, - r.c = 2), - r.pc = w([6 * a])[0], - h.pc = r.pc / r.m, - r.cp = r.pc, - r.da = 0, - r.sa = r.sv = 0, - t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) { - for (l = {}, - o = {}, - f = r.tv ? y() : 1, - i = 0; 3 > i; i++) - if (p = ["v", "p", "a"][i], - (f ? y() : 0) && (a = N(), - r["l" + p] += a), - u = "v" == p && r.rv ? y() : 1, - a = w([3 * r["l" + p] + ("v" == p ? 7 * u : 0)], [!!i])[0] * (u ? 1 : 100), - o[p] = a, - "v" == p) { - if (!(l[d[p]] = a) && (s > 1 || 241 > t) && (r.zv ? !y() : 1)) { - o.p = 0; - break - } - } else - "a" == p && (r.da = (1 > s ? 0 : r.da) + o.a); - r.sv += o.v, - l[d.p] = (r.cp += o.p) / r.m, + }, T = function(t) { + var e, i, n; + return t ? 0 > t ? (e = T(-t), + [-e[0], -e[1]]) : (e = t % 3, + i = (t - e) / 3, + n = [i, i], + e && n[e - 1]++, + n) : [0, 0] + }, P = function(t, e, i) { + var n, r, a; + for (r = "number" == typeof e ? T(e) : e, + a = T(i), + n = [a[0] - r[0], a[1] - r[1]], + r = 1; n[0] < n[1]; ) + r *= 5, + n[1]--; + for (; n[1] < n[0]; ) + r *= 2, + n[0]--; + if (r > 1 && (t *= r), + n = n[0], + t = E(t), + 0 > n) { + for (; t.length + n <= 0; ) + t = "0" + t; + return n += t.length, + r = t.substr(0, n) - 0, + void 0 === i ? r + "." + t.substr(n) - 0 : (a = t.charAt(n) - 0, + a > 5 ? r++ : 5 == a && (t.substr(n + 1) - 0 > 0 ? r++ : r += 1 & r), + r) + } + for (; n > 0; n--) + t += "0"; + return t - 0 + }, C = function() { + var t, i, a, o, l; + if (s >= 1) + return []; + for (r.d = w([18], [1])[0] - 1, + a = w([3, 3, 30, 6]), + r.p = a[0], + r.ld = a[1], + r.cd = a[2], + r.c = a[3], + r.m = p.pow(10, r.p), + r.pc = r.cd / r.m, + i = [], + t = 0; o = { + d: 1 + }, + y() && (a = w([3])[0], + 0 == a ? o.d = w([6])[0] : 1 == a ? (r.d = w([18])[0], + o.d = 0) : o.d = a), + l = { + date: S(o.d) + }, + y() && (r.ld += N()), + a = w([3 * r.ld], [1]), + r.cd += a[0], + l.close = r.cd / r.m, + i.push(l), + !(e >= n) && (e != n - 1 || 63 & (r.c ^ t + 1)); t++) + ; + return i[0].prevclose = r.pc, + i + }, _ = function() { + var t, i, a, o, l, u, c, d, h, f, m; + if (s > 2) + return []; + for (c = [], + h = { + v: "volume", + p: "price", + a: "avg_price" + }, + r.d = w([18], [1])[0] - 1, + d = { + date: S(1) + }, + a = w(1 > s ? [3, 3, 4, 1, 1, 1, 5] : [4, 4, 4, 1, 1, 1, 3]), + t = 0; 7 > t; t++) + r[["la", "lp", "lv", "tv", "rv", "zv", "pp"][t]] = a[t]; + for (r.m = p.pow(10, r.pp), + s >= 1 ? (a = w([3, 3]), + r.c = a[0], + a = a[1]) : (a = 5, + r.c = 2), + r.pc = w([6 * a])[0], + d.pc = r.pc / r.m, + r.cp = r.pc, + r.da = 0, + r.sa = r.sv = 0, + t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) { + for (l = {}, + o = {}, + f = r.tv ? y() : 1, + i = 0; 3 > i; i++) + if (m = ["v", "p", "a"][i], + (f ? y() : 0) && (a = N(), + r["l" + m] += a), + u = "v" == m && r.rv ? y() : 1, + a = w([3 * r["l" + m] + ("v" == m ? 7 * u : 0)], [!!i])[0] * (u ? 1 : 100), + o[m] = a, + "v" == m) { + if (!(l[h[m]] = a) && (s > 1 || 241 > t) && (r.zv ? !y() : 1)) { + o.p = 0; + break + } + } else + "a" == m && (r.da = (1 > s ? 0 : r.da) + o.a); + r.sv += o.v, + l[h.p] = (r.cp += o.p) / r.m, r.sa += o.v * r.cp, - l[d.a] = b(o.a) ? t ? c[t - 1][d.a] : l[d.p] : r.sv ? ((m.floor((r.sa * (2e3 / r.m) + r.sv) / r.sv) >> 1) + r.da) / 1e3 : l[d.p] + r.da / 1e3, + l[h.a] = b(o.a) ? t ? c[t - 1][h.a] : l[h.p] : r.sv ? ((p.floor((r.sa * (2e3 / r.m) + r.sv) / r.sv) >> 1) + r.da) / 1e3 : l[h.p] + r.da / 1e3, c.push(l) - } - return c[0].date = h.day, - c[0].prevclose = h.pc, + } + return c[0].date = d.date, + c[0].prevclose = d.pc, c - }, T = function () { - var t, e, i, n, a, o, l; - if (s >= 1) - return []; - for (r.lv = 0, - r.ld = 0, - r.cd = 0, - r.cv = [0, 0], - r.p = w([6])[0], - r.d = w([18], [1])[0] - 1, - r.m = m.pow(10, r.p), - a = w([3, 3]), - r.md = a[0], - r.mv = a[1], - t = []; a = w([6]), - a.length;) { - if (i = { - c: a[0] - }, + }, D = function() { + var t, e, i, n, a, o, l; + if (s >= 1) + return []; + for (r.lv = 0, + r.ld = 0, + r.cd = 0, + r.cv = [0, 0], + r.p = w([6])[0], + r.d = w([18], [1])[0] - 1, + r.m = p.pow(10, r.p), + a = w([3, 3]), + r.md = a[0], + r.mv = a[1], + t = []; a = w([6]), + a.length; ) { + if (i = { + c: a[0] + }, n = {}, i.d = 1, - 32 & i.c) - for (; ;) { - if (a = w([6])[0], - 63 == (16 | a)) { - l = 16 & a ? "x" : "u", + 32 & i.c) + for (; ; ) { + if (a = w([6])[0], + 63 == (16 | a)) { + l = 16 & a ? "x" : "u", a = w([3, 3]), i[l + "_d"] = a[0] + r.md, i[l + "_v"] = a[1] + r.mv; - break - } - if (32 & a) { - o = 8 & a ? "d" : "v", + break + } + if (32 & a) { + o = 8 & a ? "d" : "v", l = 16 & a ? "x" : "u", i[l + "_" + o] = (7 & a) + r["m" + o]; - break - } - if (o = 15 & a, + break + } + if (o = 15 & a, 0 == o ? i.d = w([6])[0] : 1 == o ? (r.d = o = w([18])[0], - i.d = 0) : i.d = o, + i.d = 0) : i.d = o, !(16 & a)) - break - } - n.date = x(i.d); - for (o in { - v: 0, - d: 0 - }) - b(i["x_" + o]) || (r["l" + o] = i["x_" + o]), - b(i["u_" + o]) && (i["u_" + o] = r["l" + o]); - for (i.l_l = [i.u_d, i.u_d, i.u_d, i.u_d, i.u_v], - l = p[15 & i.c], - 1 & i.u_v && (l = 31 - l), - 16 & i.c && (i.l_l[4] += 2), - e = 0; 5 > e; e++) - l & 1 << 4 - e && i.l_l[e]++, + break + } + n.date = S(i.d); + for (o in { + v: 0, + d: 0 + }) + b(i["x_" + o]) || (r["l" + o] = i["x_" + o]), + b(i["u_" + o]) && (i["u_" + o] = r["l" + o]); + for (i.l_l = [i.u_d, i.u_d, i.u_d, i.u_d, i.u_v], + l = m[15 & i.c], + 1 & i.u_v && (l = 31 - l), + 16 & i.c && (i.l_l[4] += 2), + e = 0; 5 > e; e++) + l & 1 << 4 - e && i.l_l[e]++, i.l_l[e] *= 3; - i.d_v = w(i.l_l, [1, 0, 0, 1, 1], [0, 0, 0, 0, 1]), + i.d_v = w(i.l_l, [1, 0, 0, 1, 1], [0, 0, 0, 0, 1]), o = r.cd + i.d_v[0], n.open = o / r.m, n.high = (o + i.d_v[1]) / r.m, n.low = (o - i.d_v[2]) / r.m, n.close = (o + i.d_v[3]) / r.m, a = i.d_v[4], - "number" == typeof a && (a = [a, a >= 0 ? 0 : -1]), + "number" == typeof a && (a = [a, a >= 0 ? 0 : -1]), r.cd = o + i.d_v[3], l = r.cv[0] + a[0], - r.cv = [l & d, r.cv[1] + a[1] + !!((r.cv[0] & d) + (a[0] & d) & f)], + r.cv = [l & h, r.cv[1] + a[1] + !!((r.cv[0] & h) + (a[0] & h) & f)], n.volume = (r.cv[0] & f - 1) + r.cv[1] * f, t.push(n) - } - return t - }, k = function () { - var t, e, i, n; - if (s > 1) - return []; - for (r.l = 0, - n = -1, - r.d = w([18])[0] - 1, - i = w([18])[0]; r.d < i;) - e = x(1), + } + return t + }, R = function() { + var t, e, i, n; + if (s > 1) + return []; + for (r.l = 0, + n = -1, + r.d = w([18])[0] - 1, + i = w([18])[0]; r.d < i; ) + e = S(1), 0 >= n ? (y() && (r.l += N()), - n = w([3 * r.l], [0])[0] + 1, + n = w([3 * r.l], [0])[0] + 1, t || (t = [e], - n--)) : t.push(e), + n--)) : t.push(e), n--; - return t - }; - return _mi_run = function () { - var t, i, a, o; - if (s >= 1) - return []; - for (r.f = w([6])[0], - r.c = w([6])[0], - a = [], - r.dv = [], - r.dl = [], - t = 0; t < r.f; t++) - r.dv[t] = 0, - r.dl[t] = 0; - for (t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) { - for (o = [], - i = 0; i < r.f; i++) - y() && (r.dl[i] += N()), - r.dv[i] += w([3 * r.dl[i]], [1])[0], - o[i] = r.dv[i]; - a.push(o) + return t + }, A = function() { + var t, i, a, o; + if (s >= 1) + return []; + for (r.f = w([6])[0], + r.c = w([6])[0], + a = [], + r.dv = [], + r.dl = [], + t = 0; t < r.f; t++) + r.dv[t] = 0, + r.dl[t] = 0; + for (t = 0; !(e >= n) && (e != n - 1 || 7 & (r.c ^ t)); t++) { + for (o = [], + i = 0; i < r.f; i++) + y() && (r.dl[i] += N()), + r.dv[i] += w([3 * r.dl[i]], [1])[0], + o[i] = r.dv[i]; + a.push(o) + } + return a + }, O = function() { + if (r = { + b_avp: 1, + b_ph: 0, + b_phx: 0, + b_sep: 0, + p_p: 6, + p_v: 0, + p_a: 0, + p_e: 0, + p_t: 0, + l_o: 3, + l_h: 3, + l_l: 3, + l_c: 3, + l_v: 5, + l_a: 5, + l_e: 3, + l_t: 0, + u_p: 0, + u_v: 0, + u_a: 0, + wd: 62, + d: 0 + }, + s > 0) + return []; + var t, i, a, o, l, u, c; + for (t = []; ; ) { + if (e >= n) + return void 0; + if (a = { + d: 1, + c: 0 + }, + y()) + if (y()) { + if (y()) { + for (a.c++, + a.a = r.b_avp, + y() && (r.b_avp ^= y(), + r.b_ph ^= y(), + r.b_phx ^= y(), + a.s = r.b_sep, + r.b_sep ^= y(), + y() && (r.wd = w([7])[0]), + a.s ^ r.b_sep && (a.s ? r.u_p = r.u_c : r.u_o = r.u_h = r.u_l = r.u_c = r.u_p)), + u = 0; u < 3 + 2 * r.b_ph; u++) + if (y() && (l = "pvaet".charAt(u), + o = r["p_" + l], + r["p_" + l] += N(), + r["u_" + l] = P(r["u_" + l], o, r["p_" + l]) - 0, + r.b_sep && !u)) + for (c = 0; 4 > c; c++) + l = "ohlc".charAt(c), + r["u_" + l] = P(r["u_" + l], o, r.p_p) - 0; + !r.b_avp && a.a && (r.u_a = P(i && i.amount || 0, 0, r.p_a)) + } + if (y()) + for (a.c++, + u = 0; u < 7 + r.b_ph + r.b_phx; u++) + y() && (6 == u ? a.d = x() : r["l_" + "ohlcva*et".charAt(u)] += N()); + if (y() && (a.c++, + l = r.l_o + (y() && N()), + o = w([3 * l], [1])[0], + a.p = r.b_sep ? r.u_c + o : r.u_p += o), + !a.c) + break + } else + y() ? y() ? y() ? a.d = x() : r.l_v += N() : r.b_ph && y() ? r["l_" + "et".charAt(r.b_phx && y())] += N() : r.l_a += N() : r["l_" + "ohlc".charAt(w([2])[0])] += N(); + for (u = 0; u < 6 + r.b_ph + r.b_phx; u++) + c = "ohlcvaet".charAt(u), + o = (r.b_sep ? 191 : 185) >> u & 1, + a["v_" + c] = w([3 * r["l_" + c]], [o])[0]; + i = { + date: k(a.d) + }, + a.p && (i.prevclose = P(a.p, r.p_p)), + r.b_sep ? (i.open = P(r.u_o += a.v_o, r.p_p), + i.high = P(r.u_h += a.v_h, r.p_p), + i.low = P(r.u_l += a.v_l, r.p_p), + i.close = P(r.u_c += a.v_c, r.p_p)) : (a.o = r.u_p + a.v_o, + i.open = P(a.o, r.p_p), + i.high = P(a.o + a.v_h, r.p_p), + i.low = P(a.o - a.v_l, r.p_p), + i.close = P(r.u_p = a.o + a.v_c, r.p_p)), + i.volume = P(r.u_v += a.v_v, r.p_v), + r.b_avp ? (o = T(r.p_p), + l = T(r.p_v), + i.amount = P(P(Math.floor((r.b_sep ? (r.u_o + r.u_h + r.u_l + r.u_c) / 4 : a.o + (a.v_h - a.v_l + a.v_c) / 4) * r.u_v + .5), [o[0] + l[0], o[1] + l[1]], r.p_a) + a.v_a, r.p_a)) : (r.u_a += a.v_a, + i.amount = P(r.u_a, r.p_a)), + r.b_ph && (i.postVol = P(a.v_e, r.p_e), + i.postAmt = P(Math.floor(i.postVol * i.close + (r.b_phx ? P(a.v_t, r.p_t) : 0) + .5), 0)), + t.push(i) + } + return t + }, E = function(t) { + var e, i, n; + if (t = (t || 0).toString(), + n = [], + i = t.toLowerCase().indexOf("e"), + i > 0) { + for (e = t.substr(i + 1) - 0; e >= 0; e--) + n.push(Math.floor(e * Math.pow(10, -e) + .5) - 0); + return n.join("") + } + return t + }; + return g()() } - return a - } - , - g()() -} + ; """ zh_js_decode = """ diff --git a/akshare/stock/stock_zh_a_sina.py b/akshare/stock/stock_zh_a_sina.py index 5014076d37c..cf939d7cd26 100644 --- a/akshare/stock/stock_zh_a_sina.py +++ b/akshare/stock/stock_zh_a_sina.py @@ -148,9 +148,9 @@ def stock_zh_a_daily( def _fq_factor(method: str) -> pd.DataFrame: if method == "hfq": - res = requests.get(zh_sina_a_stock_hfq_url.format(symbol)) + r = requests.get(zh_sina_a_stock_hfq_url.format(symbol)) hfq_factor_df = pd.DataFrame( - eval(res.text.split("=")[1].split("\n")[0])["data"] + eval(r.text.split("=")[1].split("\n")[0])["data"] ) if hfq_factor_df.shape[0] == 0: raise ValueError("sina hfq factor not available") @@ -160,9 +160,9 @@ def _fq_factor(method: str) -> pd.DataFrame: hfq_factor_df.reset_index(inplace=True) return hfq_factor_df else: - res = requests.get(zh_sina_a_stock_qfq_url.format(symbol)) + r = requests.get(zh_sina_a_stock_qfq_url.format(symbol)) qfq_factor_df = pd.DataFrame( - eval(res.text.split("=")[1].split("\n")[0])["data"] + eval(r.text.split("=")[1].split("\n")[0])["data"] ) if qfq_factor_df.shape[0] == 0: raise ValueError("sina hfq factor not available") @@ -175,21 +175,26 @@ def _fq_factor(method: str) -> pd.DataFrame: if adjust in ("hfq-factor", "qfq-factor"): return _fq_factor(adjust.split("-")[0]) - res = requests.get(zh_sina_a_stock_hist_url.format(symbol)) + r = requests.get(zh_sina_a_stock_hist_url.format(symbol)) js_code = py_mini_racer.MiniRacer() js_code.eval(hk_js_decode) dict_list = js_code.call( - "d", res.text.split("=")[1].split(";")[0].replace('"', "") + "d", r.text.split("=")[1].split(";")[0].replace('"', "") ) # 执行js解密代码 data_df = pd.DataFrame(dict_list) data_df.index = pd.to_datetime(data_df["date"]).dt.date del data_df["date"] + try: + del data_df["prevclose"] + except: + pass data_df = data_df.astype("float") r = requests.get(zh_sina_a_stock_amount_url.format(symbol, symbol)) amount_data_json = demjson.decode( r.text[r.text.find("["): r.text.rfind("]") + 1] ) amount_data_df = pd.DataFrame(amount_data_json) + amount_data_df.columns = ['date', 'outstanding_share'] amount_data_df.index = pd.to_datetime(amount_data_df.date) del amount_data_df["date"] temp_df = pd.merge( @@ -205,21 +210,22 @@ def _fq_factor(method: str) -> pd.DataFrame: print("Error:", e) temp_df = temp_df.astype(float) - temp_df["amount"] = temp_df["amount"] * 10000 - temp_df["turnover"] = temp_df["volume"] / temp_df["amount"] + temp_df["outstanding_share"] = temp_df["outstanding_share"] * 10000 + temp_df["turnover"] = temp_df["volume"] / temp_df["outstanding_share"] temp_df.columns = [ "open", "high", "low", "close", "volume", + "amount", "outstanding_share", "turnover", ] if adjust == "": temp_df = temp_df[start_date:end_date] temp_df.drop_duplicates( - subset=["open", "high", "low", "close", "volume"], inplace=True + subset=["open", "high", "low", "close", "volume", "amount"], inplace=True ) temp_df["open"] = round(temp_df["open"], 2) temp_df["high"] = round(temp_df["high"], 2) @@ -228,6 +234,7 @@ def _fq_factor(method: str) -> pd.DataFrame: temp_df.dropna(inplace=True) temp_df.drop_duplicates(inplace=True) temp_df.reset_index(inplace=True) + temp_df['date'] = pd.to_datetime(temp_df['date'], errors="coerce").dt.date return temp_df if adjust == "hfq": res = requests.get(zh_sina_a_stock_hfq_url.format(symbol)) @@ -256,7 +263,7 @@ def _fq_factor(method: str) -> pd.DataFrame: temp_df = temp_df.astype(float) temp_df.dropna(inplace=True) temp_df.drop_duplicates( - subset=["open", "high", "low", "close", "volume"], inplace=True + subset=["open", "high", "low", "close", "volume", "amount"], inplace=True ) temp_df["open"] = temp_df["open"] * temp_df["hfq_factor"] temp_df["high"] = temp_df["high"] * temp_df["hfq_factor"] @@ -270,6 +277,7 @@ def _fq_factor(method: str) -> pd.DataFrame: temp_df["close"] = round(temp_df["close"], 2) temp_df.dropna(inplace=True) temp_df.reset_index(inplace=True) + temp_df['date'] = pd.to_datetime(temp_df['date'], errors="coerce").dt.date return temp_df if adjust == "qfq": @@ -299,7 +307,7 @@ def _fq_factor(method: str) -> pd.DataFrame: temp_df = temp_df.astype(float) temp_df.dropna(inplace=True) temp_df.drop_duplicates( - subset=["open", "high", "low", "close", "volume"], inplace=True + subset=["open", "high", "low", "close", "volume", "amount"], inplace=True ) temp_df["open"] = temp_df["open"] / temp_df["qfq_factor"] temp_df["high"] = temp_df["high"] / temp_df["qfq_factor"] @@ -313,6 +321,7 @@ def _fq_factor(method: str) -> pd.DataFrame: temp_df["close"] = round(temp_df["close"], 2) temp_df.dropna(inplace=True) temp_df.reset_index(inplace=True) + temp_df['date'] = pd.to_datetime(temp_df['date'], errors="coerce").dt.date return temp_df @@ -394,7 +403,7 @@ def stock_zh_a_minute( temp_df = pd.DataFrame(data_json).iloc[:, :6] if temp_df.empty: print(f"{symbol} 股票数据不存在,请检查是否已退市") - return + return pd.DataFrame() try: stock_zh_a_daily(symbol=symbol, adjust="qfq") except: @@ -483,13 +492,13 @@ def stock_zh_a_minute( stock_zh_a_daily_hfq_df_one = stock_zh_a_daily( symbol="sz000001", start_date="19910403", - end_date="20230614", - adjust="qfq", + end_date="20231027", + adjust="hfq", ) print(stock_zh_a_daily_hfq_df_one) stock_zh_a_daily_hfq_df_three = stock_zh_a_daily( - symbol="sz002008", + symbol="sz000001", start_date="19900103", end_date="20210118", adjust="qfq", @@ -501,10 +510,10 @@ def stock_zh_a_minute( ) print(stock_zh_a_daily_hfq_df_two) - qfq_factor_df = stock_zh_a_daily(symbol="bj430047", adjust="qfq-factor") + qfq_factor_df = stock_zh_a_daily(symbol="sz000002", adjust="qfq-factor") print(qfq_factor_df) - hfq_factor_df = stock_zh_a_daily(symbol="bj430047", adjust="hfq-factor") + hfq_factor_df = stock_zh_a_daily(symbol="sz000002", adjust="hfq-factor") print(hfq_factor_df) stock_zh_a_daily_hfq_factor_df = stock_zh_a_daily( diff --git a/docs/changelog.md b/docs/changelog.md index 309e5b0358d..82139ae72af 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -68,6 +68,10 @@ ## 更新说明详情 +1.11.51 fix: fix stock_zh_a_daily interface + + 1. 修复 stock_zh_a_daily 接口 + 1.11.50 fix: fix amac_fund_abs support 1. 修复 amac_fund_abs 接口 @@ -3042,6 +3046,8 @@ ## 版本更新说明 +1.11.51 fix: fix stock_zh_a_daily interface + 1.11.50 fix: fix amac_fund_abs support 1.11.49 add: add aarch64 support diff --git a/docs/data/stock/stock.md b/docs/data/stock/stock.md index ad65694bdad..b9bacd2146b 100644 --- a/docs/data/stock/stock.md +++ b/docs/data/stock/stock.md @@ -1186,42 +1186,43 @@ P.S. 建议切换为 stock_zh_a_hist 接口使用(该接口数据质量高, 访 输出参数-历史行情数据 -| 名称 | 类型 | 描述 | -|-------------------|------------|---------------| -| date | datetime64 | 交易日 | -| open | float64 | 开盘价 | -| high | float64 | 最高价 | -| low | float64 | 最低价 | -| close | float64 | 收盘价 | -| volume | float64 | 成交量; 注意单位: 股 | -| outstanding_share | float64 | 流动股本; 注意单位: 股 | -| turnover | float64 | 换手率=成交量/流动股本 | +| 名称 | 类型 | 描述 | +|-------------------|---------|---------------| +| date | object | 交易日 | +| open | float64 | 开盘价 | +| high | float64 | 最高价 | +| low | float64 | 最低价 | +| close | float64 | 收盘价 | +| volume | float64 | 成交量; 注意单位: 股 | +| amount | float64 | 成交额; 注意单位: 元 | +| outstanding_share | float64 | 流动股本; 注意单位: 股 | +| turnover | float64 | 换手率=成交量/流动股本 | 接口示例-历史行情数据(前复权) ```python import akshare as ak -stock_zh_a_daily_qfq_df = ak.stock_zh_a_daily(symbol="sz000002", start_date="20101103", end_date="20201116", adjust="qfq") +stock_zh_a_daily_qfq_df = ak.stock_zh_a_daily(symbol="sz000001", start_date="19910403", end_date="20231027", adjust="qfq") print(stock_zh_a_daily_qfq_df) ``` 数据示例-历史行情数据(前复权) ``` - open high low ... volume outstanding_share turnover -date ... -2010-11-03 6.98 7.20 6.90 ... 146025616.0 9.656080e+09 0.015123 -2010-11-04 7.13 7.22 7.04 ... 104870112.0 9.656080e+09 0.010861 -2010-11-05 7.22 7.28 7.04 ... 130233640.0 9.656080e+09 0.013487 -2010-11-08 7.12 7.34 7.12 ... 162830704.0 9.656080e+09 0.016863 -2010-11-09 7.17 7.23 6.88 ... 188507360.0 9.656080e+09 0.019522 - ... ... ... ... ... ... ... -2020-11-10 29.70 30.11 29.20 ... 61377060.0 9.714315e+09 0.006318 -2020-11-11 29.37 30.25 29.25 ... 88521186.0 9.714315e+09 0.009112 -2020-11-12 29.76 29.81 29.38 ... 45905719.0 9.714315e+09 0.004726 -2020-11-13 29.56 29.69 28.83 ... 66013466.0 9.714315e+09 0.006795 -2020-11-16 29.39 29.50 29.00 ... 51657638.0 9.714315e+09 0.005318 + date open high ... amount outstanding_share turnover +0 1991-04-03 0.39 0.39 ... 5.000000e+03 3.710000e+07 0.000003 +1 1991-04-04 0.39 0.39 ... 1.500000e+04 3.710000e+07 0.000008 +2 1991-04-05 0.38 0.38 ... 1.000000e+04 3.710000e+07 0.000005 +3 1991-04-08 0.38 0.38 ... 1.000000e+04 3.710000e+07 0.000005 +4 1991-04-09 0.38 0.38 ... 1.900000e+04 3.710000e+07 0.000011 + ... ... ... ... ... ... ... +7730 2023-10-23 10.59 10.60 ... 5.570322e+08 1.940555e+10 0.002733 +7731 2023-10-24 10.54 10.61 ... 8.015284e+08 1.940555e+10 0.003920 +7732 2023-10-25 10.51 10.54 ... 1.470972e+09 1.940555e+10 0.007273 +7733 2023-10-26 10.31 10.42 ... 6.219153e+08 1.940555e+10 0.003092 +7734 2023-10-27 10.38 10.48 ... 9.575875e+08 1.940555e+10 0.004740 +[7735 rows x 9 columns] ``` 接口示例-历史行情数据(后复权) @@ -1229,25 +1230,26 @@ date ... ```python import akshare as ak -stock_zh_a_daily_hfq_df = ak.stock_zh_a_daily(symbol="sz000002", start_date='20201103', end_date='20201116', adjust="hfq") +stock_zh_a_daily_hfq_df = ak.stock_zh_a_daily(symbol="sz000001", start_date="19910403", end_date="20231027", adjust="hfq") print(stock_zh_a_daily_hfq_df) ``` 数据示例-历史行情数据(后复权) ``` - open high low ... volume outstanding_share turnover -date ... -2020-11-03 4010.19 4031.67 3982.98 ... 61766600.0 9.714315e+09 0.006358 -2020-11-04 4017.35 4045.99 3995.87 ... 45499180.0 9.714315e+09 0.004684 -2020-11-05 4074.64 4204.97 4054.59 ... 120119594.0 9.714315e+09 0.012365 -2020-11-06 4202.10 4235.04 4157.70 ... 85288066.0 9.714315e+09 0.008780 -2020-11-09 4256.53 4276.58 4180.62 ... 81118542.0 9.714315e+09 0.008350 -2020-11-10 4253.66 4312.38 4182.05 ... 61377060.0 9.714315e+09 0.006318 -2020-11-11 4206.40 4332.43 4189.21 ... 88521186.0 9.714315e+09 0.009112 -2020-11-12 4262.26 4269.42 4207.83 ... 45905719.0 9.714315e+09 0.004726 -2020-11-13 4233.61 4252.23 4129.06 ... 66013466.0 9.714315e+09 0.006795 -2020-11-16 4209.26 4225.02 4153.41 ... 51657638.0 9.714315e+09 0.005318 + date open high ... amount outstanding_share turnover +0 1991-04-03 49.00 49.00 ... 5.000000e+03 3.710000e+07 0.000003 +1 1991-04-04 48.76 48.76 ... 1.500000e+04 3.710000e+07 0.000008 +2 1991-04-05 48.52 48.52 ... 1.000000e+04 3.710000e+07 0.000005 +3 1991-04-08 48.04 48.04 ... 1.000000e+04 3.710000e+07 0.000005 +4 1991-04-09 47.80 47.80 ... 1.900000e+04 3.710000e+07 0.000011 + ... ... ... ... ... ... ... +7730 2023-10-23 1341.02 1342.28 ... 5.570322e+08 1.940555e+10 0.002733 +7731 2023-10-24 1334.69 1343.55 ... 8.015284e+08 1.940555e+10 0.003920 +7732 2023-10-25 1330.89 1334.69 ... 1.470972e+09 1.940555e+10 0.007273 +7733 2023-10-26 1305.56 1319.49 ... 6.219153e+08 1.940555e+10 0.003092 +7734 2023-10-27 1314.42 1327.09 ... 9.575875e+08 1.940555e+10 0.004740 +[7735 rows x 9 columns] ``` 接口示例-前复权因子 @@ -1262,42 +1264,44 @@ print(qfq_factor_df) 数据示例-前复权因子 ``` - qfq_factor -date -2020-08-14 1.0000000000000000 -2019-08-15 1.0368559887152000 -2018-08-23 1.0783980437203000 -2017-08-29 1.1205595658467000 -2016-07-29 1.1586836854427000 -2015-07-21 1.2071867234379000 -2014-05-08 1.2478327410621000 -2013-05-16 1.3164133608792000 -2012-07-05 1.3377030648287000 -2011-05-27 1.3570684766804000 -2010-05-18 1.3744667904840000 -2009-06-08 1.3885124365181000 -2008-06-16 1.3950374009754000 -2007-05-16 2.2456699625458000 -2006-07-21 3.3906467379279000 -2005-06-29 3.4764135188199000 -2004-05-26 5.3736026037856000 -2003-05-23 8.1158399710544000 -2002-07-17 16.4702057311185000 -2001-08-21 16.7388877169443000 -2000-08-17 16.9482692172257000 -2000-01-10 17.1244466519161980 -1999-08-06 18.3747279845260000 -1998-07-10 20.3681591223534000 -1997-07-14 22.6729771283040000 -1997-06-27 26.4431943252300000 -1996-08-06 30.5408061754980000 -1995-07-04 34.1548015729318950 -1994-06-21 40.5700619999530000 -1993-04-05 55.8148047629125000 -1992-03-30 83.8869605857810100 -1991-06-10 100.6643527029372100 -1991-01-29 143.2209726780930000 -1900-01-01 143.2209726780930000 + date qfq_factor +0 2023-08-25 1.0000000000000000 +1 2022-08-25 1.0517754291451000 +2 2021-08-25 1.1168798473057000 +3 2020-08-14 1.1810093745970000 +4 2019-08-15 1.2245366427798000 +5 2018-08-23 1.2735981991808000 +6 2017-08-29 1.3233913520593000 +7 2016-07-29 1.3684162947004000 +8 2015-07-21 1.4256988372693000 +9 2014-05-08 1.4737021651235000 +10 2013-05-16 1.5546965200431000 +11 2012-07-05 1.5798398599899000 +12 2011-05-27 1.6027105929296000 +13 2010-05-18 1.6232581646338000 +14 2009-06-08 1.6398462042724000 +15 2008-06-16 1.6475522484654000 +16 2007-05-16 2.6521572780175000 +17 2006-07-21 4.0043855834397000 +18 2005-06-29 4.1056769557021000 +19 2004-05-26 6.3462750504298000 +20 2003-05-23 9.5848830885446000 +21 2002-07-17 19.4514673699928000 +22 2001-08-21 19.7687833140383020 +23 2000-08-17 20.0160648287379000 +24 2000-01-10 20.2241320306998030 +25 1999-08-06 21.7007260053956000 +26 1998-07-10 24.0549868667835000 +27 1997-07-14 26.7769985385511000 +28 1997-06-27 31.2296603923877000 +29 1996-08-06 36.0689784010141000 +30 1995-07-04 40.3371408451341000 +31 1994-06-21 47.9136235499274000 +32 1993-04-05 65.9178076663026900 +33 1992-03-30 99.0712868582592000 +34 1991-06-10 118.8855442299110900 +35 1991-01-29 169.1453113717332000 +36 1900-01-01 169.1453113717332000 ``` 接口示例-后复权因子 @@ -1312,42 +1316,44 @@ print(hfq_factor_df) 数据示例-后复权因子 ``` - hfq_factor -date -2020-08-14 143.2209726780930000 -2019-08-15 138.1300530033660000 -2018-08-23 132.8090063887723000 -2017-08-29 127.8120120012347900 -2016-07-29 123.6066188533391900 -2015-07-21 118.6402814886960200 -2014-05-08 114.7757772056767000 -2013-05-16 108.7963529802222000 -2012-07-05 107.0648460362397000 -2011-05-27 105.5370271575669000 -2010-05-18 104.2011154213951000 -2009-06-08 103.1470578954562000 -2008-06-16 102.6646114132510000 -2007-05-16 63.7765010294438000 -2006-07-21 42.2400160641970000 -2005-06-29 41.1979104047185000 -2004-05-26 26.6526915438809980 -2003-05-23 17.6470917599285000 -2002-07-17 8.6957610011813000 -2001-08-21 8.5561821729119010 -2000-08-17 8.4504777946604000 -2000-01-10 8.3635387226989000 -1999-08-06 7.7944540348408990 -1998-07-10 7.0316110463273000 -1997-07-14 6.3168137059205000 -1997-06-27 5.4161751759863000 -1996-08-06 4.6894954853220000 -1995-07-04 4.1932895546844000 -1994-06-21 3.5302133055222000 -1993-04-05 2.5660032904614000 -1992-03-30 1.7073091178651000 -1991-06-10 1.4227575982209000 -1991-01-29 1.0000000000000000 -1900-01-01 1.0000000000000000 + date hfq_factor +0 2023-08-25 169.1453113717332000 +1 2022-08-25 160.8188465756604000 +2 2021-08-25 151.4445011965874000 +3 2020-08-14 143.2209726780933200 +4 2019-08-15 138.1300530033661900 +5 2018-08-23 132.8090063887726200 +6 2017-08-29 127.8120120012352000 +7 2016-07-29 123.6066188533395000 +8 2015-07-21 118.6402814886964000 +9 2014-05-08 114.7757772056770000 +10 2013-05-16 108.7963529802224000 +11 2012-07-05 107.0648460362401000 +12 2011-05-27 105.5370271575670000 +13 2010-05-18 104.2011154213954000 +14 2009-06-08 103.1470578954563000 +15 2008-06-16 102.6646114132513100 +16 2007-05-16 63.7765010294439100 +17 2006-07-21 42.2400160641971000 +18 2005-06-29 41.1979104047185000 +19 2004-05-26 26.6526915438809980 +20 2003-05-23 17.6470917599285000 +21 2002-07-17 8.6957610011813000 +22 2001-08-21 8.5561821729119010 +23 2000-08-17 8.4504777946604000 +24 2000-01-10 8.3635387226989000 +25 1999-08-06 7.7944540348408990 +26 1998-07-10 7.0316110463273000 +27 1997-07-14 6.3168137059205000 +28 1997-06-27 5.4161751759863000 +29 1996-08-06 4.6894954853220000 +30 1995-07-04 4.1932895546844000 +31 1994-06-21 3.5302133055222000 +32 1993-04-05 2.5660032904614000 +33 1992-03-30 1.7073091178651000 +34 1991-06-10 1.4227575982209000 +35 1991-01-29 1.0000000000000000 +36 1900-01-01 1.0000000000000000 ``` ##### 分时数据-新浪 diff --git a/docs/introduction.md b/docs/introduction.md index 4bf136256ab..c76a4fd8009 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -6,7 +6,7 @@ **风险提示:[AKShare](https://github.com/akfamily/akshare) 开源财经数据接口库所采集的数据皆来自公开的数据源,不涉及任何个人隐私数据和非公开数据。 同时本项目提供的数据接口及相关数据仅用于学术研究,任何个人、机构及团体使用本项目的数据接口及相关数据请注意商业风险。** -1. 本文档更新时间:**2023-10-26**; +1. 本文档更新时间:**2023-10-27**; 2. 如有 [AKShare](https://github.com/akfamily/akshare) 库、文档及数据的相关问题,请在 [AKShare Issues](https://github.com/akfamily/akshare/issues) 中提 Issues; 3. 欢迎关注 **数据科学实战** 微信公众号:
; 4. 如果您的问题未能在文档中找到答案,您也可以加入 **AKShare-VIP QQ 群**: 为了提高问答质量,此群为收费群(一杯咖啡钱即可入群,赠送[《AKShare-初阶-使用教学》](https://zmj.xet.tech/s/wck86)视频课),可以添加 **AKShare-小助手** QQ:1254836886,由小助手邀请入群! ![](https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/qrcode/qr_code_1254836886.jpg)