예제 #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
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)

    klines_socket[market] = {}
    klines_socket[market][ticker] = {}
    klines_socket[market][ticker]['properties'] = [_schedule, collection_name, collection]
    klines_socket[market][ticker]['klines'] = []

    bm = BinanceSocketManager(binance_obj.client)
    bm.start_kline_socket(market, process_kline_socket_message, interval=ticker)
    bm.start()

    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

    handle_klines(klines, _schedule, collection_name, collection)
예제 #3
0
from kucoin.client import Client
from kucoin.exceptions import KucoinAPIException, KucoinRequestException, MarketOrderException, LimitOrderException


# symbol (string) – Name of symbol e.g. KCS-BTC
# kline_type (string) – type of symbol, type of candlestick patterns: 1min, 3min, 5min, 15min, 30min, 1hour, 2hour, 4hour, 6hour, 8hour, 12hour, 1day, 1week
# start (int) – Start time as unix timestamp (optional) default start of day in UTC
# end (int) – End time as unix timestamp (optional) default now in UTC
from library import get_klines, get_kucoin_klines, get_kucoin_interval_unit, get_binance_klines, SellAsset, stop_signal, \
    sat, cancel_kucoin_current_orders, setup_logger, get_or_create_kucoin_trade_account, sell_limit_stop_loss, \
    kucoin_client

klines_k = get_kucoin_klines("LTC-BTC", "1hour")
klines_b = get_binance_klines("LTCBTC", "1h", '6 hours ago')
#
# klines = get_klines("BNBBTC", '1h', '6 hours ago')


stop_price_in_satoshi = 777999

stop_price = stop_price_in_satoshi * sat


acc = get_or_create_kucoin_trade_account('KCS')

vra = kucoin_client.get_order_book('VRA-BTC')

sell_asset_binance = SellAsset("binance", "LTC", stop_price, True, '1h')
sell_asset_kucoin = SellAsset("kucoin", "VIDT", stop_price, True, '1h')