# Path: async_v20/definitions/attributes.py

# 
# Path: async_v20/definitions/helpers.py
# def check_conflicting_arguments(self, kwargs, preset_values):
#     for argument, preset_value in preset_values.items():
#         value = kwargs.pop(argument, None)
#         if value is not None and value != preset_value:
#             msg = f'CLASS {self.__class__.__name__}.{argument}' \
#                   f' MUST == {preset_value} NOT {value}'
#             logger.error(msg)
#             raise IncompatibleValue(msg)
# 
# Path: async_v20/definitions/helpers.py
# def create_doc_signature(obj, sig):
#     names = list(sig.parameters.keys())
#     annotations = list(
#         map(lambda x: '' if x.annotation == _empty else ': ' + x.annotation.__name__, sig.parameters.values()))
#     defaults = list(map(lambda x: '' if x.default == _empty else '=' + str(x.default)
#                         if not x.default is sentinel else '= sentinel ', sig.parameters.values()))
#     arguments = ', '.join(''.join(argument) for argument in zip(names, annotations, defaults))
#     return f'{obj.__name__}({arguments})\n{obj.__doc__}'
# 
# Path: async_v20/definitions/helpers.py
# def flatten_dict(dictionary, delimiter='_'):
#     """Flatten a nested dictionary structure"""
# 
#     def unpack(parent_key, parent_value):
#         """Unpack one level of nesting in a dictionary"""
#         try:
#             items = parent_value.items()
#         except AttributeError:
#             # parent_value was not a dict, no need to flatten
#             yield (parent_key, parent_value)
#         else:
#             for key, value in items:
#                 yield (parent_key + delimiter + key, value)
# 
#     while True:
#         # Keep unpacking the dictionary until all value's are not dictionary's
#         dictionary = dict(chain.from_iterable(starmap(unpack, dictionary.items())))
#         if not any(isinstance(value, dict) for value in dictionary.values()):
#             break
# 
#     return dictionary
# 
# Path: async_v20/definitions/helpers.py
# def json_to_instance_attributes(self, kwargs, template):
#     """Convert CamelCase keyword arguments to snake_case. Also
#     validate corresponding snake_case keyword argument is a valid
#     argument for the class being initialized.
#     """
# 
#     for key, value in kwargs.items():
#         try:
#             attr = instance_attributes[key]
#             assert attr in template
#             yield attr, value
#         except (KeyError, AssertionError):
#             possible_arguments = ', '.join(attr for attr in template)
#             msg = f'`{key}` with value `{value}` supplied to {self.__class__.__qualname__} \n' \
#                   f'Possible arguments include: {possible_arguments}'
#             logger.error(msg)
#             warnings.warn(msg, UnknownKeywordArgument)
# 
# Path: async_v20/definitions/helpers.py
# def check_conflicting_arguments(self, kwargs, preset_values):
# def json_to_instance_attributes(self, kwargs, template):
# def domain_check(value, example=None, possible_values=None):
# def flatten_dict(dictionary, delimiter='_'):
#     def unpack(parent_key, parent_value):
# def create_doc_signature(obj, sig):
# 
# Path: async_v20/definitions/primitives.py
# class Primitive(object):
#     """Mixin class to denote primitive type"""
#     pass
# 
# class Specifier(object):
#     """Mixin class to denote primitive type can be used for
#     specifying an Order/Trade/Position"""
#     # This is necessary due to different types using a mixture
#     # of int and str which prevents inheritance due to 'Lay-out error'
#     pass
# 
# class InstrumentName(str, Primitive):
#     """Instrument name identifier. Used by clients to refer to an Instrument.
#     """
# 
#     # Correct syntax of value
#     format_syntax = 'A string containing the base currency and quote currency delimited by a "_".'
# 
#     def __new__(cls, value):
#         return super().__new__(cls, value)
# 
# Path: async_v20/exceptions.py
# class IncompatibleValue(AsyncV20Exception):
#     """A supplied argument is different than the predefined value"""
#     pass
# 
# class UnknownKeywordArgument(AsyncV20Warning):
#     """A passed keyword argument is not in the objects __init__ signature"""
#     pass
# 
# class InstantiationFailure(AsyncV20Exception):
#     """async_v20 was unable to create an object from the passed arguments"""
#     pass


import logging
import ujson as json
import pandas as pd
from functools import wraps, partial
from inspect import signature
from .attributes import json_attributes
from .helpers import check_conflicting_arguments
from .helpers import create_doc_signature
from .helpers import flatten_dict
from .helpers import json_to_instance_attributes
from .helpers import sentinel
from .primitives import Primitive, Specifier, InstrumentName
from ..exceptions import IncompatibleValue, UnknownKeywordArgument, InstantiationFailure
            pass
        return default

    def get_instruments(self, instrument, default=None):
        """Return all the objects in the array where the
        `object.instrument` attribute matches the passed instrument
        else return the default"""
        try:
            return self.__class__(*[self[idx] for idx in self._instrument_index[instrument]])
        except KeyError:
            pass
        return default

    def dataframe(self, json=False, datetime_format=None):
        """Create a pandas.Dataframe

        Args:
            json: True, DataFrame columns will have the JSON representation,
                False, DataFrame columns will have the object attribute representation

            datetime_format: 'UNIX' or 'RFC3339'
        """
        return pd.DataFrame(obj.data(json=json, datetime_format=datetime_format) for obj in self)


def create_attribute(typ, data):
    """Correctly instantiate object based upon type of argument passed"""
    try:
        if isinstance(data, dict):
            result = typ(**data)

# Path: async_v20/definitions/attributes.py

# 
# Path: async_v20/definitions/helpers.py
# def check_conflicting_arguments(self, kwargs, preset_values):
#     for argument, preset_value in preset_values.items():
#         value = kwargs.pop(argument, None)
#         if value is not None and value != preset_value:
#             msg = f'CLASS {self.__class__.__name__}.{argument}' \
#                   f' MUST == {preset_value} NOT {value}'
#             logger.error(msg)
#             raise IncompatibleValue(msg)
# 
# Path: async_v20/definitions/helpers.py
# def create_doc_signature(obj, sig):
#     names = list(sig.parameters.keys())
#     annotations = list(
#         map(lambda x: '' if x.annotation == _empty else ': ' + x.annotation.__name__, sig.parameters.values()))
#     defaults = list(map(lambda x: '' if x.default == _empty else '=' + str(x.default)
#                         if not x.default is sentinel else '= sentinel ', sig.parameters.values()))
#     arguments = ', '.join(''.join(argument) for argument in zip(names, annotations, defaults))
#     return f'{obj.__name__}({arguments})\n{obj.__doc__}'
# 
# Path: async_v20/definitions/helpers.py
# def flatten_dict(dictionary, delimiter='_'):
#     """Flatten a nested dictionary structure"""
# 
#     def unpack(parent_key, parent_value):
#         """Unpack one level of nesting in a dictionary"""
#         try:
#             items = parent_value.items()
#         except AttributeError:
#             # parent_value was not a dict, no need to flatten
#             yield (parent_key, parent_value)
#         else:
#             for key, value in items:
#                 yield (parent_key + delimiter + key, value)
# 
#     while True:
#         # Keep unpacking the dictionary until all value's are not dictionary's
#         dictionary = dict(chain.from_iterable(starmap(unpack, dictionary.items())))
#         if not any(isinstance(value, dict) for value in dictionary.values()):
#             break
# 
#     return dictionary
# 
# Path: async_v20/definitions/helpers.py
# def json_to_instance_attributes(self, kwargs, template):
#     """Convert CamelCase keyword arguments to snake_case. Also
#     validate corresponding snake_case keyword argument is a valid
#     argument for the class being initialized.
#     """
# 
#     for key, value in kwargs.items():
#         try:
#             attr = instance_attributes[key]
#             assert attr in template
#             yield attr, value
#         except (KeyError, AssertionError):
#             possible_arguments = ', '.join(attr for attr in template)
#             msg = f'`{key}` with value `{value}` supplied to {self.__class__.__qualname__} \n' \
#                   f'Possible arguments include: {possible_arguments}'
#             logger.error(msg)
#             warnings.warn(msg, UnknownKeywordArgument)
# 
# Path: async_v20/definitions/helpers.py
# def check_conflicting_arguments(self, kwargs, preset_values):
# def json_to_instance_attributes(self, kwargs, template):
# def domain_check(value, example=None, possible_values=None):
# def flatten_dict(dictionary, delimiter='_'):
#     def unpack(parent_key, parent_value):
# def create_doc_signature(obj, sig):
# 
# Path: async_v20/definitions/primitives.py
# class Primitive(object):
#     """Mixin class to denote primitive type"""
#     pass
# 
# class Specifier(object):
#     """Mixin class to denote primitive type can be used for
#     specifying an Order/Trade/Position"""
#     # This is necessary due to different types using a mixture
#     # of int and str which prevents inheritance due to 'Lay-out error'
#     pass
# 
# class InstrumentName(str, Primitive):
#     """Instrument name identifier. Used by clients to refer to an Instrument.
#     """
# 
#     # Correct syntax of value
#     format_syntax = 'A string containing the base currency and quote currency delimited by a "_".'
# 
#     def __new__(cls, value):
#         return super().__new__(cls, value)
# 
# Path: async_v20/exceptions.py
# class IncompatibleValue(AsyncV20Exception):
#     """A supplied argument is different than the predefined value"""
#     pass
# 
# class UnknownKeywordArgument(AsyncV20Warning):
#     """A passed keyword argument is not in the objects __init__ signature"""
#     pass
# 
# class InstantiationFailure(AsyncV20Exception):
#     """async_v20 was unable to create an object from the passed arguments"""
#     pass


# Path: async_v20/definitions/base.py
import logging
import ujson as json
import pandas as pd
from functools import wraps, partial
from inspect import signature
from .attributes import json_attributes
from .helpers import check_conflicting_arguments
from .helpers import create_doc_signature
from .helpers import flatten_dict
from .helpers import json_to_instance_attributes
from .helpers import sentinel
from .primitives import Primitive, Specifier, InstrumentName
from ..exceptions import IncompatibleValue, UnknownKeywordArgument, InstantiationFailure

            pass
        return default

    def get_instruments(self, instrument, default=None):
        """Return all the objects in the array where the
        `object.instrument` attribute matches the passed instrument
        else return the default"""
        try:
            return self.__class__(*[self[idx] for idx in self._instrument_index[instrument]])
        except KeyError:
            pass
        return default

    def dataframe(self, json=False, datetime_format=None):
        """Create a pandas.Dataframe

        Args:
            json: True, DataFrame columns will have the JSON representation,
                False, DataFrame columns will have the object attribute representation

            datetime_format: 'UNIX' or 'RFC3339'
        """
        return pd.DataFrame(obj.data(json=json, datetime_format=datetime_format) for obj in self)


def create_attribute(typ, data):
    """Correctly instantiate object based upon type of argument passed"""
    try:
        if isinstance(data, dict):
            result = typ(**data)

        elif isinstance(data, Specifier):