Пример #1
0
def _do_schedule(_schedule):
    market = _schedule.market
    ticker = _schedule.ticker
    collection_name = _schedule.collection_name
    collection = db.get_collection(collection_name,
                                   codec_options=codec_options)
    sleep(1)
    while True:
        if ticker == BinanceClient.KLINE_INTERVAL_1MINUTE or ticker == BinanceClient.KLINE_INTERVAL_5MINUTE:
            sleep(randrange(2))
        elif ticker == BinanceClient.KLINE_INTERVAL_15MINUTE or BinanceClient.KLINE_INTERVAL_30MINUTE:
            sleep(randrange(20))
        else:
            sleep(randrange(200))
        if _schedule.exchange == "binance":
            try:
                klines = try_get_klines(_schedule.exchange, market, ticker,
                                        get_binance_interval_unit(ticker))
                klines = klines[:
                                -1]  # we skip the last kline on purpose to have for it a crawling volume
            except Exception as err:
                traceback.print_tb(err.__traceback__)
                logger.exception("{} {} {}".format(_schedule.exchange,
                                                   collection_name,
                                                   err.__traceback__))
                sleep(randrange(30))
                klines = get_binance_klines(market, ticker,
                                            get_binance_interval_unit(ticker))
                klines = klines[:
                                -1]  # we skip the last kline on purpose to have for it a crawling volume
        elif _schedule.exchange == "kucoin":
            try:
                klines = try_get_klines(_schedule.exchange, market, ticker,
                                        get_kucoin_interval_unit(ticker))
            except Exception:
                traceback.print_tb(err.__traceback__)
                logger.exception("{} {} {}".format(_schedule.exchange,
                                                   collection_name,
                                                   err.__traceback__))
                sleep(randrange(30))
                klines = get_kucoin_klines(market, ticker,
                                           get_kucoin_interval_unit(ticker))
        current_klines = filter_current_klines(klines, collection_name,
                                               collection)
        sleep(15)
        bd, sd = get_average_depths(_schedule.depth_crawl, _schedule.no_depths)
        list(map(lambda x: x.add_buy_depth(bd), current_klines))
        list(map(lambda x: x.add_sell_depth(sd), current_klines))
        list(map(lambda x: x.add_market(market), current_klines))
        if _schedule.exchange == "binance":
            list(map(lambda x: set_trade_volume(_schedule, x), current_klines))
        list(map(lambda x: x.add_exchange(_schedule.exchange), current_klines))
        persist_klines(current_klines, collection)
        logger.info("Stored to collection : {} : {} ".format(
            _schedule.exchange, collection_name))
        _sleep_seed = 100
        if _schedule.market == "BTCUSDT" and _schedule.ticker == "15m":
            sleep(2 * 60 + randrange(10))
        else:
            sleep(_schedule.sleep + randrange(100))
Пример #2
0
                _kucoin_ticker = "15min"

            _24_hours_old = datetime.datetime.now().timestamp(
            ) - markets_obj.timestamp > 24 * 60 * 60
            if _24_hours_old:
                logger.info(
                    f"Markets older than 24 hours {datetime.datetime.now().timestamp()} <- now : {markets_obj.timestamp} <- markets"
                )
                markets_obj = Markets(binance_vol_filter, kucoin_vol_filter)
            market_setups_binance = analyze_markets("exclude-markets-binance",
                                                    _binance_ticker,
                                                    "1600 hours ago",
                                                    "binance", markets_obj)
            market_setups_kucoin = analyze_markets(
                "exclude-markets-kucoin", _kucoin_ticker,
                get_kucoin_interval_unit(_kucoin_ticker, 1600), "kucoin",
                markets_obj)
            setup_tuples = [(market_setups_binance, "binance"),
                            (market_setups_kucoin, "kucoin")]
            process_setups(setup_tuples, collection, _binance_ticker,
                           mail_content)

        if len(mail_content.content) > 0:
            send_mail(f"WWW Market Setup Found ({type_of_scan.upper()}) WWW",
                      mail_content.content)

        if type_of_scan == "long":
            time.sleep(3600 * 4 - 900)
        elif type_of_scan == "short":
            time.sleep(3600 - 900)
    except Exception as err:
binance_ticker = "1w"
kucoin_ticker = "1week"

binance_vol_filter = 50.0
kucoin_vol_filter = 20.0

mail_content = MailContent('')
markets_obj = Markets(binance_vol_filter, kucoin_vol_filter)

market_setups_binance_raw = analyze_valuable_alts("exclude-markets-binance",
                                                  "binance", binance_ticker,
                                                  "30 weeks ago", markets_obj)
market_setups_kucoin_raw = analyze_valuable_alts(
    "exclude-markets-kucoin", "kucoin", kucoin_ticker,
    get_kucoin_interval_unit(kucoin_ticker, 30), markets_obj)

market_setups_binance = sorted(market_setups_binance_raw,
                               key=lambda x: x[1],
                               reverse=True)
market_setups_kucoin = sorted(market_setups_kucoin_raw,
                              key=lambda x: x[1],
                              reverse=True)

process_valuable_alts(market_setups_binance, "binance", binance_ticker,
                      mail_content)
process_valuable_alts(market_setups_kucoin, "kucoin", binance_ticker,
                      mail_content)

send_mail("QQQ Valuable Alts Found QQQ", mail_content.content)
            elif _t == 24:
                _binance_ticker = "1d"
                _kucoin_ticker = "1day"
            elif _t == 30:
                _binance_ticker = "30m"
                _kucoin_ticker = "30min"
            elif _t == 0.5:
                _binance_ticker = "5m"
                _kucoin_ticker = "5min"
            _24_hours_old = datetime.datetime.now().timestamp() - markets_obj.timestamp > 24*60*60
            if _24_hours_old:
                logger.info(f"Markets older than 24 hours {datetime.datetime.now().timestamp()} <- now : {markets_obj.timestamp} <- markets")
                markets_obj = Markets(binance_vol_filter, kucoin_vol_filter)
            market_setups_binance = analyze_micro_markets("exclude-micro-markets-binance", _binance_ticker, "200 hours ago", "binance", markets_obj)
            market_setups_kucoin = analyze_micro_markets("exclude-micro-markets-kucoin", _kucoin_ticker,
                                                        get_kucoin_interval_unit(_kucoin_ticker, 200), "kucoin", markets_obj)
            setup_tuples = [(market_setups_binance, "binance"), (market_setups_kucoin, "kucoin")]
            process_setups(setup_tuples, collection, _binance_ticker, mail_content)

        # if len(mail_content.content) > 0:
        #     send_mail("WWW Market Micro Setup Found WWW", mail_content.content)

        time.sleep(60)
    except Exception as err:
        if isinstance(err, requests.exceptions.ConnectionError) or isinstance(err, requests.exceptions.ReadTimeout):
            logger.error("Connection problem...")
        else:
            traceback.print_tb(err.__traceback__)
            logger.exception(err.__traceback__)