Exemplo n.º 1
0
    def orders_report_by_name(self, searched_order):
        searched = Translate.order(searched_order)
        searched_price = searched['price']
        searched_volume = searched['amount']
        return_value = ''
        for order in self.user_orders:
            if order.is_equal(searched_price, searched_volume):
                return_value += order.complete_report()

        if not return_value:
            return_value = 'سفارشی یافت نشد! ❗️'

        return return_value
Exemplo n.º 2
0
    async def message_handler(self, event):
        """Callback method for received events.NewMessage

         Note that message_handler is called when a Telegram update occurs
        # and an event is created. Telegram may not always send information
        # about the ``.sender`` or the ``.chat``, so if you *really* want it
        # you should use ``get_chat()`` and ``get_sender()`` while working
        # with events. Since they are methods, you know they may make an API
        # call, which can be expensive.
        """
        print(event)

        event_sender = await (event.get_sender())
        event_sender = self.event_sender_to_string(event_sender)
        event_time = str(utc_to_local(event.message.date).time())

        if self.account.has_active_order():
            offer_dic = Translate.order(event.text)
            counter_offer_amount = Translate.order_counter_offer(event.text)

            if self.does_offer_match(offer_dic):
                check_offer_result = self.account.get_last_order().check_offer(
                    offer_dic['price'], offer_dic['amount'],
                    offer_dic['dividable'], event_sender, event_time)
                if check_offer_result is not None:  # if it is not none then we are going to buy or sell
                    if check_offer_result == -1:
                        await event.reply('ب')
                    else:
                        await event.reply(str(check_offer_result))
                    await self.fire_changes()

            elif event.reply_to_msg_id in self.account.get_last_order(
            ).last_offered_event_ids:
                if counter_offer_amount is not None:
                    self.account.get_last_order().amounted_accept(
                        counter_offer_amount, event_sender, event_time)
                    await self.fire_changes()

                elif event.text == 'ب':
                    self.account.get_last_order().complete_accept(
                        event_sender, event_time)
                    await self.fire_changes()

        elif self.account.is_transfer_active():
            if (Translate.order(event.text) is not None):
                offer = Translate.order(event.text)
                if (offer['dividable'] == True):
                    print(offer)
                    offer.update({'time': event_time, 'id': event})
                    response = self.account.transfer.new_offer(offer)
                if response is not None:
                    await event.reply(response['current_answer'])
                    await response['event'].reply(response['older_answer'])
            elif Translate.complete_accept(event.text) is not None:
                if event.is_reply:
                    replied = await event.get_reply_message()
                    self.account.transfer.delete_offer_with_id(replied.id)
            elif Translate.order_counter_offer(event.text) is not None:
                counter = Translate.order_counter_offer(event.text)
                if event.is_reply:
                    replied = await event.get_reply_message()
                    self.account.transfer.modify_offer_with_id(
                        replied.id, counter)

            elif event.text == 'ن':
                self.account.transfer.delete_offer_with_sender_id(
                    event.from_id)
            print(self.account.transfer.sell_list)
            print(self.account.transfer.buy_list)
            print(self.account.transfer.tomorrow_buy_list)
            print(self.account.transfer.tomorrow_sell_list)