fix NoneType issues

This commit is contained in:
gcarq 2017-09-08 19:25:39 +02:00
parent c737041acb
commit 9aaa169ec3

View File

@ -3,7 +3,7 @@ from datetime import timedelta
from typing import Callable, Any from typing import Callable, Any
import arrow import arrow
from sqlalchemy import and_, func from sqlalchemy import and_, func, text
from telegram.error import NetworkError from telegram.error import NetworkError
from telegram.ext import CommandHandler, Updater from telegram.ext import CommandHandler, Updater
from telegram import ParseMode, Bot, Update from telegram import ParseMode, Bot, Update
@ -60,7 +60,8 @@ def authorized_only(command_handler: Callable[[Bot, Update], None]) -> Callable[
:return: decorated function :return: decorated function
""" """
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
bot, update = args[0], args[1] bot, update = (args[0], args[1]) if args else (kwargs['bot'], kwargs['update'])
if not isinstance(bot, Bot) or not isinstance(update, Update): if not isinstance(bot, Bot) or not isinstance(update, Update):
raise ValueError('Received invalid Arguments: {}'.format(*args)) raise ValueError('Received invalid Arguments: {}'.format(*args))
@ -151,12 +152,17 @@ def _profit(bot: Bot, update: Update) -> None:
profit_amounts.append((profit / 100) * trade.btc_amount) profit_amounts.append((profit / 100) * trade.btc_amount)
profits.append(profit) profits.append(profit)
bp_pair, bp_rate = Trade.session().query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum')) \ best_pair = Trade.session.query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum')) \
.filter(Trade.is_open.is_(False)) \ .filter(Trade.is_open.is_(False)) \
.group_by(Trade.pair) \ .group_by(Trade.pair) \
.order_by('profit_sum DESC') \ .order_by(text('profit_sum DESC')) \
.first() .first()
if not best_pair:
send_msg('*Status:* `no closed trade`', bot=bot)
return
bp_pair, bp_rate = best_pair
markdown_msg = """ markdown_msg = """
*ROI:* `{profit_btc} ({profit}%)` *ROI:* `{profit_btc} ({profit}%)`
*Trade Count:* `{trade_count}` *Trade Count:* `{trade_count}`
@ -272,7 +278,7 @@ def _performance(bot: Bot, update: Update) -> None:
send_msg('`trader is not running`', bot=bot) send_msg('`trader is not running`', bot=bot)
return return
pair_rates = Trade.session().query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum')) \ pair_rates = Trade.session.query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum')) \
.filter(Trade.is_open.is_(False)) \ .filter(Trade.is_open.is_(False)) \
.group_by(Trade.pair) \ .group_by(Trade.pair) \
.order_by('profit_sum DESC') \ .order_by('profit_sum DESC') \