Пример #1
0
 def get_text(self, session, user=False):
     joined_self = session.query(Order).filter_by(
         order_id=self.order_id).join(Transaction).one()
     items = ""
     for item in self.items:
         items += str(item) + "\n"
     if self.delivery_date is not None:
         status_emoji = strings.emoji_completed
         status_text = strings.text_completed
     elif self.refund_date is not None:
         status_emoji = strings.emoji_refunded
         status_text = strings.text_refunded
     else:
         status_emoji = strings.emoji_not_processed
         status_text = strings.text_not_processed
     if user and configloader.config["Appearance"][
             "full_order_info"] == "no":
         return strings.user_order_format_string.format(status_emoji=status_emoji,
                                                        status_text=status_text,
                                                        items=items,
                                                        notes=self.notes,
                                                        value=str(utils.Price(-joined_self.transaction.value))) + \
                (strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "")
     else:
         return status_emoji + " " + \
                strings.order_number.format(id=self.order_id) + "\n" + \
                strings.order_format_string.format(user=self.user.mention(),
                                                   date=self.creation_date.isoformat(),
                                                   items=items,
                                                   notes=self.notes if self.notes is not None else "",
                                                   value=str(utils.Price(-joined_self.transaction.value))) + \
                (strings.refund_reason.format(reason=self.refund_reason) if self.refund_date is not None else "")
Пример #2
0
 def text(self, *, loc: localization.Localization, session, user=False):
     joined_self = session.query(Order).filter_by(order_id=self.order_id).join(Transaction).one()
     items = ""
     for item in self.items:
         items += str(item) + "\n"
     if self.delivery_date is not None:
         status_emoji = loc.get("emoji_completed")
         status_text = loc.get("text_completed")
     elif self.refund_date is not None:
         status_emoji = loc.get("emoji_refunded")
         status_text = loc.get("text_refunded")
     else:
         status_emoji = loc.get("emoji_not_processed")
         status_text = loc.get("text_not_processed")
     if user and configloader.config["Appearance"]["full_order_info"] == "no":
         return loc.get("user_order_format_string",
                        status_emoji=status_emoji,
                        status_text=status_text,
                        items=items,
                        notes=self.notes,
                        value=str(utils.Price(-joined_self.transaction.value, loc))) + \
                (loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
     else:
         return status_emoji + " " + \
                loc.get("order_number", id=self.order_id) + "\n" + \
                loc.get("order_format_string",
                        user=self.user.mention(),
                        date=self.creation_date.isoformat(),
                        items=items,
                        notes=self.notes if self.notes is not None else "",
                        value=str(utils.Price(-joined_self.transaction.value, loc))) + \
                (loc.get("refund_reason", reason=self.refund_reason) if self.refund_date is not None else "")
Пример #3
0
    def __init__(self,
                 symbol,
                 long_short=utils.LONG,
                 expiration=None,
                 call_put=None,
                 strike=None,
                 price_range=20,
                 tick_size=0.01,
                 cost_func=tradeking_cost,
                 premium_func=None,
                 **kwargs):

        if premium_func is None:
            premium_func = tradeking_premium(**kwargs)

        price_range = utils.Price(price_range)
        self._tick_size = utils.Price(tick_size)
        self._cost_func = cost_func
        self._premium_func = premium_func

        if not all((expiration, call_put, strike)):
            (symbol, expiration, call_put,
             strike) = utils.parse_option_symbol(symbol)

        self._symbol = utils.option_symbol(symbol, expiration, call_put,
                                           strike)
        self._underlying = symbol
        self._expiration = expiration
        self._call_put = call_put.upper()
        self._long_short = long_short.upper()
        self._strike = utils.Price(strike)
        self._start = self._strike - price_range
        self._stop = self._strike + price_range + 1

        if self._call_put == utils.PUT:
            self._payoff_func = lambda x: max(self._strike - x, 0)
        else:
            self._payoff_func = lambda x: max(x - self._strike, 0)
Пример #4
0
 def text(self, style: str="full", cart_qty: int=None):
     """Return the product details formatted with Telegram HTML. The image is omitted."""
     if style == "short":
         return f"{cart_qty}x {utils.telegram_html_escape(self.name)} - {str(utils.Price(self.price) * cart_qty)}"
     elif style == "full":
         if cart_qty is not None:
             cart = strings.in_cart_format_string.format(quantity=cart_qty)
         else:
             cart = ''
         return strings.product_format_string.format(name=utils.telegram_html_escape(self.name),
                                                     description=utils.telegram_html_escape(self.description),
                                                     price=str(utils.Price(self.price)),
                                                     cart=cart)
     else:
         raise ValueError("style is not an accepted value")
Пример #5
0
def tradeking_cost(num_legs, *args, **kwargs):
    base_fee = utils.Price(4.95)
    per_leg = utils.Price(0.65)
    return base_fee + per_leg * num_legs
Пример #6
0
def bid_ask_avg(symbol, quotes):
    mean = quotes[['bid', 'ask']].T.mean()
    return utils.Price(mean[symbol])