Source code for unicorn_binance_rest_api.exceptions

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# File: unicorn_binance_rest_api/exceptions.py
#
# Part of ‘UNICORN Binance REST API’
# Project website: https://www.lucit.tech/unicorn-binance-rest-api.html
# Github: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-rest-api
# Documentation: https://unicorn-binance-rest-api.docs.lucit.tech
# PyPI: https://pypi.org/project/unicorn-binance-rest-api
# LUCIT Online Shop: https://shop.lucit.services/software
#
# License: LSOSL - LUCIT Synergetic Open Source License
# https://github.com/LUCIT-Systems-and-Development/unicorn-binance-rest-api/blob/master/LICENSE
#
# Author: LUCIT Systems and Development
#
# Copyright (c) 2017-2021, MIT License, Sam McHardy (https://github.com/sammchardy)
# Copyright (c) 2021-2023, LSOSL License, LUCIT Systems and Development (https://www.lucit.tech)
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

[docs] class BinanceAPIException(Exception): def __init__(self, response): self.code = 0 try: json_res = response.json() except ValueError: self.message = 'Invalid JSON error message from Binance: {}'.format(response.text) else: self.code = json_res['code'] self.message = json_res['msg'] self.status_code = response.status_code self.response = response self.request = getattr(response, 'request', None) def __str__(self): # pragma: no cover return 'APIError(code=%s): %s' % (self.code, self.message)
[docs] class BinanceRequestException(Exception): def __init__(self, message): self.message = message def __str__(self): return 'BinanceRequestException: %s' % self.message
[docs] class BinanceOrderException(Exception): def __init__(self, code, message): self.code = code self.message = message def __str__(self): return 'BinanceOrderException(code=%s): %s' % (self.code, self.message)
[docs] class BinanceOrderMinAmountException(BinanceOrderException): def __init__(self, value): message = "Amount must be a multiple of %s" % value super(BinanceOrderMinAmountException, self).__init__(-1013, message)
[docs] class BinanceOrderMinPriceException(BinanceOrderException): def __init__(self, value): message = "Price must be at least %s" % value super(BinanceOrderMinPriceException, self).__init__(-1013, message)
[docs] class BinanceOrderMinTotalException(BinanceOrderException): def __init__(self, value): message = "Total must be at least %s" % value super(BinanceOrderMinTotalException, self).__init__(-1013, message)
[docs] class BinanceOrderUnknownSymbolException(BinanceOrderException): def __init__(self, value): message = "Unknown symbol %s" % value super(BinanceOrderUnknownSymbolException, self).__init__(-1013, message)
[docs] class BinanceOrderInactiveSymbolException(BinanceOrderException): def __init__(self, value): message = "Attempting to trade an inactive symbol %s" % value super(BinanceOrderInactiveSymbolException, self).__init__(-1013, message)
[docs] class BinanceWithdrawException(Exception): def __init__(self, message): if message == u'参数异常': message = 'Withdraw to this address through the website first' self.message = message def __str__(self): return 'BinanceWithdrawException: %s' % self.message
[docs] class UnknownExchange(Exception): """ Exception for if the manager class is started with an unkown exchange. """ pass
[docs] class AlreadyStoppedError(Exception): """Exception raised when an attempt is made to use an instance that has already been stopped.""" pass