示例#1
0
def echo(update, context):
    query = update.message.text
    ret = rtProvider.getStockInfo(query)
    result_str = ret['ID'] + " " + ret['Name'] + "的即時股價: " + str(
        ret['RealPrice'])
    context.bot.send_message(chat_id=update.effective_chat.id, text=result_str)
    ret['photo'].seek(0)
    context.bot.send_photo(chat_id=update.effective_chat.id,
                           photo=ret['photo'])
    stock = Stock(query)
    tendayMA_str = ("5日線:%.2f" % stock.moving_average(stock.price, 5)[-1])
    moMA_str = ("月線:%.2f" % stock.moving_average(stock.price, 20)[-1])
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text=tendayMA_str + "\n" + moMA_str)
示例#2
0
def main():
    
    stock = Stock('2330')                             # 擷取
    ma_p = stock.moving_average(stock.price, 5)       # 計算五日均價
    strma_p=str(ma_p)
    ma_c = stock.moving_average(stock.capacity, 5)    # 計算五日均量
    strma_c=str(ma_c)
    ma_p_cont = stock.continuous(ma_p)                # 計算五日均價持續天數
    strma_p_cont=str(ma_p_cont)
    ma_br = stock.ma_bias_ratio(5, 10)                # 計算五日、十日乖離值
    strma_br=str(ma_br)
    
    print ("計算五日均價", strma_p)
    print ("計算五日均量", strma_c)
    print ("計算五日均價持續天數", strma_p_cont)
    print ("計算五日、十日乖離值", strma_br)
示例#3
0
def _load_daily_stock_price(stock_id, sleep=1):  #-> Tuple
    stock = Stock(str(stock_id))
    date = stock.date[-1].strftime('%Y/%m/%d')
    low_price = stock.low[-1]
    high_price = stock.high[-1]
    price = stock.price[-1]
    latest_5_mv_avg_price = stock.moving_average(stock.price[-5:], days=5)[0]
    if sleep:
        time.sleep(sleep)
    return (date, price, low_price, high_price, latest_5_mv_avg_price)
示例#4
0
# import pandas as pd
# data = pd.read_csv("./stock_list.csv")
# stockNumberList =  data['id']
# print(stockNumberList[3])

# exit()

from StockFunction import getStockList

stockList = getStockList()

exit()

from twstock import Stock

stock = Stock('2330')  # 擷取台積電股價
ma_p = stock.moving_average(stock.price, 5)  # 計算五日均價
ma_c = stock.moving_average(stock.capacity, 1)  # 計算五日均量
ma_p_cont = stock.continuous(ma_p)  # 計算五日均價持續天數
ma_br = stock.ma_bias_ratio(5, 10)  # 計算五日、十日乖離值

# print(stock.data[-1])
print(ma_c)

exit()

from testHello import sample_func
sample_func()

exit()
                sql = "INSERT INTO news (`code`,`date`,`title`,`url`,`logTime`) VALUES (%s,%s,%s,%s,%s)"
                val = (code,date,title,url,datetime.datetime.now())
                cursor.execute(sql, val)
                conn.commit()
                if count == MAX_COUNT: 
                    break
                else:
                    count = count + 1
                print (date,title,url)
            except:
                if fail_count == MAX_FAIL_COUNT:
                    break
                else:
                    fail_count = fail_count + 1                
                    print ('insert failed')
        time.sleep(3) 
'''
if __name__ == '__main__':
    cursor = conn.cursor()
    code_list = []
    sql = "SELECT distinct(code) FROM own"
    cursor.execute(sql)
    for row in cursor:
        code = row[0]
        stock = Stock(code)
        week_ma = stock.moving_average(stock.price, 5)
        month_ma = stock.moving_average(stock.price, 20)
        season_ma = stock.moving_average(stock.price, 60)
        print(code, week_ma[-1], month_ma[-1], season_ma[-1])
        time.sleep(10)