Exemplo n.º 1
0
def wolfinch_main():
    """
    Main Function for Wolfinch
    """
    feed_deQ_fn = feed_deQ
    feed_Q_process_msg_fn = feed_Q_process_msg

    integrated_ui = ui.integrated_ui
    ui_conn_pipe = ui.ui_conn_pipe

    sleep_time = MAIN_TICK_DELAY
    while True:
        cur_time = time.time()
        #         log.critical("Current(%d)Sleep time left:%s"%(cur_time, str(sleep_time)))
        # check for the msg in the feed Q and process, with timeout
        msg = feed_deQ_fn(sleep_time)
        #         log.critical("Current(%d)"%(time.time()))
        while msg is not None:
            feed_Q_process_msg_fn(msg)
            msg = feed_deQ_fn(0)
        if integrated_ui == True:
            process_ui_msgs(ui_conn_pipe)
        for market in get_market_list():
            process_market(market)
        # '''Make sure each iteration take exactly LOOP_DELAY time'''
        sleep_time = (MAIN_TICK_DELAY - (time.time() - cur_time))
        #         if sleep_time < 0 :
        #             log.critical("******* TIMING SKEWED(%f)******"%(sleep_time))
        sleep_time = 0 if sleep_time < 0 else sleep_time
Exemplo n.º 2
0
def do_backtesting(simulator_on=False):
    # don't sleep for backtesting
    sleep_time = 0
    done = False
    all_done = 0

    for market in get_market_list():
        log.info("backtest setup for market: %s num_candles:%d" %
                 (market.name, market.num_candles))
        market.backtesting_idx = 0

    while (all_done < 5):
        # check for the msg in the feed Q and process, with timeout
        done = True
        msg = feed_deQ(sleep_time)
        while (msg != None):
            feed_Q_process_msg(msg)
            msg = feed_deQ(0)
        for market in get_market_list():
            market.update_market_states()
            market.cur_candle_time = market.market_indicators_data[
                market.backtesting_idx]['ohlc'].time
            # Trade only on primary markets
            if (market.primary == True
                    and (market.backtesting_idx < market.num_candles - 1)):
                #                 log.info ("BACKTEST(%d): processing on market: exchange (%s) product: %s"%(
                #                     market.backtesting_idx, market.exchange_name, market.name))
                signal = market.generate_trade_signal(market.backtesting_idx)
                market.consume_trade_signal(signal)

                if (simulator_on):
                    sim_exchange.market_simulator_run(market)
                #if atleast one market is not done, we will continue
                done = False
                market.backtesting_idx += 1
            elif done == True:
                finish_backtesting(market)
                market.backtesting_idx = market.num_candles - 1
                if (simulator_on):
                    sim_exchange.market_simulator_run(market)
                #let's do few iterations and make sure everything is really done!
                all_done += 1
Exemplo n.º 3
0
def process_ui_get_markets_rr(msg, ui_conn_pipe):
    log.debug("enter")
    m_dict = {}
    for m in get_market_list():
        p_list = m_dict.get(m.exchange_name)
        if not p_list:
            m_dict[m.exchange_name] = [{
                "product_id": m.product_id,
                "buy_paused": m.trading_paused_buy,
                "sell_paused": m.trading_paused_sell
            }]
        else:
            p_list.append({
                "product_id": m.product_id,
                "buy_paused": m.trading_paused_buy,
                "sell_paused": m.trading_paused_sell
            })

    msg["type"] = "GET_MARKETS_RESP"
    msg["data"] = m_dict
    ui_conn_pipe.send(msg)