Example #1
0
def stock_list():
    df = ts.get_stock_basics()
    data = df.to_dict('index')
    for code, value in sorted(data.items()):
        # print(code)
        # print(value['name'])
        Stock.objects(code=code).update_one(code=code, name=value['name'], upsert=True)
Example #2
0
def read_equity_by_portfolio(begin_date='2017-12-28', end_date=None):
    equities = read_portfolio()
    for equity in equities:
        try:
            # update to stock collection
            Stock.objects(code=equity).update_one(code=equity, focus=True, upsert=True)
            read_equity(equity, begin_date, end_date)
        except:
            print("****fail to read****"+equity)
            traceback.print_exc(file=sys.stdout)
            continue
Example #3
0
def ipo():
    ts.set_token('b4c94429dc00fee32d14c52507d9cd44c9621ca91eaa161fcec14041')
    pro = ts.pro_api()

    # 查询当前所有正常上市交易的股票列表
    df = pro.stock_basic(exchange_id='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date')
    print(df)
    data = df.to_dict('index')
    print(data.items())
    for item, value in sorted(data.items()):
        code = value['symbol']
        ipo_date = value['list_date']
        Stock.objects(code=code).update_one(code=code, ipo_date=ipo_date, upsert=True)
Example #4
0
def read_equity_by_portfolio(begin_date='2017-12-28', end_date=None):
    equities = read_portfolio()
    for equity in equities:
        try:
            # update to stock collection
            Stock.objects(code=equity).update_one(code=equity,
                                                  focus=True,
                                                  upsert=True)
            read_equity(equity, begin_date, end_date)
        except:
            print("****fail to read****" + equity)
            traceback.print_exc(file=sys.stdout)
            continue
Example #5
0
def ipo(page=1):
    # all columns
    all_columns = 'symbol,name,onl_subcode,list_date,actissqty,onl_actissqty,onl_submaxqty,onl_subbegdate,onl_unfrozendate,onl_refunddate,iss_price,onl_frozenamt,onl_lotwinrt,onl_lorwincode,onl_lotwiner_stpub_date,onl_effsubqty,onl_effsubnum,onl_onversubrt,offl_lotwinrt,offl_effsubqty,offl_planum,offl_oversubrt,napsaft,eps_dilutedaft,leaduwer,list_recomer,acttotraiseamt,onl_rdshowweb,onl_rdshowbegdate,onl_distrdate,onl_drawlotsdate,first_open_price,first_close_price,first_percent,first_turnrate,stock_income,onl_lotwin_amount,listed_percent,current,pe_ttm,pb,percent,hasexist'
    columns = 'name,onl_subcode,list_date,iss_price,current,symbol,onl_subbegdate,actissqty'
    url = 'https://xueqiu.com/proipo/query.json?page={}&size=30&order=desc&orderBy=list_date&stockType=&type=quote&_=1539863464075&column={}'.format(
        page, columns)
    payload = {'access_token': xq_a_token}
    r = requests.get(url, params=payload, headers=headers)
    data = r.json().get('data')
    date_format = 'ddd MMM DD HH:mm:ss Z YYYY'

    for stock in data:
        print(stock)
        name = stock[0]
        # code = stock[1]
        list_date = stock[2]
        # CST(China Standard Time timezone解析有问题,转化一下)
        list_date = list_date.replace('CST', '+0800')
        print(list_date)
        date = arrow.get(list_date, date_format)
        print(date.datetime)
        issue_price = stock[3]
        current = stock[4]
        symbol = stock[5]
        subscribe_date = stock[6]
        sub_date = None
        if subscribe_date and "CST" in subscribe_date:
            subscribe_date = subscribe_date.replace('CST', '+0800')
            sub_date = arrow.get(subscribe_date, date_format).datetime
            print(sub_date)
        issue_amount = stock[7]
        financing = 0
        if issue_price and issue_amount:
            financing = float(issue_price) * float(issue_amount)
        code = re.sub('[SHZ]', '', symbol)
        break_point_rate = 0
        if issue_price and float(current) < float(issue_price):
            break_point_rate = (current - issue_price) / issue_price
            print(break_point_rate)
        Stock.objects(code=code).update_one(code=code,
                                            name=name,
                                            list_date=date.datetime,
                                            sub_date=sub_date,
                                            issue_price=issue_price,
                                            current=current,
                                            break_point_rate=break_point_rate,
                                            issue_amount=issue_amount,
                                            financing=financing,
                                            upsert=True)
Example #6
0
def ipo(page=1):
    # all columns
    all_columns = 'symbol,name,onl_subcode,list_date,actissqty,onl_actissqty,onl_submaxqty,onl_subbegdate,onl_unfrozendate,onl_refunddate,iss_price,onl_frozenamt,onl_lotwinrt,onl_lorwincode,onl_lotwiner_stpub_date,onl_effsubqty,onl_effsubnum,onl_onversubrt,offl_lotwinrt,offl_effsubqty,offl_planum,offl_oversubrt,napsaft,eps_dilutedaft,leaduwer,list_recomer,acttotraiseamt,onl_rdshowweb,onl_rdshowbegdate,onl_distrdate,onl_drawlotsdate,first_open_price,first_close_price,first_percent,first_turnrate,stock_income,onl_lotwin_amount,listed_percent,current,pe_ttm,pb,percent,hasexist'
    columns = 'name,onl_subcode,list_date,iss_price,current,symbol,onl_subbegdate,actissqty'
    url = 'https://xueqiu.com/proipo/query.json?page={}&size=30&order=desc&orderBy=list_date&stockType=&type=quote&_=1539863464075&column={}'.format(page, columns)
    payload = {'access_token': xq_a_token}
    r = requests.get(url, params=payload, headers=headers)
    data = r.json().get('data')
    date_format = 'ddd MMM DD HH:mm:ss Z YYYY'

    for stock in data:
        print(stock)
        name = stock[0]
        # code = stock[1]
        list_date = stock[2]
        # CST(China Standard Time timezone解析有问题,转化一下)
        list_date = list_date.replace('CST', '+0800')
        print(list_date)
        date = arrow.get(list_date, date_format)
        print(date.datetime)
        issue_price = stock[3]
        current = stock[4]
        symbol = stock[5]
        subscribe_date = stock[6]
        sub_date = None
        if subscribe_date and "CST" in subscribe_date:
            subscribe_date = subscribe_date.replace('CST', '+0800')
            sub_date = arrow.get(subscribe_date, date_format).datetime
            print(sub_date)
        issue_amount = stock[7]
        financing = 0
        if issue_price and issue_amount:
            financing = float(issue_price)*float(issue_amount)
        code = re.sub('[SHZ]', '', symbol)
        break_point_rate = 0
        if issue_price and float(current) < float(issue_price):
            break_point_rate = (current-issue_price)/issue_price
            print(break_point_rate)
        Stock.objects(code=code).update_one(code=code, name=name, list_date=date.datetime, sub_date=sub_date, issue_price=issue_price,
                                            current=current, break_point_rate=break_point_rate,
                                            issue_amount=issue_amount, financing=financing, upsert=True)
Example #7
0
def polling():
    result = []

    # 交易时间才需要刷新
    now = arrow.now()
    today = now.date()
    weekday = now.weekday()

    trade_begin = arrow.get(str(today)+'T09:25+08:00')
    trade_end = arrow.get(str(today)+'T18:30+08:00')
    refresh = False
    if trade_begin < now < trade_end:
        refresh = True
    # ignore weekend
    if weekday == 5 or weekday == 6:
        refresh = False
    stocks = get_stocks_from_latest_portfolio()
    for item in stocks:
        code = item['code']
        amount = item['amount']
        current = item.get('current')
        if amount <= 0:
            continue
        if True:
            s = xueqiu(code)
            print('code:{} s:{}'.format(code, s))
            Stock.objects(code=code).update_one(code=code, amount=amount, current=s.current, volume=s.volume,
                                                percentage=s.percentage, change=s.change,
                                                open_price=s.open_price, high=s.high, low=s.low, close=s.close,
                                                high52week=s.high52week, low52week=s.low52week,
                                                nh=s.nh, nl=s.nl, upsert=True)
        stock = Stock.objects.get(code=code)
        stock.amount = amount
        if stock.current is None and current:
            stock.current = current
        result.append(stock)
    return result