示例#1
0
 def test_cross_all_currency(self):
     for cur0 in get_all_currency_codes():
         for cur1 in get_all_currency_codes():
             pr = RegexParser(f"{cur0}{cur1}", 1, "en", "USD",
                              False).parse()
             self.assertEqual(pr.currency, cur0, f"{cur0}{cur1}")
             self.assertEqual(pr.to_currency, cur1, f"{cur0}{cur1}")
示例#2
0
def menu_callback(
    update: Update, context: CallbackContext, chat_info: dict, _: gettext
):
    text_to = _(
        "*%(default_currency)s* is your default currency.\n"
        "You can set any currency by default, e.g. *EUR*. When you send only USD - will get *EUR USD*"
    ) % {"default_currency": chat_info["default_currency"]}

    keyboard = KeyboardSimpleClever(["↩️"] + get_all_currency_codes(), 4).show()

    update.message.reply_text(
        parse_mode=ParseMode.MARKDOWN,
        reply_markup=ReplyKeyboardMarkup(keyboard),
        text=text_to,
    )

    return SettingsSteps.default_currency
示例#3
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.all_currencies = get_all_currency_codes()
示例#4
0
    def _get_data(self) -> dict:
        try:
            response = requests.get("https://api.bitkub.com/api/market/ticker")
            response.raise_for_status()
            data = response.json()
        except (requests.exceptions.RequestException, ValueError) as e:
            raise APIErrorException(e)

        try:
            schema = {
                "type": "object",
                "patternProperties": {
                    r"^.*_.*$": {
                        "type":
                        "object",
                        "properties": {
                            "lowestAsk": {
                                "type": "number"
                            },
                            "highestBid": {
                                "type": "number"
                            },
                            "isFrozen": {
                                "type": "number"
                            },
                            "low24hr": {
                                "type": "number"
                            },
                            "high24hr": {
                                "type": "number"
                            },
                        },
                        "required": [
                            "lowestAsk",
                            "highestBid",
                            "isFrozen",
                            "low24hr",
                            "high24hr",
                        ],
                    },
                    "not": {
                        "required": ["error", ""]
                    },
                },
            }
            validate(data, schema)
        except ValidationError as e:
            raise APIErrorException(e)

        result = {}
        all_currency_codes = get_all_currency_codes()
        for currencies, info in data.items():
            if info["isFrozen"]:
                logging.info("Bitkub isFrozen: %s", currencies)
                continue

            # reverse
            to_currency, from_currency = currencies.split("_")

            if not info["lowestAsk"] or not info["highestBid"]:
                if (to_currency in all_currency_codes
                        and from_currency in all_currency_codes):
                    logging.info("Bitkub no Bid Ask: %s", info)
                continue

            result[Pair(ECurrency(from_currency),
                        ECurrency(to_currency))] = info

        return result
 def test_get_all_currencies(self):
     self.assertEqual(len(get_all_currency_codes()), 211)
    def _get_data(self) -> dict:
        try:
            response = requests.get(
                "https://api.bittrex.com/api/v1.1/public/getmarketsummaries")
            response.raise_for_status()
            data = response.json()
        except (requests.exceptions.RequestException, ValueError) as e:
            raise APIErrorException(e)

        try:
            schema = {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean"
                    },
                    "result": {
                        "type": "array",
                        "items": {
                            "type":
                            "object",
                            "properties": {
                                "MarketName": {
                                    "type": "string"
                                },
                                "High": {
                                    "type": ["number", "null"]
                                },
                                "Low": {
                                    "type": ["number", "null"]
                                },
                                "TimeStamp": {
                                    "type": "string"
                                },
                                "Bid": {
                                    "type": ["number", "null"]
                                },
                                "Ask": {
                                    "type": ["number", "null"]
                                },
                                "PrevDay": {
                                    "type": ["number", "null"]
                                },
                            },
                            "required": [
                                "MarketName",
                                "High",
                                "Low",
                                "TimeStamp",
                                "Bid",
                                "Ask",
                                "PrevDay",
                            ],
                        },
                    },
                },
                "required": ["success", "result"],
            }
            validate(data, schema)
        except ValidationError as e:
            raise APIErrorException(e)

        result = {}
        all_currency_codes = get_all_currency_codes()
        for x in data["result"]:
            # reverse
            to_currency, from_currency = x["MarketName"].upper().split("-")

            if not x["Bid"] or not x["Ask"]:
                if (to_currency in all_currency_codes
                        and from_currency in all_currency_codes):
                    logging.info("Bittrex no Bid Ask: %s", x)
                continue

            del x["MarketName"]
            result[Pair(ECurrency(from_currency), ECurrency(to_currency))] = x

        return result