Exemple #1
0
 def EWMA(self, stk_id):
     p = Profiler()        
     self.log.info(p.startLog("stk_id: {}", stk_id))
             
     last_quote_obj = self.gdo.Get_Last_EWMA(stk_id)        
     Ay = last_quote_obj["A"]
     lambdaa = 0.06
     ls = self.gdo.Get_Noncalcute_EWMA(stk_id)                   
     for obj in ls:
         r = obj["updown_limit"]
         Ai = round(pow(r, 2) * lambdaa + Ay * (1-lambdaa), 2)
         ewma = round(pow(Ai*250, 0.5), 2)
         self.gdo.updateEWMA(stk_id, obj["q_date"], Ai, ewma)
     
     self.log.info(p.endLog("stk_id: {}", stk_id))
Exemple #2
0
    def Get_Stock(self, stk_id=None):
        p = Profiler()
        #self.log.info("[START] {cname}.Get_Stock(), stk_id: {stk_id}".format(cname = type(self).__name__, stk_id = stk_id))
        self.log.info(p.startLog("stk_id: {}", stk_id))

        sql = "select distinct a.* from TW_STOCK_LIST a left join tw_stock_quote b on a.STOCK_ID = b.stk_id where a.DELISTING_DATE is null "
        if stk_id is not None:
            sql = sql + (" and a.STOCK_ID = " + stk_id)

        self.log.debug("exec sql statement: {sql}".format(sql=sql))
        session = self.sessionFactory.GetSession()
        stk_list = session.execute(sql)
        session.close()
        #self.log.info("[END] {cname}.Get_Stock(), exec TIME: {t} ms., stk_no: {sn}".format(cname = type(self).__name__, t = p.executeTime(), sn = stk_id))
        self.log.info(p.endLog("stk_id: {}", stk_id))
        return stk_list
Exemple #3
0
 def GetExangeDailyFromWantgoo(self, d, cb=None):
     p = Profiler()
     self.log.info(p.startLog("date: {}", d))
     if d is None:
         d = datetime.datetime.now().strftime("%Y%m%d")
     url = "https://www.wantgoo.com/stock/astock/agentstat_ajax?StockNo={id}&Types=3.5&StartDate={ds}&EndDate={de}&Rows=35"
     url = url.format(id=self.stock_no, ds=d, de=d)
     self.log.debug("get wantgoo daily exchange url: " + url)
     resp = requests.get(url)
     dailyReport = resp.json()
     code = dailyReport["code"]
     message = dailyReport["message"]
     returnValues = json.loads(dailyReport["returnValues"])
     if cb is not None:
         cb(returnValues)
     else:
         return returnValues
Exemple #4
0
 def Save_Daily_Exchange(self, a, b, c, d, e, f, g, h, i, j):
     p = Profiler()
     self.log.info(
         p.startLog(
             "商品代碼: {}, 交易日期: {}, 券商代碼: {}, 券商名稱: {}, 買量: {}, 賣量: {}, 買價: {}, 賣價: {}, 買賣超: {}, 均價: {}",
             a, b, c, d, e, f, g, h, i, j))
     sql = "insert into tw_stock_daily_exchange (stk_id, date, company_id, company_name, buy_quantity, sell_quantity, buy_price, sell_price, over_quantity, avg_price) values ('{a}', '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}')"
     sql = sql.format(a=a, b=b, c=c, d=d, e=e, f=f, g=g, h=h, i=i, j=j)
     session = self.sessionFactory.GetSession()
     session.execute(sql)
     session.commit()
     session.close()
     self.log.info(
         p.endLog(
             "商品代碼: {}, 交易日期: {}, 券商代碼: {}, 券商名稱: {}, 買量: {}, 賣量: {}, 買價: {}, 賣價: {}, 買賣超: {}, 均價: {}",
             a, b, c, d, e, f, g, h, i, j))
     pass
Exemple #5
0
 def Calcute_UpDown(self, stk_id):        
     p = Profiler()
     #self.log.info("[START] {cn}.Calcute_UpDown(), stk_id: {id}".format(cn = type(self).__name__, id = stk_id))
     self.log.info(p.startLog("stk_id: {}", stk_id))
     #取出未計算漲跌的資料
     ls = self.gdo.Get_Uncalcute_Updown(stk_id)  
     #取出最後一筆有計算漲跌的資料      
     updownObj = self.gdo.Get_Last_Updown(stk_id)        
     close = updownObj["close"]
     for obj in ls:
         distance = obj["close"] - close
         updown = distance
         updown_limit = round((distance / close) * 100, 2)
         self.log.debug("stk_id: {id}, q_date: {qd}, updown: {upd}, updown_limit: {updl}".format(id = stk_id, qd = obj["q_date"], upd = updown, updl = updown_limit))
         
         self.gdo.update_updown_value(
             stk_id = stk_id,
             q_date = obj["q_date"].strftime("%Y-%m-%d"),
             updown = updown,
             updown_limit = updown_limit
         )
         close = obj["close"]        
     self.log.info(p.endLog("stk_id: {}", stk_id))
Exemple #6
0
    def GetExchangeDailyReport(self, stk_id, d):
        p = Profiler()
        self.log.info(p.startLog("商品代碼: {}, 交易日期", stk_id, d))
        stk_spider = StockInfo(stk_id)
        rs = stk_spider.GetExangeDailyFromWantgoo(d)
        for r in rs:
            c1 = r["券商名稱"]
            bq1 = r["買量"]
            sq1 = r["賣量"]
            bp1 = r["買價"]
            sp1 = r["賣價"]            
            overbs1 = r["買賣超"]
            avg1 = r["均價"]

            c2 = r["券商名稱2"]
            bq2 = r["買量2"]
            sq2 = r["賣量2"]
            bp2 = r["買價2"]
            sp2 = r["賣價2"]
            overbs2 = r["買賣超2"]
            avg2 = r["均價2"]
            
            if c1 is not None:                
                id = c1[-5:-1]
Exemple #7
0
 def GetExangeDailySummaryFromWantgoo(self, d, cb=None):
     p = Profiler()
     url = "https://www.wantgoo.com/stock/astock/agentstat_total_ajax?StockNo={id}&StartDate={d}&EndDate={d}&Rows=35"
     self.log.info(p.startLog("date: {}", d))
     if d is None:
         d = datetime.datetime.now().strftime("%Y%m%d")