Exemple #1
0
    def exec_sell_order(self, rate: float, amount: float) -> float:
        """
        Executes a sell for the given trade and updated the entity.
        :param rate: rate to sell for
        :param amount: amount to sell
        :return: current profit as percentage
        """
        profit = 100 * ((rate - self.open_rate) / self.open_rate)

        # Execute sell and update trade record
        order_id = get_exchange_api(conf).sell(self.pair, rate, amount)
        self.close_rate = rate
        self.close_profit = profit
        self.close_date = datetime.utcnow()
        self.open_order_id = order_id
        Session.flush()
        return profit
Exemple #2
0
from telegram import ParseMode, Bot, Update
from wrapt import synchronized

from persistence import Trade, Session
from exchange import get_exchange_api
from utils import get_conf

# Remove noisy log messages
logging.getLogger('requests.packages.urllib3').setLevel(logging.INFO)
logging.getLogger('telegram').setLevel(logging.INFO)
logger = logging.getLogger(__name__)

_updater = None

conf = get_conf()
api_wrapper = get_exchange_api(conf)


def authorized_only(
        command_handler: Callable[[Bot, Update], None]) -> Callable[..., Any]:
    """
    Decorator to check if the message comes from the correct chat_id
    :param command_handler: Telegram CommandHandler
    :return: decorated function
    """
    def wrapper(*args, **kwargs):
        bot, update = args[0], args[1]
        if not isinstance(bot, Bot) or not isinstance(update, Update):
            raise ValueError('Received invalid Arguments: {}'.format(*args))

        chat_id = int(conf['telegram']['chat_id'])
Exemple #3
0
from exchange import get_exchange_api, Exchange
from rpc.telegram import TelegramHandler
from utils import get_conf

logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

__author__ = "gcarq"
__copyright__ = "gcarq 2017"
__license__ = "GPLv3"
__version__ = "0.8.0"


CONFIG = get_conf()
api_wrapper = get_exchange_api(CONFIG)


class TradeThread(threading.Thread):
    def __init__(self):
        super().__init__()
        self._should_stop = False

    def stop(self) -> None:
        """ stops the trader thread """
        self._should_stop = True

    def run(self) -> None:
        """
        Threaded main function
        :return: None