Skip to content

Api quotes

A class for interacting with OneQuant quotedatas.

Source code in onequant/api/quotes.py
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class OqQuotes:
    """A class for interacting with OneQuant quotedatas."""

    def __init__(self, wrapper=None):
        """Initializes an OqQuotes object.

        Args:
            wrapper (object, optional): An object containing the API and username. Defaults to None.
        """
        self.api = wrapper.api
        self.username = wrapper.username

    def _query(self, router, params=None):
        """Sends a GET request to the specified router with the given parameters.

        Args:
            router (str): The router to send the request to.
            params (dict, optional): The parameters to include in the request. Defaults to None.

        Returns:
            tuple: A tuple containing the data and code from the response.
        """
        result = self.api.request(method='get', router=router, params=params)
        if result['code'] != 200:
            raise Exception(f'An error occurred while retrieving tdegine data! code is {result["code"]}')
        return result['data']

    @_pd
    def _query_pd(self, params=None, router=None):
        """Sends a GET request and returns the data as a pandas DataFrame.

        Args:
            params (dict, optional): The parameters to include in the request. Defaults to None.
            router (str, optional): The router to send the request to. Defaults to None.

        Returns:
            pandas.DataFrame: The data from the response as a pandas DataFrame.
        """
        result = self.api.request(method='get', router=router, params=params)
        return result['data'], result['code']

    @_pd
    @_pagination
    def _query_pd_pg(self, params=None, router=None):
        """Sends a GET request and returns the data as a paginated pandas DataFrame.

        Args:
            params (dict, optional): The parameters to include in the request. Defaults to None.
            router (str, optional): The router to send the request to. Defaults to None.

        Returns:
            dict: A dictionary containing the paginated data and metadata from the response.
        """
        result = self.api.request(method='get', router=router, params=params)
        return result

    @_pd
    @tddata_2_list
    def _querytd_pd(self, router, params=None):
        """Sends a GET request and returns the data as a pandas DataFrame.

        Args:
            router (str): The router to send the request to.
            params (dict, optional): The parameters to include in the request. Defaults to None.

        Returns:
            pandas.DataFrame: The data from the response as a pandas DataFrame.
        """
        result = self.api.request(method='get', router=router, params=params)
        return result

    def realtime_quote(self):
        """Returns realtime quote data.

        Returns:
            pandas.DataFrame: The realtime quote data.
        """
        return self._query_pd(router='/quote/future/realTime/quote')

    def realtime_quotes(self):
        """Returns multiple realtime quote data.

        Returns:
            pandas.DataFrame: The multiple realtime quote data.
        """
        return self._query_pd(router='/quote/future/realTime/quotes')

    def future_bars(self, code=None, interval=None, start_time=None, end_time=None, limit=None):
        """Fetches K-line (candlestick) data for futures.

        Args:
            code (str, optional): The code of the future to fetch data for. Defaults to None.
            interval (str, optional): The time interval for each K-line data point. Defaults to None.
            start (uint or str, optional): The start time for the data fetch. Can be a timestamp or a date string.
            end (uint or str, optional): The end time for the data fetch. Can be a timestamp or a date string.
            limit (int, optional): The maximum number of data points to fetch. Defaults to None.If set limit value,then
            start will discarded.

        Returns:
            pandas.DataFrame: The K-line data as a pandas DataFrame.
        """
        if isinstance(start_time, int) and isinstance(end_time, int):
            params = {
                'symbol': code,
                'interval': interval,
                'start': start_time,
                'end': end_time,
                'limit': limit,
            }
            return self._querytd_pd(router='/tvquote/kline_ascend', params=params)
        else:
            params = {
                'symbol': code,
                'interval': interval,
                'start': OqDateTime.string_to_ms_timestamp(start_time),
                'end': OqDateTime.string_to_ms_timestamp(end_time),
                'limit': limit,
            }
            return self._querytd_pd(router='/tvquote/kline_ascend', params=params)

    def symbols(self):
        """Returns symbols data."""
        return self._query_pd_pg(router='/quote/futureBase/symbol', params={})

    def codeinfos(self):
        """Returns code information data."""
        return self._query_pd_pg(router='/quote/futureBase/allCode', params={})

    def indexes(self):
        """Returns indexes data."""
        return self._query_pd_pg(router='/quote/futureBase/indexCode', params={})

    def option_codes(self):
        """Returns option codes data."""
        return self._query_pd_pg(router='/quote/futureBase/optionCode', params={})

    def std_codes(self):
        """Returns standard codes data."""
        return self._query_pd_pg(router='/quote/futureBase/stdCode', params={})

__init__(wrapper=None)

Initializes an OqQuotes object.

Parameters:

Name Type Description Default
wrapper object

An object containing the API and username. Defaults to None.

None
Source code in onequant/api/quotes.py
 9
10
11
12
13
14
15
16
def __init__(self, wrapper=None):
    """Initializes an OqQuotes object.

    Args:
        wrapper (object, optional): An object containing the API and username. Defaults to None.
    """
    self.api = wrapper.api
    self.username = wrapper.username

codeinfos()

Returns code information data.

Source code in onequant/api/quotes.py
130
131
132
def codeinfos(self):
    """Returns code information data."""
    return self._query_pd_pg(router='/quote/futureBase/allCode', params={})

future_bars(code=None, interval=None, start_time=None, end_time=None, limit=None)

Fetches K-line (candlestick) data for futures.

Parameters:

Name Type Description Default
code str

The code of the future to fetch data for. Defaults to None.

None
interval str

The time interval for each K-line data point. Defaults to None.

None
start uint or str

The start time for the data fetch. Can be a timestamp or a date string.

required
end uint or str

The end time for the data fetch. Can be a timestamp or a date string.

required
limit int

The maximum number of data points to fetch. Defaults to None.If set limit value,then

None

Returns:

Type Description

pandas.DataFrame: The K-line data as a pandas DataFrame.

Source code in onequant/api/quotes.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
def future_bars(self, code=None, interval=None, start_time=None, end_time=None, limit=None):
    """Fetches K-line (candlestick) data for futures.

    Args:
        code (str, optional): The code of the future to fetch data for. Defaults to None.
        interval (str, optional): The time interval for each K-line data point. Defaults to None.
        start (uint or str, optional): The start time for the data fetch. Can be a timestamp or a date string.
        end (uint or str, optional): The end time for the data fetch. Can be a timestamp or a date string.
        limit (int, optional): The maximum number of data points to fetch. Defaults to None.If set limit value,then
        start will discarded.

    Returns:
        pandas.DataFrame: The K-line data as a pandas DataFrame.
    """
    if isinstance(start_time, int) and isinstance(end_time, int):
        params = {
            'symbol': code,
            'interval': interval,
            'start': start_time,
            'end': end_time,
            'limit': limit,
        }
        return self._querytd_pd(router='/tvquote/kline_ascend', params=params)
    else:
        params = {
            'symbol': code,
            'interval': interval,
            'start': OqDateTime.string_to_ms_timestamp(start_time),
            'end': OqDateTime.string_to_ms_timestamp(end_time),
            'limit': limit,
        }
        return self._querytd_pd(router='/tvquote/kline_ascend', params=params)

indexes()

Returns indexes data.

Source code in onequant/api/quotes.py
134
135
136
def indexes(self):
    """Returns indexes data."""
    return self._query_pd_pg(router='/quote/futureBase/indexCode', params={})

option_codes()

Returns option codes data.

Source code in onequant/api/quotes.py
138
139
140
def option_codes(self):
    """Returns option codes data."""
    return self._query_pd_pg(router='/quote/futureBase/optionCode', params={})

realtime_quote()

Returns realtime quote data.

Returns:

Type Description

pandas.DataFrame: The realtime quote data.

Source code in onequant/api/quotes.py
77
78
79
80
81
82
83
def realtime_quote(self):
    """Returns realtime quote data.

    Returns:
        pandas.DataFrame: The realtime quote data.
    """
    return self._query_pd(router='/quote/future/realTime/quote')

realtime_quotes()

Returns multiple realtime quote data.

Returns:

Type Description

pandas.DataFrame: The multiple realtime quote data.

Source code in onequant/api/quotes.py
85
86
87
88
89
90
91
def realtime_quotes(self):
    """Returns multiple realtime quote data.

    Returns:
        pandas.DataFrame: The multiple realtime quote data.
    """
    return self._query_pd(router='/quote/future/realTime/quotes')

std_codes()

Returns standard codes data.

Source code in onequant/api/quotes.py
142
143
144
def std_codes(self):
    """Returns standard codes data."""
    return self._query_pd_pg(router='/quote/futureBase/stdCode', params={})

symbols()

Returns symbols data.

Source code in onequant/api/quotes.py
126
127
128
def symbols(self):
    """Returns symbols data."""
    return self._query_pd_pg(router='/quote/futureBase/symbol', params={})