# -*- coding: utf-8 -*- import subprocess import time import pika from gryphon.lib.logger import get_logger logger = get_logger('emerald-havoc-consumer') class QueueConsumerException(Exception): pass class QueueConsumer(object): """ This is an example consumer that will handle unexpected interactions with RabbitMQ such as channel and connection closures. If RabbitMQ closes the connection, it will reopen it. You should look at the output, as there are limited reasons why the connection may be closed, which usually are tied to permission related issues or socket timeouts. If the channel is closed, it will indicate a problem with one of the commands that were issued and that should surface in the output as well. """ def __init__(self, amqp_url, consumer_func, consumer_func_args, exchange, exchange_type, binding_key, queue_name): """ Create a new instance of the consumer class, passing in the AMQP URL used to
IMPORTANT: - the 'Order' used here is gryphon.lib.exchange.exchange_order, not the database order model. """ from collections import defaultdict import itertools from cdecimal import Decimal from gryphon.lib.logger import get_logger from gryphon.lib.models.emeraldhavoc.orderbook import Orderbook from gryphon.lib.money import Money from gryphon.lib.metrics import midpoint logger = get_logger(__name__) CURRENCY_MISMATCH_ERROR_MESSAGE = """\ Orderbooks do not have the same volume currency. A: %s, B: %s\ """ class MismatchedVolumeCurrenciesError(Exception): def __init__(self, cur_a, cur_b): self.message = CURRENCY_MISMATCH_ERROR_MESSAGE % (cur_a, cur_b) class Cross(object): """ Represents a cross between the bids and asks two orderbooks, whether or not that cross is a profitable arbitrage opportunity.
def turn_on_debug(loggers): for logger_name in loggers: logger = get_logger(logger_name) logger.setLevel(logging.DEBUG)