Example #1
0
def buy_signals(strategies: List[str] = typer.Argument(...), ):
    with typer.progressbar(tse.all_symbols()) as progress:
        result = tse.all_symbols()
        for symbol in progress:
            ticker = tse.Ticker(symbol)
            df = ticker.history
            for strategy in strategies:
                strategy = trade_strategies[strategy](df=df, )
                strategy.analyze()
                if not strategy.is_buy_signal() and symbol in result:
                    result.remove(symbol)
        for i, symbol in enumerate(result):
            print(i + 1)
            print(symbol)
            print(tse.Ticker(symbol).url)
            print("------------------------------------")
Example #2
0
def downloadCsvs():
    print("to download Csv ...")
    tickers = tse.download(symbols='all', write_to_csv=True, include_jdate=True)
    records_dict = download_client_types_records(symbols='all', write_to_csv=True, include_jdate=True)
    clear()
    for symbol in all_symbols():
        symbol1 = renameSymbol(symbol)
        df = pd.read_csv('client_types_data/' + symbol1 + '.csv', index_col=False, low_memory=False,
                         error_bad_lines=False)
        df = df.sort_values(by='date', ascending=True)
        symbol1 = renameSymbol(symbol)
        df.to_csv('client_types_data/' + symbol1 + '.csv', index=False)
        print(symbol)
    print("finish download csv")
    timeVolume()
Example #3
0
def possibleQueueSell():
    possibleSell = []
    for symbol in all_symbols():
        symbol1 = renameSymbol(symbol)
        fileNameTicker = 'tickers_data/' + symbol1 + '.csv'
        fileNameVolume = 'client_types_data/' + symbol1 + '.csv'
        if os.path.isfile(fileNameTicker) and os.path.isfile(fileNameVolume):
            ticker = pd.read_csv(fileNameTicker, index_col=False, low_memory=False, error_bad_lines=False)
            df = pd.read_csv(fileNameVolume, index_col=False, low_memory=False, error_bad_lines=False)
            if ticker['close'].iloc[-1] is not None and today == df['date'].iloc[-1]:
                if ticker['adjClose'].iloc[-1] > ticker['close'].iloc[-1]:
                    percent = (ticker['adjClose'].iloc[-1] - ticker['close'].iloc[-1]) * 100 / ticker['close'].iloc[-1]
                    if percent > 3:
                        cell = {"symbol": symbol,
                                "close": ticker['close'].iloc[-1],
                                "closeP": ticker['adjClose'].iloc[-1],
                                "percent": float("{:.2f}".format(round(percent, 2)))}
                        possibleSell.append(cell)

    return possibleSell
Example #4
0
"""
access properties of Ticker for all symbols
"""
import datetime
import random
from collections import defaultdict

from pytse_client import Ticker, all_symbols

if __name__ == '__main__':
    symbols_errors = defaultdict(list)
    random_symbols = random.sample(all_symbols(), 2)
    for index, symbol in enumerate(random_symbols):
        print(f"{symbol} item {index}/{len(random_symbols)}")
        try:
            ticker = Ticker(symbol)
            ticker.title
            ticker.url
            ticker.group_name
            ticker.eps
            ticker.p_e_ratio
            ticker.group_p_e_ratio
            ticker.base_volume
            ticker.last_price
            ticker.adj_close
            ticker.shareholders
            ticker.total_shares
            ticker.get_shareholders_history(from_when=datetime.timedelta(
                days=20))
            ticker.get_ticker_real_time_info_response()
        except Exception as e:
Example #5
0
"""
This is a test file to ensure all symbols in symbols_name.json file are
downloadable.
This process takes a long time so it's not part of the unit test
"""

from pytse_client import download, download_client_types_records, all_symbols

if __name__ == "__main__":
    download(all_symbols())
    download_client_types_records(all_symbols())
Example #6
0
def max_Volume_sell():
    sell10 = []
    sell20 = []
    sell30 = []
    sell45 = []
    sell60 = []
    sell10Ind = []
    sell20Ind = []
    sell30Ind = []

    for symbol in all_symbols():
        symbol1 = renameSymbol(symbol)
        fileNameTicker = 'tickers_data/' + symbol1 + '.csv'
        fileNameVolume = 'client_types_data/' + symbol1 + '.csv'
        if os.path.isfile(fileNameTicker) and os.path.isfile(fileNameVolume):
            try:

                ticker = pd.read_csv(fileNameTicker, index_col=False)
                df = pd.read_csv(fileNameVolume, index_col=False)
                df = df.fillna(0).astype({"individual_buy_vol": int})
                df = df.fillna(0).astype({"individual_buy_count": int})
                df = df.fillna(0).astype({"corporate_buy_vol": int})
                df = df.fillna(0).astype({"corporate_buy_count": int})
                df = df.fillna(0).astype({"corporate_sell_vol": int})
                df = df.fillna(0).astype({"individual_sell_vol": int})

                if not ticker.empty and ticker.size > 2:
                    if ticker.iloc[-1].close is not None and df['individual_buy_vol'].size > 1 and today == \
                            df['date'].iloc[
                                -1]:
                        maxNowSell = int(df['individual_sell_vol'].iloc[-1]) + int(df['corporate_sell_vol'].iloc[-1])
                        max10Sell = int(max(df['individual_sell_vol'][-10:-1] + df['corporate_sell_vol'][-10:-1]))
                        max20Sell = int(max(df['individual_sell_vol'][-20:-1] + df['corporate_sell_vol'][-20:-1]))
                        max30Sell = int(max(df['individual_sell_vol'][-30:-1] + df['corporate_sell_vol'][-30:-1]))
                        max45Sell = int(max(df['individual_sell_vol'][-45:-1] + df['corporate_sell_vol'][-45:-1]))
                        max60Sell = int(max(df['individual_sell_vol'][-60:-1] + df['corporate_sell_vol'][-60:-1]))

                        maxNowIndividualSell = int(df['individual_sell_vol'].iloc[-1])
                        max10IndividualSell = int(max(df['individual_sell_vol'][-10:-1]))
                        max20IndividualSell = int(max(df['individual_sell_vol'][-20:-1]))
                        max30IndividualSell = int(max(df['individual_sell_vol'][-30:-1]))

                        if maxNowSell > max10Sell:
                            percent = (maxNowSell - max10Sell) / maxNowSell
                            y10Sell = {"symbol": symbol, "vol": maxNowSell,
                                       "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell10.append(y10Sell)

                        if maxNowSell > max20Sell:
                            percent = (maxNowSell - max20Sell) / maxNowSell
                            y20Sell = {"symbol": symbol, "vol": maxNowSell,
                                       "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell20.append(y20Sell)

                        if maxNowSell > max30Sell:
                            percent = (maxNowSell - max30Sell) / maxNowSell
                            y30Sell = {"symbol": symbol, "vol": maxNowSell,
                                       "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell30.append(y30Sell)

                        if maxNowSell > max45Sell:
                            percent = (maxNowSell - max45Sell) / maxNowSell
                            y45Sell = {"symbol": symbol, "vol": maxNowSell,
                                       "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell45.append(y45Sell)

                        if maxNowSell > max60Sell:
                            percent = (maxNowSell - max60Sell) / maxNowSell
                            y60Sell = {"symbol": symbol, "vol": maxNowSell,
                                       "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell60.append(y60Sell)

                        if maxNowIndividualSell > max10IndividualSell:
                            percent = (maxNowIndividualSell - max10IndividualSell) / maxNowSell
                            y10IndividualSell = {"symbol": symbol, "vol": maxNowIndividualSell,
                                                 "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell10Ind.append(y10IndividualSell)

                        if maxNowIndividualSell > max20IndividualSell:
                            percent = (maxNowIndividualSell - max20IndividualSell) / maxNowSell
                            y20IndividualSell = {"symbol": symbol, "vol": maxNowIndividualSell,
                                                 "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell20Ind.append(y20IndividualSell)

                        if maxNowIndividualSell > max30IndividualSell:
                            percent = (maxNowIndividualSell - max30IndividualSell) / maxNowSell
                            y30IndividualSell = {"symbol": symbol, "vol": maxNowIndividualSell,
                                                 "percent": float("{:.2f}".format(round(percent, 2)))}
                            sell30Ind.append(y30IndividualSell)

            except:
                logging.exception(symbol + symbol1)

    return sell10, sell20, sell30, sell45, sell60, sell10Ind, sell20Ind, sell30Ind
Example #7
0
def max_Volume_buy():
    buy10 = []
    buy20 = []
    buy30 = []
    buy45 = []
    buy60 = []
    buy10Ind = []
    buy20Ind = []
    buy30Ind = []

    for symbol in all_symbols():
        symbol1 = renameSymbol(symbol)
        fileNameTicker = 'tickers_data/' + symbol1 + '.csv'
        fileNameVolume = 'client_types_data/' + symbol1 + '.csv'
        if os.path.isfile(fileNameVolume) and os.path.isfile(fileNameTicker):
            ticker = pd.read_csv(fileNameTicker, index_col=False, low_memory=False, error_bad_lines=False)
            df = pd.read_csv(fileNameVolume, index_col=False, low_memory=False, error_bad_lines=False)
            if symbol1 == "فولاد":
                print(symbol)
            try:
                df = df.fillna(0).astype({"individual_buy_vol": int})
            except:
                logging.exception(symbol1)
            df = df.fillna(0).astype({"individual_buy_vol": int})
            df = df.fillna(0).astype({"individual_buy_count": int})
            df = df.fillna(0).astype({"corporate_buy_vol": int})
            df = df.fillna(0).astype({"corporate_buy_count": int})
            df = df.fillna(0).astype({"corporate_sell_vol": int})
            df = df.fillna(0).astype({"individual_sell_vol": int})

            if not ticker.empty and ticker.size > 2:
                if ticker.iloc[-1].close is not None and df['individual_buy_vol'].size > 1 and today == df['date'].iloc[
                    -1]:
                    maxNow = int(df['individual_buy_vol'].iloc[-1]) + int(df['corporate_buy_vol'].iloc[-1])
                    max10 = int(max(df['individual_buy_vol'][-10:-1] + df['corporate_buy_vol'][-10:-1]))
                    max20 = int(max(df['individual_buy_vol'][-20:-1] + df['corporate_buy_vol'][-20:-1]))
                    max30 = int(max(df['individual_buy_vol'][-30:-1] + df['corporate_buy_vol'][-30:-1]))
                    max45 = int(max(df['individual_buy_vol'][-45:-1] + df['corporate_buy_vol'][-45:-1]))
                    max60 = int(max(df['individual_buy_vol'][-60:-1] + df['corporate_buy_vol'][-60:-1]))

                    maxNowIndividual = int(df['individual_buy_vol'].iloc[-1])
                    max10Individual = int(max(df['individual_buy_vol'][-10:-1]))
                    max20Individual = int(max(df['individual_buy_vol'][-20:-1]))
                    max30Individual = int(max(df['individual_buy_vol'][-30:-1]))

                    if maxNow > max10:
                        percent = (maxNow - max10) / maxNow
                        y10 = {"symbol": symbol, "vol": maxNow, "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy10.append(y10)

                    if maxNow > max20:
                        percent = (maxNow - max20) / maxNow
                        y20 = {"symbol": symbol, "vol": maxNow, "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy20.append(y20)

                    if maxNow > max30:
                        percent = (maxNow - max30) / maxNow
                        y30 = {"symbol": symbol, "vol": maxNow, "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy30.append(y30)

                    if maxNow > max45:
                        percent = (maxNow - max45) / maxNow
                        y45 = {"symbol": symbol, "vol": maxNow, "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy45.append(y45)

                    if maxNow > max60:
                        percent = (maxNow - max60) / maxNow
                        y60 = {"symbol": symbol, "vol": maxNow, "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy60.append(y60)

                    if maxNowIndividual > max10Individual:
                        percent = (maxNowIndividual - max10Individual) / maxNow
                        y10Individual = {"symbol": symbol, "vol": maxNowIndividual,
                                         "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy10Ind.append(y10Individual)

                    if maxNowIndividual > max20Individual:
                        percent = (maxNowIndividual - max20Individual) / maxNow
                        y20Individual = {"symbol": symbol, "vol": maxNowIndividual,
                                         "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy20Ind.append(y20Individual)

                    if maxNowIndividual > max30Individual:
                        percent = (maxNowIndividual - max30Individual) / maxNow
                        y30Individual = {"symbol": symbol, "vol": maxNowIndividual,
                                         "percent": float("{:.2f}".format(round(percent, 2)))}
                        buy30Ind.append(y30Individual)

    return buy10, buy20, buy30, buy45, buy60, buy10Ind, buy20Ind, buy30Ind