Exemple #1
0
def GetAllStockTradingInfoFrom(YYYY, MM):
    Code = TWSENo().industry_code
    Comps= TWSENo().industry_comps
    for code in Code.keys():
        print "Industry Code: %s, %s" %(code, Code.get(code))
        try:
            if (len(Comps[str(code)]) > 0):
                for stock in Comps[str(code)]:
                    #print "Stock: " + stock
                    GetStockTradingInfoFrom(stock, YYYY, MM)
                print "Industry Code: %s is not empty" %(code)
        except:
            print "Industry Code: %s is empty" %(code)
Exemple #2
0
def printIndustryCodeAndTheirStocks():
    fo = open("IndustryCodesAndTheirStocks.txt", "wb")
    Code = TWSENo().industry_code
    Codes = Code.keys()
    Codes.sort()
    Comps= TWSENo().industry_comps
    for code in Codes:
        #print "Industry Code: %s, %s" %(code, Code.get(code))
        a="Industry Code: %s, %s\n" %(code, Code.get(code))
        #fo.write("Industry Code: " + str(code) + ": " + Code.get(code) )
        fo.write(a.encode("utf8"))
        try:
            if (len(Comps[str(code)]) > 0):
                for stock in Comps[str(code)]:
                    print stock
                    fo.write(str(stock) + " ")
                fo.write("\n\n");
                #print "Industry Code: %s is not empty" %(code)
        except:
            print "Industry Code: %s is empty" %(code)
            fo.write("Industry Code: " + str(code) + " is empty\n")
    fo.close()
Exemple #3
0
#os.sys.path.insert(0, './')
sys.path.append('/home/tim/Stock_Bot')
sys.path.append('/home/tim/Stock_Bot/')
from datetime import datetime
from grs import BestFourPoint
from grs import Stock
from grs import TWSENo
from grs import OTCNo
from csvv import yields as fields  #殖利率
from csvv import yields_otc as fields_otc  #殖利率
from csvv import vip_other
from csvv import vip_main
from rand_market_value import market_value as rank_market_value  #股本排名
from sell_buy_immediately import stock_buy_sell_oneday as oneday  #是否為現股當充

Stock_no_name = TWSENo().all_stock  # 所有上市股票名稱與代碼字典 type: dict

OTC_no_name = OTCNo().all_stock  # 所有上櫃股票名稱與代碼字典 type: dict

stock_no_list = TWSENo().all_stock_no  # 所有上市股票代碼

#stock_name_list = TWSENo().all_stock_name

OTC_no_list = OTCNo().all_stock_no  # 所有上櫃股票代碼

#OTC_name_list = OTCNo().all_stock_name

content = "贏要衝,輸要縮."  #沒有辦法換行

time_now = datetime.now().strftime("%Y%m%d_%H%M%S")  #今天的日期 ex:2015-0411
title = str(time_now + "-明天標的股")  #Email郵件的標題 ex:2015-0411-選股機器人
Exemple #4
0
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 10 00:43:39 2015

@author: tim
"""

from grs import TWSENo


twse_no = TWSENo()
twse_no.all_stock       # 所有股票名稱、代碼 type: dict
twse_no.all_stock_no    # 所有股票代碼 type: list
twse_no.all_stock_name  # 所有股票名稱 type: list
twse_no.industry_code   # 回傳類別代碼 type: dict
twse_no.industry_comps  # 回傳類別所屬股票代碼 type: dict
twse_no.search(u'中')   # 搜尋股票名稱,回傳 type: dict
twse_no.searchbyno(23)  # 搜尋股票代碼,回傳 type: dict
twse_no.last_update     # 回傳列表最後更新時間(非同步)type: str
Exemple #5
0
期交所盤後約14:30分,網站才更新今日大盤資料
故14:30前需要去抓昨天以前的資料
期交所網站http://www.taifex.com.tw/chinese/3/3_1_1.asp
假設查詢不到該日期,將會將網頁跳至今天的日期
"""
import urllib, re
import time
import os
from datetime import datetime
from time import strftime
from grs import TWSENo
from grs import OTCNo

start = time.time()  #記錄程式執行後的開始時間

stock_no_list = TWSENo().all_stock_no  # 所有上市股票代碼

OTC_no_list = OTCNo().all_stock_no  # 所有上櫃股票代碼

Stock_no_name = TWSENo().all_stock  # 所有上市股票名稱與代碼字典 type: dict

f = open(u"range.txt", 'w')  #欲儲存資料的文字檔檔名
f.write("人數	股數	佔集保庫存數比例 (%)\n")  #文字檔標頭

stock_No_total = [1101, 1102, 2330, 2412]
fetch_month = [20150828, 20150925, 20151023]

print u"正在連結期交所網站抓取資料,請稍等。抓取一個月的資料約10秒,需等待多久取決於抓取多少月份的資料"

tmp = []
owner = {}  #儲存歷史資料
Exemple #6
0
 def get_TWSE_no(self):
     return TWSENo().all_stock_no
Exemple #7
0
import sys
import csv
import time
import string
import logging
import requests
import argparse
import progressbar
from lxml import html
from datetime import datetime, timedelta

from os import mkdir
from os.path import isdir
from grs import TWSENo

stock_list = TWSENo().all_stock_no
#bar = progressbar.ProgressBar(max_value=len(stock_list))
prefix = './data'
reload(sys)
sys.setdefaultencoding('utf-8')


def check_contain_chinese(check_str):
    for ch in check_str.decode('utf-8'):
        if u'\u4e00' <= ch <= u'\u9fff':
            return True
    return False


def clean_row(row):
    ''' Clean comma and spaces'''
Exemple #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from grs import Stock
from grs import TWSENo

import sys
sys.path.append('./src')
from Rule import Rule
from Trade import Trade

# get all stock no list
stock_no_list = [i for i in sorted(TWSENo().all_stock_no)[:-2] ]
print 'Total stock: '+str(len(stock_no_list))

# parameters
contiDay_thd = 3
day = -1;

# process
for i in stock_no_list:
  try:
    stock = Stock(i)
    rule = Rule(stock)
    if rule.buyRule1(-1):
      print stock.info[0],
      print "Buy"
  
  except:
    print i
    print "[Error] "+i+" "+stock.info[0]