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 ccxt.async.base.exchange import Exchange
  from ccxt.base.errors import ExchangeError
  
  
  class btcbox (Exchange):
  
      def describe(self):
          return self.deep_extend(super(btcbox, self).describe(), {
              'id': 'btcbox',
              'name': 'BtcBox',
              'countries': 'JP',
              'rateLimit': 1000,
              'version': 'v1',
              'has': {
                  'CORS': False,
                  'fetchOHLCV': False,
              },
              'urls': {
                  'logo': 'https://user-images.githubusercontent.com/1294454/31275803-4df755a8-aaa1-11e7-9abb-11ec2fad9f2d.jpg',
                  'api': 'https://www.btcbox.co.jp/api',
                  'www': 'https://www.btcbox.co.jp/',
                  'doc': 'https://www.btcbox.co.jp/help/asm',
              },
              'api': {
                  'public': {
                      'get': [
                          'depth',
                          'orders',
                          'ticker',
                          'allticker',
                      ],
                  },
                  'private': {
                      'post': [
                          'balance',
                          'trade_add',
                          'trade_cancel',
                          'trade_list',
                          'trade_view',
                          'wallet',
                      ],
                  },
              },
              'markets': {
                  'BTC/JPY': {'id': 'BTC/JPY', 'symbol': 'BTC/JPY', 'base': 'BTC', 'quote': 'JPY'},
              },
          })
  
      async def fetch_balance(self, params={}):
          await self.load_markets()
          balances = await self.privatePostBalance()
          result = {'info': balances}
          currencies = list(self.currencies.keys())
          for i in range(0, len(currencies)):
              currency = currencies[i]
              lowercase = currency.lower()
              if lowercase == 'dash':
                  lowercase = 'drk'
              account = self.account()
              free = lowercase + '_balance'
              used = lowercase + '_lock'
              if free in balances:
                  account['free'] = float(balances[free])
              if used in balances:
                  account['used'] = float(balances[used])
              account['total'] = self.sum(account['free'], account['used'])
              result[currency] = account
          return self.parse_balance(result)
  
      async def fetch_order_book(self, symbol, limit=None, params={}):
          await self.load_markets()
          market = self.market(symbol)
          request = {}
          numSymbols = len(self.symbols)
          if numSymbols > 1:
              request['coin'] = market['id']
          orderbook = await self.publicGetDepth(self.extend(request, params))
          result = self.parse_order_book(orderbook)
          result['asks'] = self.sort_by(result['asks'], 0)
          return result
  
      def parse_ticker(self, ticker, market=None):
          timestamp = self.milliseconds()
          symbol = None
          if market:
              symbol = market['symbol']
          return {
              'symbol': symbol,
              'timestamp': timestamp,
              'datetime': self.iso8601(timestamp),
              'high': self.safe_float(ticker, 'high'),
              'low': self.safe_float(ticker, 'low'),
              'bid': self.safe_float(ticker, 'buy'),
              'ask': self.safe_float(ticker, 'sell'),
              'vwap': None,
              'open': None,
              'close': None,
              'first': None,
              'last': self.safe_float(ticker, 'last'),
              'change': None,
              'percentage': None,
              'average': None,
              'baseVolume': self.safe_float(ticker, 'vol'),
              'quoteVolume': self.safe_float(ticker, 'volume'),
              'info': ticker,
          }
  
      async def fetch_tickers(self, symbols=None, params={}):
          await self.load_markets()
          tickers = await self.publicGetAllticker(params)
          ids = list(tickers.keys())
          result = {}
          for i in range(0, len(ids)):
              id = ids[i]
              market = self.markets_by_id[id]
              symbol = market['symbol']
              ticker = tickers[id]
              result[symbol] = self.parse_ticker(ticker, market)
          return result
  
      async def fetch_ticker(self, symbol, params={}):
          await self.load_markets()
          market = self.market(symbol)
          request = {}
          numSymbols = len(self.symbols)
          if numSymbols > 1:
              request['coin'] = market['id']
          ticker = await self.publicGetTicker(self.extend(request, params))
          return self.parse_ticker(ticker, market)
  
      def parse_trade(self, trade, market):
          timestamp = int(trade['date']) * 1000
          return {
              'info': trade,
              'id': trade['tid'],
              'order': None,
              'timestamp': timestamp,
              'datetime': self.iso8601(timestamp),
              'symbol': market['symbol'],
              'type': None,
              'side': trade['type'],
              'price': trade['price'],
              'amount': trade['amount'],
          }
  
      async def fetch_trades(self, symbol, since=None, limit=None, params={}):
          await self.load_markets()
          market = self.market(symbol)
          request = {}
          numSymbols = len(self.symbols)
          if numSymbols > 1:
              request['coin'] = market['id']
          response = await self.publicGetOrders(self.extend(request, params))
          return self.parse_trades(response, market, since, limit)
  
      async def create_order(self, symbol, type, side, amount, price=None, params={}):
          await self.load_markets()
          market = self.market(symbol)
          request = {
              'amount': amount,
              'price': price,
              'type': side,
          }
          numSymbols = len(self.symbols)
          if numSymbols > 1:
              request['coin'] = market['id']
          response = await self.privatePostTradeAdd(self.extend(request, params))
          return {
              'info': response,
              'id': response['id'],
          }
  
      async def cancel_order(self, id, symbol=None, params={}):
          await self.load_markets()
          return await self.privatePostTradeCancel(self.extend({
              'id': id,
          }, params))
  
      def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
          url = self.urls['api'] + '/' + self.version + '/' + path
          if api == 'public':
              if params:
                  url += '?' + self.urlencode(params)
          else:
              self.check_required_credentials()
              nonce = str(self.nonce())
              query = self.extend({
                  'key': self.apiKey,
                  'nonce': nonce,
              }, params)
              request = self.urlencode(query)
              secret = self.hash(self.encode(self.secret))
              query['signature'] = self.hmac(self.encode(request), self.encode(secret))
              body = self.urlencode(query)
              headers = {
                  'Content-Type': 'application/x-www-form-urlencoded',
              }
          return {'url': url, 'method': method, 'body': body, 'headers': headers}
  
      async def request(self, path, api='public', method='GET', params={}, headers=None, body=None, proxy=''):
          response = await self.fetch2(path, api, method, params, headers, body, proxy)
          if 'result' in response:
              if not response['result']:
                  raise ExchangeError(self.id + ' ' + self.json(response))
          return response
  