text: # -*- coding: utf-8 -*-
  
  # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
  # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
  
  from xrpl.asyncio.clients.exceptions import XRPLRequestFailureException
  from xrpl.models.requests.account_currencies import AccountCurrencies
  from xrpl.models.response import ResponseStatus
  from ccxt.async_support.base.exchange import Exchange
  import hashlib
  from ccxt.base.errors import ExchangeError
  from ccxt.base.errors import AuthenticationError
  from ccxt.base.errors import PermissionDenied
  from ccxt.base.errors import AccountSuspended
  from ccxt.base.errors import ArgumentsRequired
  from ccxt.base.errors import BadRequest
  from ccxt.base.errors import BadSymbol
  from ccxt.base.errors import InsufficientFunds
  from ccxt.base.errors import InvalidOrder
  from ccxt.base.errors import OrderNotFound
  from ccxt.base.errors import DDoSProtection
  from ccxt.base.errors import RateLimitExceeded
  from ccxt.base.errors import ExchangeNotAvailable
  from ccxt.base.precise import Precise
  from xrpl.clients import JsonRpcClient
  from xrpl.ledger import get_fee
  from xrpl.models.requests import Ledger, Ping
  from typing import Any, Dict, cast
  
  class xrpl(Exchange):
  
      def __init__(self):
          self.client = JsonRpcClient("https://s.altnet.rippletest.net:51234/")
  
      def describe(self):
          return self.deep_extend(super(xrpl, self).describe(), {
              'id': 'xrpl',
              'name': 'XRPL',
              'countries': ['US'],
              'version': 'v1',
              'hostname': 'https://xrpl.org/',
              'has': {
                  'fetchTransactionFee': True,
              },
              'timeframes': {
                  '1m': '1min',
                  '5m': '5min',
                  '15m': '15min',
                  '30m': '30min',
                  '1h': '1hour',
                  '2h': '2hour',
                  '4h': '4hour',
                  '6h': '6hour',
                  '12h': '12hour',
                  '1d': 'day',
                  '1w': 'week',
              },
              'urls': {
                  'logo': 'https://user-images.githubusercontent.com/51840849/77257418-3262b000-6c85-11ea-8fb8-20bdf20b3592.jpg',
                  'api': 'https://api.{hostname}',
                  'www': 'https://xrpl.org/',
                  'doc': [
                      'https://xrpl-py.readthedocs.io/en/stable/index.html',
                  ],
              },
              'api': {
                  'public': {
                      'get': [
                          'markets',
                          'tickers/{pair}',
                          'tickers_multi',
                          'order_book',
                          'order_book/multi',
                          'fees/trading',
                          'trades',
                          'timestamp',
                      ],
                  },
                  'private': {
                      'get': [
                          'key',
                          'members/me',
                          'orders',
                          'orders/filter',
                      ],
                      'post': [
                          'orders',
                          'orders/multi',
                          'order/delete',
                          'order/delete/multi',
                          'orders/clear',
                      ],
                  },
              },
              'exceptions': {
                  '2011': AccountSuspended,  # Account is locked
                  '2015': AuthenticationError,  # Google authenticator is wrong
                  '2021': InsufficientFunds,  # Insufficient balance available for withdrawal
                  '2027': InsufficientFunds,  # Insufficient balance available(for trade)
                  '2033': OrderNotFound,  # operation failed! Orders have been completed or revoked
                  '2065': InvalidOrder,  # Precatory price is exorbitant, please reset
                  '2066': InvalidOrder,  # Precatory price is low, please reset
                  '2067': InvalidOrder,  # Does not support market orders
                  '2068': InvalidOrder,  # The number of orders can not be less than
                  '2078': InvalidOrder,  # unvalid order price
                  '2085': InvalidOrder,  # Order quantity is too small
                  '2091': RateLimitExceeded,  # request is too frequency, please try again later
                  '2092': InvalidOrder,  # Minimum amount not met
                  '2131': InvalidOrder,  # The order quantity cannot be greater than
                  '3000': BadRequest,  # Requested parameter incorrect
                  '3002': BadRequest,  # Parameter cannot be null
                  '3012': AuthenticationError,  # invalid apiKey
                  '3016': BadSymbol,  # Trading pair error
                  '3024': PermissionDenied,  # wrong apikey permissions
                  '3025': AuthenticationError,  # signature failed
                  '4000': ExchangeNotAvailable,  # current network is unstable
                  '4003': DDoSProtection,  # server busy please try again later
              },
              'commonCurrencies': {
                  'xrp': 'XRP',
              },
          })
  
      async def fetch_markets(self):
          client = JsonRpcClient("https://s.altnet.rippletest.net:51234/")
          return await get_fee(client)
  
      async def fetch_status(self):
          response = await self.client.request_impl(
              Ping()
          )
          if response.is_successful():
              status = response.status
              if status == ResponseStatus.SUCCESS:
                  return 'ok'
              return 'maintenance'
  
          result = cast(Dict[str, Any], response.result)
          raise XRPLRequestFailureException(result)
  
      async def fetch_ledger(self):
          response = await self.client.request_impl(Ledger())
          result = cast(Dict[str, Any], response.result)
          if response.is_successful():
              return cast(str, result["closed"]["ledger"])
  
          raise XRPLRequestFailureException(result)
  
      async def fetch_currencies(self, account):
          response = await self.client.request_impl(AccountCurrencies(account=account))
          result = cast(Dict[str, Any], response.result)
          if response.is_successful():
              return result
  
          raise XRPLRequestFailureException(result)
  
      def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
          url = self.implode_hostname(self.urls['api']) + '/' + self.version + '/' + path
          cmds = self.json([params])
          if api == 'public':
              if method != 'GET':
                  body = {'cmds': cmds}
              elif params:
                  url += '?' + self.urlencode(params)
          elif api == 'v2private':
              self.check_required_credentials()
              url = self.implode_hostname(self.urls['api']) + '/v2/' + path
              json_params = self.json(params)
              body = {
                  'body': json_params,
                  'apikey': self.apiKey,
                  'sign': self.hmac(self.encode(json_params), self.encode(self.secret), hashlib.md5),
              }
          else:
              self.check_required_credentials()
              body = {
                  'cmds': cmds,
                  'apikey': self.apiKey,
                  'sign': self.hmac(self.encode(cmds), self.encode(self.secret), hashlib.md5),
              }
          if body is not None:
              body = self.json(body, {'convertArraysToObjects': True})
          headers = {'Content-Type': 'application/json'}
          return {'url': url, 'method': method, 'body': body, 'headers': headers}
  
      def handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody):
          if response is None:
              return
          if 'error' in response:
              if 'code' in response['error']:
                  code = self.safe_string(response['error'], 'code')
                  feedback = self.id + ' ' + body
                  self.throw_exactly_matched_exception(self.exceptions, code, feedback)
                  raise ExchangeError(feedback)
              raise ExchangeError(self.id + ' ' + body)
          if not ('result' in response):
              raise ExchangeError(self.id + ' ' + body)
  