當前位置: 首頁>>代碼示例>>Python>>正文


Python tushare.get_realtime_quotes方法代碼示例

本文整理匯總了Python中tushare.get_realtime_quotes方法的典型用法代碼示例。如果您正苦於以下問題:Python tushare.get_realtime_quotes方法的具體用法?Python tushare.get_realtime_quotes怎麽用?Python tushare.get_realtime_quotes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tushare的用法示例。


在下文中一共展示了tushare.get_realtime_quotes方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: repo

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def repo(self):
        try:
            security = '131810'
            quote_df = ts.get_realtime_quotes(security)
            order = {
                'action': 'SELL',
                'symbol': security,
                'type': 'LIMIT',
                'price': float(quote_df['bid'][0]),
                'amountProportion': 'ALL'
            }
            for trader in self._traders.values():
                try:
                    trader.execute(**order)
                except:
                    self._logger.exception('[%s] 逆回購失敗', trader.id)
        except:
            self._logger.exception('逆回購失敗') 
開發者ID:sinall,項目名稱:StrategyEase-Python-SDK,代碼行數:20,代碼來源:base_manager.py

示例2: get_order

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_order(self, strategy_id, all=True):
        """獲取訂單列表
            :param all:True返回當日所有訂單,False返回上次下單後新產生的訂單。
        """

        s = self.session
        orders = s.get(order_url%strategy_id).json()
        
        percent = self.percent

        if all:
            return orders
        else:
            tmp_orders = []
            for order in orders:
                price = float(ts.get_realtime_quotes(order['ticker']).price)
                order['price'] = round(price*(order['side']=='BUY' and 1.+percent or 1.-percent), 2)
                tmp_orders.append(order)
            return tmp_orders 
開發者ID:musequant,項目名稱:uqtrader,代碼行數:21,代碼來源:uqer.py

示例3: get_push

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_push(all_list = []):
    stock_symbol_list, price_low_list, price_high_list = handle(all_list)
    localtime = datetime.datetime.now()    # 獲取當前時間
    now = localtime.strftime('%H:%M:%S')
    data = ts.get_realtime_quotes(stock_symbol_list)    # 獲取股票信息
    price_list = data['price']
    itchat.send(now, toUserName='filehelper')
    print(now)

    for i in range(int(len(all_list) / 3)):
        content = stock_symbol_list[i] + ' 當前價格為 ' + price_list[i] + '\n'
        if float(price_list[i]) <=  float(price_low_list[i]):
            itchat.send(content + '低於最低預警價格', toUserName='filehelper')
            print(content + '低於最低預警價格')
        elif float(price_list[i]) >=  float(price_high_list[i]):
            itchat.send(content + '高於最高預警價格', toUserName='filehelper')
            print(content + '高於最高預警價格')
        else:
            itchat.send(content + '價格正常', toUserName='filehelper')
            print(content + '價格正常')
    itchat.send('***** end *****', toUserName='filehelper')
    print('***** end *****\n') 
開發者ID:onshek,項目名稱:Stock_WeChat,代碼行數:24,代碼來源:sw.py

示例4: get_remind

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_remind(all_list = []):
    stock_symbol_list, price_low_list, price_high_list = handle(all_list)
    localtime = datetime.datetime.now()    # 獲取當前時間
    now = localtime.strftime('%H:%M:%S')
    data = ts.get_realtime_quotes(stock_symbol_list)    # 獲取股票信息
    price_list = data['price']
    itchat.send(now, toUserName='filehelper')
    print(now)

    for i in range(int(len(all_list) / 3)):
        content = stock_symbol_list[i] + ' 當前價格為 ' + price_list[i] + '\n'
        if float(price_list[i]) <=  float(price_low_list[i]):
            itchat.send(content + '低於最低預警價格', toUserName='filehelper')
            print(content + '低於最低預警價格')
        elif float(price_list[i]) >=  float(price_high_list[i]):
            itchat.send(content + '高於最高預警價格', toUserName='filehelper')
            print(content + '高於最高預警價格')
        else:
            print(content + '價格正常')
    itchat.send('***** end *****', toUserName='filehelper')
    print('***** end *****\n') 
開發者ID:onshek,項目名稱:Stock_WeChat,代碼行數:23,代碼來源:sw.py

示例5: getAllChinaStock2

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def getAllChinaStock2():
    df_list = pd.read_csv(cm.DownloadDir + cm.TABLE_STOCKS_BASIC + '.csv')
    stockList = df_list['code'].values;
    stockList_group = util.group_list(stockList, 20)
    print len(stockList_group)
    print stockList_group[1]
    stockList = []
    for group in stockList_group:
        df = ts.get_realtime_quotes(group)
    
        for se in df.get_values():
            stock = st.Stock('')
            stock.code = se[0]
            stock.name = se[1]
            stock.current = se[3]
            stock.open = se[4]
            stock.high = se[5]
            stock.low = se[6]
            stock.close = se[7]
            stock.dealAmount = se[8]/100
            stock.time = time.localtime(time.time()) #時間
            #print stock
            stockList.append(stock)
    return stockList 
開發者ID:cbbing,項目名稱:stock,代碼行數:26,代碼來源:online_data.py

示例6: get_realtime_quotes

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_realtime_quotes(code_list, open_only=False):
    import tushare as ts

    max_len = 800
    loop_cnt = int(math.ceil(float(len(code_list)) / max_len))

    total_df = reduce(lambda df1, df2: df1.append(df2),
                      [ts.get_realtime_quotes([code for code in code_list[i::loop_cnt]])
                       for i in range(loop_cnt)])
    total_df["is_index"] = False

    index_symbol = ["sh", "sz", "hs300", "sz50", "zxb", "cyb"]
    index_df = ts.get_realtime_quotes(index_symbol)
    index_df["code"] = index_symbol
    index_df["is_index"] = True
    total_df = total_df.append(index_df)
    total_df = total_df.set_index("code").sort_index()

    columns = set(total_df.columns) - set(["name", "time", "date"])
    # columns = filter(lambda x: "_v" not in x, columns)
    for label in columns:
        total_df[label] = total_df[label].map(lambda x: 0 if str(x).strip() == "" else x)
        total_df[label] = total_df[label].astype(float)

    total_df["chg"] = total_df["price"] / total_df["pre_close"] - 1

    total_df["order_book_id"] = total_df.index
    total_df["order_book_id"] = total_df["order_book_id"].apply(tushare_code_2_order_book_id)

    total_df["datetime"] = total_df["date"] + " " + total_df["time"]
    total_df["datetime"] = total_df["datetime"].apply(lambda x: convert_dt_to_int(datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")))

    total_df["close"] = total_df["price"]

    if open_only:
        total_df = total_df[total_df.open > 0]

    return total_df 
開發者ID:Raytone-D,項目名稱:puppet,代碼行數:40,代碼來源:utils.py

示例7: __call__

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def __call__(self):
        df = ts.get_realtime_quotes(self._symbol)
        order = {
            'action': 'SELL',
            'symbol': self._symbol,
            'type': 'LIMIT',
            'price': float(df['bid'][0]),
            'amountProportion': 'ALL'
        }
        for client_alias in self._client_aliases:
            try:
                client = self._client_aliases[client_alias]
                self._client.execute(client, **order)
            except:
                self._logger.exception('客戶端[%s]逆回購失敗', client_alias) 
開發者ID:sinall,項目名稱:StrategyEase-Python-SDK,代碼行數:17,代碼來源:repo.py

示例8: order_place

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def order_place(self):
        table = self.tableWidget

        count = table.rowCount()
        orders = []
        for x in xrange(count):

            ticker = unicode(table.item(x, 0).text())
            side   = unicode(table.item(x, 2).text())
            
            amount = unicode(table.item(x, 3).text())

            price = float(ts.get_realtime_quotes(ticker).price)
            percent = self.percent
            price = round(price*(side==u'買' and 1.+percent or 0.99-percent), 2)
            amount = int(round((int(amount)/100)*100, -2))

            orders.append((side, ticker, str(amount), str(price)))

        message = '\r\n'.join([u'%s %s: %s@%s'%order for order in orders])

        reply = QtGui.QMessageBox.question(self, u'下單確認', 
                     message, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

        if reply != QtGui.QMessageBox.Yes:
            return

        for side, ticker, amount, price in orders:

            if side == u'買':
                self.account_instance.buy(ticker, price, amount)
            else:
                self.account_instance.sell(ticker, price, amount) 
開發者ID:musequant,項目名稱:uqtrader,代碼行數:35,代碼來源:trader.py

示例9: get_stock_name

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_stock_name(stock_code):
    real_time_data = ts.get_realtime_quotes(stock_code).to_dict('record')
    stock_name = real_time_data[0]['name']
    return stock_name 
開發者ID:LinLidi,項目名稱:StockSensation,代碼行數:6,代碼來源:views.py

示例10: get_stock_name

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_stock_name(stocknumber):
    realtimeData = ts.get_realtime_quotes(stocknumber)
    realtimeData = realtimeData.to_dict('record')
    stock_name = realtimeData[0]['name']
    return stock_name

# 獲取分詞List 
開發者ID:LinLidi,項目名稱:StockSensation,代碼行數:9,代碼來源:views.py

示例11: get_stock_name

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_stock_name(stocknumber):
    realtimeData = ts.get_realtime_quotes(stocknumber)
    realtimeData = realtimeData.to_dict('record')
    stock_name = realtimeData[0]['name']
    return stock_name


# 獲取分詞List 
開發者ID:Rockyzsu,項目名稱:StockPredict,代碼行數:10,代碼來源:views.py

示例12: getAllChinaStock

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def getAllChinaStock():

    stockList = []
    try:
        df = get_real_price_dataframe()
        for se in df.get_values():
            stock = st.Stock('')
            stock.code = se[0]
            stock.name = se[1]
            stock.current = se[3]
            stock.open = se[4]
            stock.high = se[5]
            stock.low = se[6]
            stock.close = se[7]
            stock.dealAmount = se[8]/100
            stock.time = time.localtime(time.time()) #時間
            #print stock

            stockList.append(stock)
    except:
        print 'get real price timeout'

    return stockList

# 獲取A股所有股票的實時股價
# 通過get_realtime_quotes接口獲取 
開發者ID:cbbing,項目名稱:stock,代碼行數:28,代碼來源:online_data.py

示例13: get_realtime_quotes

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_realtime_quotes(code_list, open_only=False):
    import tushare as ts

    max_len = 800
    loop_cnt = int(math.ceil(float(len(code_list)) / max_len))

    total_df = reduce(lambda df1, df2: df1.append(df2),
                      [ts.get_realtime_quotes([code for code in code_list[i::loop_cnt]])
                       for i in range(loop_cnt)])
    total_df["is_index"] = False

    index_symbol = ["sh", "sz", "hs300", "sz50", "zxb", "cyb"]
    index_df = ts.get_realtime_quotes(index_symbol)
    index_df["code"] = index_symbol
    index_df["is_index"] = True
    total_df = total_df.append(index_df)

    columns = set(total_df.columns) - set(["name", "time", "date", "code"])
    # columns = filter(lambda x: "_v" not in x, columns)
    for label in columns:
        total_df[label] = total_df[label].map(lambda x: 0 if str(x).strip() == "" else x)
        total_df[label] = total_df[label].astype(float)

    total_df["chg"] = total_df["price"] / total_df["pre_close"] - 1

    total_df["order_book_id"] = total_df["code"]
    total_df["order_book_id"] = total_df["order_book_id"].apply(tushare_code_2_order_book_id)

    total_df = total_df.set_index("order_book_id").sort_index()

    total_df["datetime"] = total_df["date"] + " " + total_df["time"]
    total_df["datetime"] = total_df["datetime"].apply(lambda x: convert_dt_to_int(datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")))

    total_df["close"] = total_df["price"]
    total_df["last"] = total_df["price"]

    total_df["limit_up"] = total_df.apply(lambda row: row.pre_close * (1.1 if "ST" not in row["name"] else 1.05), axis=1).round(2)
    total_df["limit_down"] = total_df.apply(lambda row: row.pre_close * (0.9 if "ST" not in row["name"] else 0.95), axis=1).round(2)

    if open_only:
        total_df = total_df[total_df.open > 0]

    return total_df 
開發者ID:zhengwsh,項目名稱:InplusTrader_Linux,代碼行數:45,代碼來源:utils.py

示例14: get_realtime_quotes

# 需要導入模塊: import tushare [as 別名]
# 或者: from tushare import get_realtime_quotes [as 別名]
def get_realtime_quotes(order_book_id_list, open_only=False, include_limit=False):
    import tushare as ts

    code_list = [order_book_id_2_tushare_code(code) for code in order_book_id_list]

    max_len = 800
    loop_cnt = int(math.ceil(float(len(code_list)) / max_len))

    total_df = reduce(lambda df1, df2: df1.append(df2),
                      [ts.get_realtime_quotes([code for code in code_list[i::loop_cnt]])
                       for i in range(loop_cnt)])
    total_df["is_index"] = False

    index_symbol = ["sh", "sz", "hs300", "sz50", "zxb", "cyb"]
    index_df = ts.get_realtime_quotes(index_symbol)
    index_df["code"] = index_symbol
    index_df["is_index"] = True
    total_df = total_df.append(index_df)

    columns = set(total_df.columns) - set(["name", "time", "date", "code"])
    # columns = filter(lambda x: "_v" not in x, columns)
    for label in columns:
        total_df[label] = total_df[label].map(lambda x: 0 if str(x).strip() == "" else x)
        total_df[label] = total_df[label].astype(float)

    total_df["chg"] = total_df["price"] / total_df["pre_close"] - 1

    total_df["order_book_id"] = total_df["code"]
    total_df["order_book_id"] = total_df["order_book_id"].apply(tushare_code_2_order_book_id)

    total_df = total_df.set_index("order_book_id").sort_index()
    total_df["order_book_id"] = total_df.index

    total_df["datetime"] = total_df["date"] + " " + total_df["time"]
    # total_df["datetime"] = total_df["datetime"].apply(
    #     lambda x: convert_dt_to_int(datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")))

    total_df["close"] = total_df["price"]
    total_df["last"] = total_df["price"]

    total_df = total_df.rename(columns={
        "{}{}_p".format(base_name, i): "{}{}".format(base_name, i)
        for i in range(1, 6) for base_name in ["a", "b"]
    })
    total_df = total_df.rename(columns={"pre_close": "prev_close"})

    del total_df["code"]
    del total_df["is_index"]
    del total_df["date"]
    del total_df["time"]

    if include_limit:
        total_df["limit_up"] = total_df.apply(
            lambda row: row.prev_close * (1.1 if "ST" not in row["name"] else 1.05), axis=1).round(2)
        total_df["limit_down"] = total_df.apply(
            lambda row: row.prev_close * (0.9 if "ST" not in row["name"] else 0.95), axis=1).round(2)

    if open_only:
        total_df = total_df[total_df.open > 0]

    return total_df 
開發者ID:DingTobest,項目名稱:Rqalpha-myquant-learning,代碼行數:63,代碼來源:utils.py


注:本文中的tushare.get_realtime_quotes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。