# coding: utf-8

"""
    Powerbot Server

    No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)  # noqa: E501

    OpenAPI spec version: 1.0.5
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from powerbot.api_client import ApiClient


class TradesApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def get_trades(self, **kwargs):  # noqa: E501
        """Lists the own trades  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_trades(async=True)
        >>> result = thread.get()

        :param async bool
        :param int offset: Offset when loading a list of items
        :param int limit: Limits the number of loaded items
        :param int ord_id: Limit the trades to those which are related to a particular order
        :param bool active_only: Show only those trades which are active (i.e. active or rejected recalls/cancellations)
        :param str cl_ordr_id: Show only those trades related to orders with a specific 'client order id'
        :param str txt: Show onlmodify those trades related to orders with a specific 'custom text'
        :param int contract_id: Show only those trades related to a specific contract
        :param datetime from_api_timestamp: from timestamp is 'inclusive' (i.e. >=)
        :param datetime to_api_timestamp: to timestamp is 'exclusive' (i.e. <)
        :param datetime delivery_within_start:
        :param datetime delivery_within_end:
        :return: list[Trade]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.get_trades_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_trades_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_trades_with_http_info(self, **kwargs):  # noqa: E501
        """Lists the own trades  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.get_trades_with_http_info(async=True)
        >>> result = thread.get()

        :param async bool
        :param int offset: Offset when loading a list of items
        :param int limit: Limits the number of loaded items
        :param int ord_id: Limit the trades to those which are related to a particular order
        :param bool active_only: Show only those trades which are active (i.e. active or rejected recalls/cancellations)
        :param str cl_ordr_id: Show only those trades related to orders with a specific 'client order id'
        :param str txt: Show onlmodify those trades related to orders with a specific 'custom text'
        :param int contract_id: Show only those trades related to a specific contract
        :param datetime from_api_timestamp: from timestamp is 'inclusive' (i.e. >=)
        :param datetime to_api_timestamp: to timestamp is 'exclusive' (i.e. <)
        :param datetime delivery_within_start:
        :param datetime delivery_within_end:
        :return: list[Trade]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['offset', 'limit', 'ord_id', 'active_only', 'cl_ordr_id', 'txt', 'contract_id', 'from_api_timestamp', 'to_api_timestamp', 'delivery_within_start', 'delivery_within_end']  # noqa: E501
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_trades" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'offset' in params:
            query_params.append(('offset', params['offset']))  # noqa: E501
        if 'limit' in params:
            query_params.append(('limit', params['limit']))  # noqa: E501
        if 'ord_id' in params:
            query_params.append(('ordId', params['ord_id']))  # noqa: E501
        if 'active_only' in params:
            query_params.append(('active_only', params['active_only']))  # noqa: E501
        if 'cl_ordr_id' in params:
            query_params.append(('clOrdrId', params['cl_ordr_id']))  # noqa: E501
        if 'txt' in params:
            query_params.append(('txt', params['txt']))  # noqa: E501
        if 'contract_id' in params:
            query_params.append(('contract_id', params['contract_id']))  # noqa: E501
        if 'from_api_timestamp' in params:
            query_params.append(('from_api_timestamp', params['from_api_timestamp']))  # noqa: E501
        if 'to_api_timestamp' in params:
            query_params.append(('to_api_timestamp', params['to_api_timestamp']))  # noqa: E501
        if 'delivery_within_start' in params:
            query_params.append(('delivery_within_start', params['delivery_within_start']))  # noqa: E501
        if 'delivery_within_end' in params:
            query_params.append(('delivery_within_end', params['delivery_within_end']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['api_key_security']  # noqa: E501

        return self.api_client.call_api(
            '/trades', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Trade]',  # noqa: E501
            auth_settings=auth_settings,
            async=params.get('async'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def recall_trade(self, trade_id, **kwargs):  # noqa: E501
        """Recalls a trade  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.recall_trade(trade_id, async=True)
        >>> result = thread.get()

        :param async bool
        :param int trade_id: (required)
        :return: list[Trade]
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async'):
            return self.recall_trade_with_http_info(trade_id, **kwargs)  # noqa: E501
        else:
            (data) = self.recall_trade_with_http_info(trade_id, **kwargs)  # noqa: E501
            return data

    def recall_trade_with_http_info(self, trade_id, **kwargs):  # noqa: E501
        """Recalls a trade  # noqa: E501

        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async=True
        >>> thread = api.recall_trade_with_http_info(trade_id, async=True)
        >>> result = thread.get()

        :param async bool
        :param int trade_id: (required)
        :return: list[Trade]
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['trade_id']  # noqa: E501
        all_params.append('async')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method recall_trade" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'trade_id' is set
        if ('trade_id' not in params or
                params['trade_id'] is None):
            raise ValueError("Missing the required parameter `trade_id` when calling `recall_trade`")  # noqa: E501

        collection_formats = {}

        path_params = {}
        if 'trade_id' in params:
            path_params['trade_id'] = params['trade_id']  # noqa: E501

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # HTTP header `Content-Type`
        header_params['Content-Type'] = self.api_client.select_header_content_type(  # noqa: E501
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['api_key_security']  # noqa: E501

        return self.api_client.call_api(
            '/trade/{trade_id}', 'DELETE',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='list[Trade]',  # noqa: E501
            auth_settings=auth_settings,
            async=params.get('async'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
