def get_balance(self, currency_id):
        if currency_id in self.available_balance:
            return self.available_balance.get(currency_id)

        print_to_console("get_balance: no currency {c_id} within Balance 0_o".format(
            c_id=get_currency_name_by_id(currency_id)), LOG_ALL_ERRORS)
        assert False
    def do_we_have_enough(self, currency_id, threshold):
        if currency_id in self.available_balance:
            return self.available_balance[currency_id] > threshold

        print_to_console("do_we_have_enough: no currency {c_id} within Balance 0_o".format(
            c_id=get_currency_name_by_id(currency_id)), LOG_ALL_ERRORS)
        return False
    def __str__(self):
        str_repr = "Balance at Exchange: {exch} Last updated: {dt} timest: {ts} %".format(
            exch=get_exchange_name_by_id(self.exchange_id),
            dt=ts_to_string_local(self.last_update),
            ts=self.last_update)

        str_repr += " Available balance:"
        for currency_id in self.available_balance:
            str_repr += " " + get_currency_name_by_id(currency_id) + " - " + str(self.available_balance[currency_id])

        str_repr += " Total balance:"

        for currency_id in self.total_balance:
            str_repr += " " + get_currency_name_by_id(currency_id) + " - " + str(self.total_balance[currency_id])

        return str_repr
Beispiel #4
0
def log_currency_disbalance_heart_beat(src_exchange_id, dst_exchange_id, currency_id, treshold_reverse):
    msg = "No disbalance at Exchanges {exch1} {exch2} for {pair_id} with {thrs}".format(
        exch1=get_exchange_name_by_id(src_exchange_id),
        exch2=get_exchange_name_by_id(dst_exchange_id),
        pair_id=get_currency_name_by_id(currency_id),
        thrs=treshold_reverse
    )
    print_to_console(msg, LOG_ALL_MARKET_NETWORK_RELATED_CRAP)
    log_to_file(msg, DEBUG_LOG_FILE_NAME)
Beispiel #5
0
def log_not_enough_base_currency(exchange_id, currency_id, threshold,
                                 balance_for_exchange, msg_queue):
    msg = """<b> !!! INFO !!! </b>
    {base_currency} balance on exchange {exch} BELOW threshold {thrs} - only {am} LEFT!""".format(
        base_currency=get_currency_name_by_id(currency_id),
        thrs=threshold,
        exch=get_exchange_name_by_id(exchange_id),
        am=balance_for_exchange.get_balance(currency_id))
    msg_queue.add_message(DEAL_INFO_MSG, msg)
    print_to_console(msg, LOG_ALL_ERRORS)
    print_to_console(balance_for_exchange, LOG_ALL_MARKET_RELATED_CRAP)
    log_to_file(str(balance_for_exchange), "balance.log")
Beispiel #6
0
def log_currency_disbalance_present(src_exchange_id, dst_exchange_id, pair_id, currency_id,
                                    balance_threshold, new_max_cap_volume, treshold):

    msg = """We have disbalance! Exchanges {exch1} {exch2} for {pair_id} with {balance_threshold}. 
    Set max cap for {currency} to {vol} and try to find price diff more than {thrs}""".format(
        exch1=get_exchange_name_by_id(src_exchange_id),
        exch2=get_exchange_name_by_id(dst_exchange_id),
        pair_id=get_pair_name_by_id(pair_id),
        balance_threshold=balance_threshold,
        currency=get_currency_name_by_id(currency_id),
        vol=new_max_cap_volume,
        thrs=treshold
    )

    print_to_console(msg, LOG_ALL_MARKET_NETWORK_RELATED_CRAP)
    log_to_file(msg, "history_trades.log")
    log_to_file(msg, "cap_price_adjustment.log")
Beispiel #7
0
 def __str__(self):
     return """Profit in {coin_name}: {profit_coin} Profit in {base_name}: {profit_base} """.format(
         coin_name=get_currency_name_by_id(self.dst_currency_id),
         profit_coin=float_to_str(self.profit_in_coin),
         base_name=get_currency_name_by_id(self.base_currency_id),
         profit_base=float_to_str(self.profit_in_base_currency))
Beispiel #8
0
def save_report(start_time,
                end_time,
                profit_by_base,
                profit_details,
                missing_orders,
                failed_orders,
                loss_details,
                loss_by_base,
                orders,
                history_trades,
                file_name="what_we_have_at_the_end.log"):
    msg = "Profit report for time period of {t1} - {t2}".format(
        t1=ts_to_string_local(start_time), t2=ts_to_string_local(end_time))
    log_to_file(msg, file_name)
    msg = "Epoch format: {t1} - {t2}".format(t1=start_time, t2=end_time)
    log_to_file(msg, file_name)

    orders_by_arbitrage_id = group_orders_by_arbitrage_id(orders)

    log_to_file(
        "Total number of arbitrage events - {p}".format(
            p=len(orders_by_arbitrage_id)), file_name)
    log_to_file("For them we registered - {p} orders".format(p=len(orders)),
                file_name)
    log_to_file(
        "Resulted number of trades - {p}".format(p=len(history_trades)),
        file_name)

    for base_currency_id in profit_details:

        log_to_file(
            "\t\tTotal profit by {cn} - {nn}".format(
                cn=get_currency_name_by_id(base_currency_id),
                nn=float_to_str(profit_by_base[base_currency_id])), file_name)

        for details_by_pair_id in profit_details[base_currency_id]:
            log_to_file(details_by_pair_id, file_name)

    total_number_missing = 0
    for entry in missing_orders:
        total_number_missing += len(missing_orders[entry])

    msg = "Total number of orders without trades (Expired?): {n}".format(
        n=total_number_missing)
    log_to_file(msg, file_name)
    for exchange_id in missing_orders:
        msg = "\t{exch}     Number of orders without trades: {n}".format(
            exch=get_exchange_name_by_id(exchange_id),
            n=len(missing_orders[exchange_id]))
        log_to_file(msg, file_name)

    for exchange_id in missing_orders:
        msg = "Missing orders for {exch}".format(
            exch=get_exchange_name_by_id(exchange_id))
        log_to_file(msg, "missing_orders.log")
        for x in missing_orders[exchange_id]:
            log_to_file(x, "missing_orders.log")

    total_number_failed = 0
    for exchange_id in failed_orders:
        total_number_failed += len(failed_orders[exchange_id])

    msg = "Total number of orders without order_id (Failed?): {n}".format(
        n=total_number_failed)
    log_to_file(msg, file_name)
    for exchange_id in failed_orders:
        msg = "\t{exch}     Number of orders without trades: {n}".format(
            exch=get_exchange_name_by_id(exchange_id),
            n=len(failed_orders[exchange_id]))
        log_to_file(msg, file_name)

    for exchange_id in failed_orders:
        msg = "Failed orders for {exch}".format(
            exch=get_exchange_name_by_id(exchange_id))
        log_to_file(msg, "failed_orders.log")
        for x in failed_orders[exchange_id]:
            log_to_file(x, "failed_orders.log")

    log_to_file("\t\tLOSS DETAILS", file_name)

    for base_currency_id in loss_details:
        log_to_file(
            "\t\tLoss details by {cn} - {nn}".format(
                cn=get_currency_name_by_id(base_currency_id),
                nn=float_to_str(loss_by_base[base_currency_id])), file_name)

        for details_by_pair_id in loss_details[base_currency_id]:
            log_to_file(details_by_pair_id, file_name)
Beispiel #9
0
def init_deals_with_logging_speedy(trade_pairs, difference, file_name,
                                   processor, msg_queue):

    # FIXME move after deal placement ?

    global overall_profit_so_far
    overall_profit_so_far += trade_pairs.current_profit

    base_currency_id, dst_currency_id = split_currency_pairs(
        trade_pairs.deal_1.pair_id)

    msg = """We try to send following deals to exchange.
        <b>Expected profit in {base_coin}:</b> <i>{cur}</i>.
        <b>Overall:</b> <i>{tot}</i>
        <b>Difference in percents:</b> <i>{diff}</i>

                Deal details:
        {deal}
        """.format(base_coin=get_currency_name_by_id(base_currency_id),
                   cur=float_to_str(trade_pairs.current_profit),
                   tot=float_to_str(overall_profit_so_far),
                   diff=difference,
                   deal=str(trade_pairs))

    msg_queue.add_message(DEAL_INFO_MSG, msg)
    log_to_file(msg, file_name)

    if not YES_I_KNOW_WHAT_AM_I_DOING:
        die_hard("init_deals_with_logging_speedy called for {f}".format(
            f=trade_pairs))

    parallel_deals = []

    for order in [trade_pairs.deal_1, trade_pairs.deal_2]:
        method_for_url = dao.get_method_for_create_url_trade_by_exchange_id(
            order)
        # key, pair_name, price, amount
        key = get_key_by_exchange(order.exchange_id)
        pair_name = get_currency_pair_name_by_exchange_id(
            order.pair_id, order.exchange_id)
        post_details = method_for_url(key, pair_name, order.price,
                                      order.volume)
        constructor = return_with_no_change

        wu = WorkUnit(post_details.final_url, constructor, order)
        wu.add_post_details(post_details)

        parallel_deals.append(wu)

    res = processor.process_async_post(parallel_deals, DEAL_MAX_TIMEOUT)

    if res is None:
        log_to_file(
            "For TradePair - {tp} result is {res}".format(tp=trade_pairs,
                                                          res=res), file_name)
        log_to_file(
            "For TradePair - {tp} result is {res}".format(tp=trade_pairs,
                                                          res=res),
            ERROR_LOG_FILE_NAME)
        return

    # check for errors only
    for entry in res:
        json_response, order = entry
        if "ERROR" in json_response:

            msg = """   <b>ERROR: </b>NONE
            During deal placement: {u1}
            Details: {err_msg}
            """.format(u1=order, err_msg=json_response)

            msg_queue.add_order(FAILED_ORDERS_MSG, order)

        else:
            msg = """ For trade {trade}
            Response is {resp} """.format(trade=order, resp=json_response)

        print_to_console(msg, LOG_ALL_ERRORS)
        msg_queue.add_message(DEBUG_INFO_MSG, msg)
        log_to_file(msg, file_name)

    for order in [trade_pairs.deal_1, trade_pairs.deal_2]:
        msg_queue.add_order(ORDERS_MSG, order)