import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))
sys.path.append(root)

# ----------------------------------------------------------------------------

# 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

# ----------------------------------------------------------------------------
# -*- coding: utf-8 -*-

from ccxt.test.exchange.base import test_shared_methods  # noqa E402

async def test_features(exchange, skipped_properties):
    market_types = ['spot', 'swap', 'future', 'option']
    sub_types = ['linear', 'inverse']
    features = exchange.features
    keys = list(features.keys())
    for i in range(0, len(keys)):
        test_shared_methods.assert_in_array(exchange, skipped_properties, 'features', keys, i, market_types)
        market_type = keys[i]
        value = features[market_type]
        # assert (value !== undefined, 'exchange.features["' + marketType + '"] is undefined, that key should be either absent or have a value');
        if value is None:
            continue
        if market_type == 'spot':
            test_features_inner(exchange, skipped_properties, value)
        else:
            sub_keys = list(value.keys())
            for j in range(0, len(sub_keys)):
                sub_key = sub_keys[j]
                test_shared_methods.assert_in_array(exchange, skipped_properties, 'features', sub_keys, j, sub_types)
                sub_value = value[sub_key]
                # sometimes it might not be available for exchange, eg. future>inverse)
                if sub_value is not None:
                    test_features_inner(exchange, skipped_properties, sub_value)
    return True


def test_features_inner(exchange, skipped_properties, feature_obj):
    format = {
        'sandbox': False,
        'createOrder': {
            'marginMode': False,
            'triggerPrice': False,
            'triggerPriceType': {
                'mark': False,
                'last': False,
                'index': False,
            },
            'stopLossPrice': False,
            'takeProfitPrice': False,
            'attachedStopLossTakeProfit': {
                'triggerPriceType': {
                    'last': False,
                    'mark': False,
                    'index': False,
                },
                'price': False,
            },
            'timeInForce': {
                'GTC': False,
                'IOC': False,
                'FOK': False,
                'PO': False,
                'GTD': False,
            },
            'hedged': False,
            'trailing': False,
        },
        'createOrders': {
            'max': 5,
        },
        'fetchMyTrades': {
            'marginMode': False,
            'daysBack': 0,
            'limit': 0,
            'untilDays': 0,
            'symbolRequired': False,
        },
        'fetchOrder': {
            'marginMode': False,
            'trigger': False,
            'trailing': False,
            'symbolRequired': False,
        },
        'fetchOpenOrders': {
            'marginMode': False,
            'limit': 0,
            'trigger': False,
            'trailing': False,
            'symbolRequired': False,
        },
        'fetchOrders': {
            'marginMode': False,
            'limit': 0,
            'daysBack': 0,
            'untilDays': 0,
            'trigger': False,
            'trailing': False,
            'symbolRequired': False,
        },
        'fetchClosedOrders': {
            'marginMode': False,
            'limit': 0,
            'daysBack': 0,
            'daysBackCanceled': 0,
            'untilDays': 0,
            'trigger': False,
            'trailing': False,
            'symbolRequired': False,
        },
        'fetchOHLCV': {
            'limit': 0,
        },
    }
    feature_keys = list(feature_obj.keys())
    all_methods = list(exchange.has.keys())
    for i in range(0, len(feature_keys)):
        test_shared_methods.assert_in_array(exchange, skipped_properties, 'features', feature_keys, i, all_methods)
        test_shared_methods.assert_structure(exchange, skipped_properties, 'features', feature_obj, format, None, True)  # deep structure check
