|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import argparse |
| 4 | +import csv |
| 5 | +import os |
| 6 | +import pandas as pd |
| 7 | +import sys |
| 8 | + |
| 9 | + |
| 10 | +def do_analyse(stock_symbol_path, database_path, verbose): |
| 11 | + with open(stock_symbol_path, "r") as csvfile: |
| 12 | + db = DataBase(database_path) |
| 13 | + rows = csv.reader(csvfile) |
| 14 | + for row in rows: |
| 15 | + if verbose: |
| 16 | + print("%s %s" % (row[0], row[1])) |
| 17 | + data = db.get_stock_report(row[0]) |
| 18 | + df = pd.DataFrame( |
| 19 | + data, columns=["date", "open", "high", "low", "close", "volume"] |
| 20 | + ) |
| 21 | + df.set_index("date", inplace=True) |
| 22 | + df.index = pd.to_datetime(df.index) |
| 23 | + analytic = Analytics(df) |
| 24 | + if analytic.pass_63ma(): |
| 25 | + Draw.DrawCandle(row[0], df) |
| 26 | + |
| 27 | + |
| 28 | +def run(): |
| 29 | + parser = argparse.ArgumentParser() |
| 30 | + command = parser.add_mutually_exclusive_group() |
| 31 | + command.add_argument("--analyse", help="Analyse stock", action="store_true") |
| 32 | + stock_arg = parser.add_mutually_exclusive_group() |
| 33 | + stock_arg.add_argument("--stock", help="stock number to handle with", type=int) |
| 34 | + stock_arg.add_argument("--csv", help="csv file with stock number to handle with") |
| 35 | + parser.add_argument("--verbose", action="store_true") |
| 36 | + parser.add_argument("--db", help="database file with stock trading datas", type=str) |
| 37 | + |
| 38 | + args = parser.parse_args() |
| 39 | + if args.analyse: |
| 40 | + if args.csv: |
| 41 | + do_analyse(args.csv, args.db, args.verbose) |
| 42 | + elif args.stock: |
| 43 | + print(args.stock) |
| 44 | + parser.print_help() |
| 45 | + else: |
| 46 | + parser.print_help() |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + # hack environment |
| 51 | + self_path = os.path.realpath(__file__) |
| 52 | + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(self_path), ".."))) |
| 53 | + |
| 54 | + from stock.analytics import Analytics |
| 55 | + from stock.draw import Draw |
| 56 | + from stock.db import DataBase |
| 57 | + |
| 58 | + run() |
0 commit comments