def fetch_ledger(self, code=None, since=None, limit=None, params={}):
    self.load_markets()
    defaultType = self.safe_string_2(self.options, 'fetchLedger', 'defaultType')
    type = self.safe_string(params, 'type', defaultType)
    query = self.omit(params, 'type')
    suffix = ('' if (type == 'account') else 'Accounts')
    argument = ''
    request = {}
    if (limit is not None):
        request['limit'] = limit
    currency = None
    if ((type == 'spot') or (type == 'futures')):
        if (code is None):
            raise ArgumentsRequired((((self.id + " fetchLedger() requires a currency code argument for '") + type) + "' markets"))
        argument = 'Currency'
        currency = self.currency(code)
        request['currency'] = currency['id']
    elif ((type == 'margin') or (type == 'swap')):
        if (code is None):
            raise ArgumentsRequired((((self.id + " fetchLedger() requires a code argument(a market symbol) for '") + type) + "' markets"))
        argument = 'InstrumentId'
        market = self.market(code)
        currency = self.currency(market['base'])
        request['instrument_id'] = market['id']
    elif (type == 'account'):
        if (code is not None):
            currency = self.currency(code)
            request['currency'] = currency['id']
    else:
        raise NotSupported((((self.id + " fetchLedger does not support the '") + type) + "' type(the type must be one of 'account', 'spot', 'margin', 'futures', 'swap')"))
    method = ((((type + 'Get') + suffix) + argument) + 'Ledger')
    response = getattr(self, method)(self.extend(request, query))
    responseLength = len(response)
    if (responseLength < 1):
        return []
    isArray = isinstance(response[0], list)
    isMargin = (type == 'margin')
    entries = (response[0] if (isMargin and isArray) else response)
    if (type == 'swap'):
        ledgerEntries = self.parse_ledger(entries)
        return self.filter_by_symbol_since_limit(ledgerEntries, code, since, limit)
    return self.parse_ledger(entries, currency, since, limit)
def fetch_ledger(self, code=None, since=None, limit=None, params={}):
    self.load_markets()
    defaultType = self.safe_string_2(self.options, 'fetchLedger', 'defaultType')
    type = self.safe_string(params, 'type', defaultType)
    query = self.omit(params, 'type')
    suffix = ( if (type == 'account') else 'Accounts')
    argument = 
    request = {}
    if (limit is not None):
        request['limit'] = limit
    currency = None
    if ((type == 'spot') or (type == 'futures')):
        if (code is None):
            raise ArgumentsRequired((((self.id + " fetchLedger() requires a currency code argument for '") + type) + "' markets"))
        argument = 'Currency'
        currency = self.currency(code)
        request['currency'] = currency['id']
    elif ((type == 'margin') or (type == 'swap')):
        if (code is None):
            raise ArgumentsRequired((((self.id + " fetchLedger() requires a code argument(a market symbol) for '") + type) + "' markets"))
        argument = 'InstrumentId'
        market = self.market(code)
        currency = self.currency(market['base'])
        request['instrument_id'] = market['id']
    elif (type == 'account'):
        if (code is not None):
            currency = self.currency(code)
            request['currency'] = currency['id']
    else:
        raise NotSupported((((self.id + " fetchLedger does not support the '") + type) + "' type(the type must be one of 'account', 'spot', 'margin', 'futures', 'swap')"))
    method = ((((type + 'Get') + suffix) + argument) + 'Ledger')
    response = getattr(self, method)(self.extend(request, query))
    responseLength = len(response)
    if (responseLength < 1):
        return []
    isArray = isinstance(response[0], list)
    isMargin = (type == 'margin')
    entries = (response[0] if (isMargin and isArray) else response)
    if (type == 'swap'):
        ledgerEntries = self.parse_ledger(entries)
        return self.filter_by_symbol_since_limit(ledgerEntries, code, since, limit)
    return self.parse_ledger(entries, currency, since, limit)