from jqdatasdk import *
auth('17099121314','gqs07070305799')
auth success
import akshare as ak
stock_zh_a_new_em_df = ak.stock_zh_a_new_em()
print(stock_zh_a_new_em_df)
序号 代码 名称 最新价 涨跌幅 涨跌额 成交量 成交额 振幅 \
0 1 688103 N国力 74.20 516.28 62.16 171725 1.204436e+09 143.52
1 2 688091 上海谊众-U 41.40 -15.49 -7.59 104268 4.464245e+08 9.70
2 3 605599 菜百股份 15.84 10.00 1.44 3077 4.873936e+06 0.00
3 4 301058 C中粮 12.21 -10.22 -1.39 483215 6.102785e+08 8.68
4 5 301057 C汇隆 27.30 7.52 1.91 162335 4.185909e+08 22.84
.. ... ... ... ... ... ... ... ... ...
463 464 300895 铜牛信息 42.56 -2.90 -1.27 51278 2.195194e+08 3.67
464 465 300893 松原股份 22.27 -2.32 -0.53 21065 4.763458e+07 3.82
465 466 003008 开普检测 32.07 -1.32 -0.43 4267 1.378321e+07 2.15
466 467 003007 直真科技 17.60 -0.68 -0.12 6293 1.106679e+07 1.64
467 468 688526 科前生物 27.88 -0.07 -0.02 11933 3.325300e+07 2.11
最高 最低 今开 昨收 量比 换手率 市盈率-动态 市净率
0 79.28 62.00 62.00 12.04 NaN 88.30 103.71 8.23
1 45.95 41.20 45.95 48.99 0.63 43.20 -179.13 3.75
2 15.84 15.84 15.84 14.40 0.25 0.40 31.39 4.09
3 13.38 12.20 12.90 13.60 0.72 50.47 60.34 3.77
4 28.68 22.88 23.40 25.39 0.93 62.70 39.62 5.27
.. ... ... ... ... ... ... ... ...
463 43.88 42.27 43.83 43.83 0.53 17.62 85.41 4.35
464 23.11 22.24 22.79 22.80 0.85 5.62 31.68 4.68
465 32.68 31.98 32.49 32.50 0.97 2.13 36.52 2.59
466 17.77 17.48 17.67 17.72 0.85 2.42 -14.94 2.22
467 28.20 27.61 27.88 27.90 0.64 1.41 22.65 4.53
[468 rows x 17 columns]
stock_zh_index_spot_df = ak.stock_zh_index_spot()
print(stock_zh_index_spot_df)
100%|██████████| 8/8 [00:05<00:00, 1.34it/s] 代码 名称 最新价 涨跌额 涨跌幅 昨收 今开 \
0 sh000001 上证指数 3703.1103 9.981 0.270 3693.1296 3691.1856
1 sh000002 A股指数 3881.1866 10.479 0.271 3870.7072 3868.6758
2 sh000003 B股指数 277.2990 -0.091 -0.033 277.3903 276.9716
3 sh000004 工业指数 3483.2656 5.303 0.152 3477.9625 3474.9399
4 sh000005 商业指数 2994.5830 -1.319 -0.044 2995.9023 2997.6732
.. ... ... ... ... ... ... ...
581 sz988006 3424.7650 21.689 0.637 3403.0760 3389.8960
582 sz988007 3429.2810 22.563 0.662 3406.7180 3393.5860
583 sz988106 3647.9960 23.102 0.637 3624.8940 3610.8540
584 sz988107 3652.7920 24.034 0.662 3628.7580 3614.7710
585 sz988201 1679.3850 11.135 0.667 1668.2500 1671.8600
最高 最低 成交量 成交额
0 3722.8732 3681.6415 635200433 759084638082
1 3901.9247 3858.6573 634706872 758690602065
2 278.8004 276.8149 474301 238605176
3 3493.6990 3452.2887 384664167 529716901409
4 3044.3966 2992.4020 37333689 39189585313
.. ... ... ... ...
581 3432.4450 3370.7080 2070244732 99377401702
582 3437.3080 3374.6570 2070244732 12779914122
583 3656.1760 3590.4160 2070244732 99377401702
584 3661.3430 3594.6080 2070244732 12779914122
585 1684.3160 1668.6140 3308668697 96750184693
[586 rows x 11 columns]
stock_zh_index_daily_df = ak.stock_zh_index_daily(symbol="sz399552")
print(stock_zh_index_daily_df)
open high low close \
date
2013-06-06 00:00:00+00:00 3353.536 3367.362 3325.742 3331.724
2013-06-07 00:00:00+00:00 3325.795 3338.029 3264.914 3276.253
2013-06-13 00:00:00+00:00 3227.157 3227.157 3138.502 3170.727
2013-06-14 00:00:00+00:00 3168.941 3190.161 3157.245 3184.553
2013-06-17 00:00:00+00:00 3189.969 3196.282 3153.118 3158.014
... ... ... ... ...
2021-09-06 00:00:00+00:00 9119.168 9289.084 9104.955 9251.786
2021-09-07 00:00:00+00:00 9258.876 9374.280 9204.488 9338.802
2021-09-08 00:00:00+00:00 9316.336 9355.946 9275.415 9304.881
2021-09-09 00:00:00+00:00 9285.144 9306.042 9233.726 9277.957
2021-09-10 00:00:00+00:00 9275.374 9417.128 9267.739 9362.351
volume
date
2013-06-06 00:00:00+00:00 6.976691e+08
2013-06-07 00:00:00+00:00 7.975941e+08
2013-06-13 00:00:00+00:00 9.214073e+08
2013-06-14 00:00:00+00:00 7.290986e+08
2013-06-17 00:00:00+00:00 7.514038e+08
... ...
2021-09-06 00:00:00+00:00 2.869844e+09
2021-09-07 00:00:00+00:00 2.553232e+09
2021-09-08 00:00:00+00:00 3.049099e+09
2021-09-09 00:00:00+00:00 2.671114e+09
2021-09-10 00:00:00+00:00 3.069509e+09
[2016 rows x 5 columns]
stock_zh_kcb_daily_df = ak.stock_zh_kcb_daily(symbol="sh688399", adjust="hfq")
#后复权因子:hfq_factor;前复权因子:qfq_factor
print(stock_zh_kcb_daily_df)
open high low close volume \
date
2019-12-05 52.330000 62.500000 50.250000 54.880000 9880338.0
2019-12-06 52.790000 55.890000 50.530000 51.000000 6317787.0
2019-12-09 51.000000 51.280000 48.000000 50.530000 4475585.0
2019-12-10 50.100000 57.510000 49.600000 53.660000 5886173.0
2019-12-11 53.010000 56.580000 52.850000 53.990000 4049939.0
... ... ... ... ... ...
2021-09-06 127.560063 131.562972 127.518257 130.664147 487160.0
2021-09-07 130.622341 132.514055 128.751529 130.622341 413376.0
2021-09-08 131.134462 131.165817 128.699272 129.389068 539479.0
2021-09-09 128.552952 129.284554 127.204713 127.852704 412494.0
2021-09-10 127.842252 127.873607 125.940087 126.441757 452204.0
after_volume after_amount outstanding_share turnover
date
2019-12-05 9264.0 508408.0 13338470.0 0.740740
2019-12-06 600.0 30600.0 13338470.0 0.473652
2019-12-09 0.0 0.0 13338470.0 0.335540
2019-12-10 1416.0 75983.0 13338470.0 0.441293
2019-12-11 1742.0 94051.0 13338470.0 0.303628
... ... ... ... ...
2021-09-06 0.0 0.0 34427400.0 0.014150
2021-09-07 0.0 0.0 34427400.0 0.012007
2021-09-08 0.0 0.0 34427400.0 0.015670
2021-09-09 300.0 36699.0 34427400.0 0.011982
2021-09-10 0.0 0.0 34427400.0 0.013135
[432 rows x 9 columns]
from pycaret.classification import *
crypto_js_spot_df = ak.crypto_js_spot()
print(crypto_js_spot_df)
bourse currency_pair price up_down \
reported_at
2021-09-12 19:02:03 Bitfinex(香港) LTCUSD 1.821400e+02 -0.46
2021-09-12 19:02:03 Bitflyer(日本) BTCJPY 5.047082e+06 25020
2021-09-12 19:02:03 Bitstamp(美国) BTCUSD 4.596137e+04 314.52
2021-09-12 19:02:03 CEX.IO(伦敦) BTCUSD 4.587830e+04 262.20
2021-09-12 19:02:03 Kraken_EUR(美国) BTCEUR 3.896840e+04 288.40
2021-09-12 19:02:03 Kraken(美国) LTCUSD 1.823000e+02 0.02
2021-09-12 19:02:03 OKCoin(中国) BTCUSD 4.588810e+04 248.34
2020-11-16 21:02:04 Bitfinex(香港) BCHUSD 0.000000e+00 0
2021-09-12 19:02:03 Bitfinex(香港) BTCUSD 4.593651e+04 287.33
2021-09-12 19:02:03 Kraken(美国) BTCUSD 4.593000e+04 290
up_down_rate hightest_price lowest_price volume
reported_at
2021-09-12 19:02:03 -0.25 186.00 1.751700e+02 39078.26
2021-09-12 19:02:03 0.50 5079523.00 4.922518e+06 1324.06
2021-09-12 19:02:03 0.69 46208.06 4.475296e+04 908.44
2021-09-12 19:02:03 0.57 46188.70 4.488780e+04 65.48
2021-09-12 19:02:03 0.75 39138.60 3.798260e+04 1086.23
2021-09-12 19:02:03 0.01 186.00 1.753700e+02 31371.66
2021-09-12 19:02:03 0.54 46213.92 4.476736e+04 114.92
2020-11-16 21:02:04 0.00 0.00 0.000000e+00 0
2021-09-12 19:02:03 0.63 46185.00 4.477418e+04 2257.75
2021-09-12 19:02:03 0.64 46173.10 4.477000e+04 918.80
stock_zh_a_spot_df = ak.stock_zh_a_spot()
print(stock_zh_a_spot_df)
Execution Error
KeyboardInterrupt:
stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20170301", end_date='20210907', adjust="qfq")
print(stock_zh_a_hist_df)
日期 开盘 收盘 最高 最低 成交量 成交额 振幅 \
0 2017-03-01 8.65 8.65 8.71 8.63 346994 3.301580e+08 0.93
1 2017-03-02 8.67 8.59 8.70 8.58 403629 3.823959e+08 1.39
2 2017-03-03 8.57 8.56 8.59 8.52 342655 3.219525e+08 0.81
3 2017-03-06 8.56 8.61 8.62 8.55 404511 3.812123e+08 0.82
4 2017-03-07 8.60 8.61 8.62 8.56 294673 2.777474e+08 0.70
... ... ... ... ... ... ... ... ...
1100 2021-09-01 17.48 17.88 17.92 17.01 2316894 4.046284e+09 5.11
1101 2021-09-02 18.00 18.40 18.78 17.80 2422604 4.454545e+09 5.48
1102 2021-09-03 18.50 18.04 18.50 17.70 1394819 2.523273e+09 4.35
1103 2021-09-06 17.93 18.45 18.60 17.78 1515226 2.780281e+09 4.55
1104 2021-09-07 18.60 19.24 19.56 18.35 1622344 3.067366e+09 6.56
涨跌幅 涨跌额 换手率
0 0.12 0.01 0.21
1 -0.69 -0.06 0.24
2 -0.35 -0.03 0.20
3 0.58 0.05 0.24
4 0.00 0.00 0.17
... ... ... ...
1100 0.45 0.08 1.19
1101 2.91 0.52 1.25
1102 -1.96 -0.36 0.72
1103 2.27 0.41 0.78
1104 4.28 0.79 0.84
[1105 rows x 11 columns]
from jinja2 import Environment, PackageLoader
env = Environment()
template = env.from_string("""
<html>
<body>
Hello! Stocks in your portfolio comparing to 200 day moving average:<br>
<ul>
{% for result in results | sort(attribute='diff_relative') %}
<li>
<b>{{ result.ticker }}</b>{{"%.2f"|format(result.diff_relative)}}%
</li>
{% endfor %}
</ul>
</body>
</html>
""")
html = template.render(results=results)
Execution Error
NameError: name 'results' is not defined
import smtplib, ssl
from email.mime.multipart import MIMEMultipart
emails = ['your.email@email.com', 'anotheremail@email.com']
smtp_server = "smtp.gmail.com"
port = 587
sender_email = "yourcreatedaccount@gmail.com"
password = "replace-with-password"
context = ssl.create_default_context()
message = MIMEMultipart("alternative")
message["Subject"] = "Stock dip detector"
message["From"] = sender_email
part = MIMEText(html, "html")
message.attach(part)
server = smtplib.SMTP(smtp_server, port)
server.starttls(context=context)
server.login(sender_email, password)
server.sendmail(sender_email, emails, message.as_string())
import smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Note: secure web apps login needs to be turned off in Google settings. For production usage, replace this with OAuth flow.
# Enable the setting here: https://myaccount.google.com/u/2/lesssecureapps
smtp_server = "smtp.gmail.com"
port = 587 # For starttls
sender_email = "your-google-email-here"
password = "password-here" # Replace this with a real value
# Create a secure SSL context
context = ssl.create_default_context()
message = MIMEMultipart("alternative")
message["Subject"] = "Stock dip detector"
message["From"] = sender_email
# Note: we should also include a text version for email. For the simplicity of this, I omit this for now.
part = MIMEText(html, "html")
message.attach(part)
try:
server = smtplib.SMTP(smtp_server, port)
server.starttls(context=context)
server.login(sender_email, password)
server.sendmail(sender_email, emails, message.as_string())
except Exception as e:
# Throw the exception, so the scheduled run is stopped and we recieve a notification in our inbox.
raise e
finally:
server.quit()