# Path: async_v20/definitions/helpers.py
# def domain_check(value, example=None, possible_values=None):
#     if example:
#         if not len(str(example)) == len(str(value)):
#             msg = f'{value} does not match length of example {example}'
#             logger.error(msg)
#             raise InvalidValue(msg)
# 
#     if possible_values:
#         if not value in possible_values:
#             possible_values = ', '.join(possible_values)
#             msg = f'{value} must be in {possible_values}. Possible values are {possible_values}'
#             logger.error(msg)
#             raise InvalidValue(msg)
# 
#     return True
# 
# Path: async_v20/exceptions.py
# class InvalidValue(AsyncV20Exception):
#     """A supplied value does not meet the specification
#     of valid values"""
#     pass
# 
# class InvalidFormatArguments(AsyncV20Exception):
#     """Arguments to format a DecimalNumber or PriceValue
#     are invalid"""
#     pass


import logging
import pandas as pd
from .helpers import domain_check
from ..exceptions import InvalidValue, InvalidFormatArguments
    """

    # Correct syntax of value
    format_syntax = 'The string representation of the OANDA-assigned OrderID. ' \
                    'OANDA-assigned OrderIDs are positive integers, and are derived from the ' \
                    'TransactionID of the Transaction that created the Order.'

    # Example of correct format
    example = '1523'

    def __new__(cls, value):
        return super().__new__(cls, value)


class OrderPositionFill(str, Primitive):
    """Specification of how Positions in the Account
    are modified when the Order is filled.
    """

    # Valid values
    values = {
        'OPEN_ONLY': 'When the Order is filled, only allow Positions to be opened or extended.',
        'REDUCE_FIRST': 'When the Order is filled, always fully reduce an existing Position '
                        'before opening a new Position.',
        'REDUCE_ONLY': 'When the Order is filled, only reduce an existing Position.',
        'DEFAULT': 'When the Order is filled, use REDUCE_FIRST behaviour for non-client hedging Accounts, '
                   'and OPEN_ONLY behaviour for client hedging Accounts.'
    }

    def __new__(cls, value):

# Path: async_v20/definitions/helpers.py
# def domain_check(value, example=None, possible_values=None):
#     if example:
#         if not len(str(example)) == len(str(value)):
#             msg = f'{value} does not match length of example {example}'
#             logger.error(msg)
#             raise InvalidValue(msg)
# 
#     if possible_values:
#         if not value in possible_values:
#             possible_values = ', '.join(possible_values)
#             msg = f'{value} must be in {possible_values}. Possible values are {possible_values}'
#             logger.error(msg)
#             raise InvalidValue(msg)
# 
#     return True
# 
# Path: async_v20/exceptions.py
# class InvalidValue(AsyncV20Exception):
#     """A supplied value does not meet the specification
#     of valid values"""
#     pass
# 
# class InvalidFormatArguments(AsyncV20Exception):
#     """Arguments to format a DecimalNumber or PriceValue
#     are invalid"""
#     pass


# Path: async_v20/definitions/primitives.py
import logging
import pandas as pd
from .helpers import domain_check
from ..exceptions import InvalidValue, InvalidFormatArguments

    """

    # Correct syntax of value
    format_syntax = 'The string representation of the OANDA-assigned OrderID. ' \
                    'OANDA-assigned OrderIDs are positive integers, and are derived from the ' \
                    'TransactionID of the Transaction that created the Order.'

    # Example of correct format
    example = '1523'

    def __new__(cls, value):
        return super().__new__(cls, value)


class OrderPositionFill(str, Primitive):
    """Specification of how Positions in the Account
    are modified when the Order is filled.
    """

    # Valid values
    values = {
        'OPEN_ONLY': 'When the Order is filled, only allow Positions to be opened or extended.',
        'REDUCE_FIRST': 'When the Order is filled, always fully reduce an existing Position '
                        'before opening a new Position.',
        'REDUCE_ONLY': 'When the Order is filled, only reduce an existing Position.',
        'DEFAULT': 'When the Order is filled, use REDUCE_FIRST behaviour for non-client hedging Accounts, '
                   'and OPEN_ONLY behaviour for client hedging Accounts.'
    }

    def __new__(cls, value):

        assert domain_check(value, possible_values=cls.values)