Skip to content

Commit

Permalink
♻️ refactor: rename exchange rate operations (#15)
Browse files Browse the repository at this point in the history
* ♻️  refactor: rename exchange rate operations

* ✅ test: update cassettes and snapshots
  • Loading branch information
ljnsn authored Mar 7, 2024
1 parent 10fbd1b commit de1ea57
Show file tree
Hide file tree
Showing 25 changed files with 8,849 additions and 255 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ if res.content is not None:

### [exchange_rates](docs/sdks/exchangerates/README.md)

* [get_specific_rate](docs/sdks/exchangerates/README.md#get_specific_rate) - [exchange rates] Get specific rate
* [get_v1_exchangerate_asset_id_base](docs/sdks/exchangerates/README.md#get_v1_exchangerate_asset_id_base) - [exchange rates] Get all current rates
* [get_v1_exchangerate_history_periods](docs/sdks/exchangerates/README.md#get_v1_exchangerate_history_periods) - [exchange rates] Timeseries periods
* [get_v1_exchangerate_asset_id_base_asset_id_quote_history](docs/sdks/exchangerates/README.md#get_v1_exchangerate_asset_id_base_asset_id_quote_history) - [exchange rates] Timeseries data
* [get_v1_specific_rate](docs/sdks/exchangerates/README.md#get_v1_specific_rate) - [exchange rates] Get specific rate
* [get_v1_base_rates](docs/sdks/exchangerates/README.md#get_v1_base_rates) - [exchange rates] Get all current rates
* [get_v1_history_periods](docs/sdks/exchangerates/README.md#get_v1_history_periods) - [exchange rates] Timeseries periods
* [get_v1_pair_history](docs/sdks/exchangerates/README.md#get_v1_pair_history) - [exchange rates] Timeseries data

### [indexes](docs/sdks/indexes/README.md)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetV1ExchangerateAssetIDBaseRequest
# GetV1BaseRatesRequest


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetV1ExchangerateAssetIDBaseResponse
# GetV1BaseRatesResponse


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetV1ExchangerateHistoryPeriodsResponse
# GetV1HistoryPeriodsResponse


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryRequest
# GetV1PairHistoryRequest


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryResponse
# GetV1PairHistoryResponse


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetSpecificRateRequest
# GetV1SpecificRateRequest


## Fields
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# GetSpecificRateResponse
# GetV1SpecificRateResponse


## Fields
Expand Down
40 changes: 19 additions & 21 deletions docs/sdks/exchangerates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Algorithm is described below:

### Available Operations

* [get_specific_rate](#get_specific_rate) - [exchange rates] Get specific rate
* [get_v1_exchangerate_asset_id_base](#get_v1_exchangerate_asset_id_base) - [exchange rates] Get all current rates
* [get_v1_exchangerate_history_periods](#get_v1_exchangerate_history_periods) - [exchange rates] Timeseries periods
* [get_v1_exchangerate_asset_id_base_asset_id_quote_history](#get_v1_exchangerate_asset_id_base_asset_id_quote_history) - [exchange rates] Timeseries data
* [get_v1_specific_rate](#get_v1_specific_rate) - [exchange rates] Get specific rate
* [get_v1_base_rates](#get_v1_base_rates) - [exchange rates] Get all current rates
* [get_v1_history_periods](#get_v1_history_periods) - [exchange rates] Timeseries periods
* [get_v1_pair_history](#get_v1_pair_history) - [exchange rates] Timeseries data

## get_specific_rate
## get_v1_specific_rate

Retrieves the exchange rate for a specific base and quote asset at a given time or the current rate.

Expand All @@ -48,8 +48,7 @@ s = coinapi.CoinAPI(
api_key="<YOUR_API_KEY_HERE>",
)


res = s.exchange_rates.get_specific_rate(asset_id_base='<value>', asset_id_quote='<value>', time='<value>')
res = s.exchange_rates.get_v1_specific_rate(asset_id_base='<value>', asset_id_quote='<value>', time='<value>')

if res.content is not None:
# handle response
Expand All @@ -67,14 +66,14 @@ if res.content is not None:

### Response

**[operations.GetSpecificRateResponse](../../models/operations/getspecificrateresponse.md)**
**[operations.GetV1SpecificRateResponse](../../models/operations/getv1specificrateresponse.md)**
### Errors

| Error Object | Status Code | Content Type |
| --------------- | --------------- | --------------- |
| errors.CoinAPIError | 4x-5xx | */* |

## get_v1_exchangerate_asset_id_base
## get_v1_base_rates

Get the current exchange rate between requested asset and all other assets.

Expand All @@ -95,8 +94,8 @@ s = coinapi.CoinAPI(
api_key="<YOUR_API_KEY_HERE>",
)


res = s.exchange_rates.get_v1_exchangerate_asset_id_base(asset_id_base='<value>', filter_asset_id='<value>', invert=False, time='<value>')
res = s.exchange_rates.get_v1_base_rates(asset_id_base='<value>', filter_asset_id='<value>', invert=False,
time='<value>')

if res.content is not None:
# handle response
Expand All @@ -115,14 +114,14 @@ if res.content is not None:

### Response

**[operations.GetV1ExchangerateAssetIDBaseResponse](../../models/operations/getv1exchangerateassetidbaseresponse.md)**
**[operations.GetV1BaseRatesResponse](../../models/operations/getv1baseratesresponse.md)**
### Errors

| Error Object | Status Code | Content Type |
| --------------- | --------------- | --------------- |
| errors.CoinAPIError | 4x-5xx | */* |

## get_v1_exchangerate_history_periods
## get_v1_history_periods

You can also obtain historical exchange rates of any asset pair, grouped into time periods.
Get full list of supported time periods available for requesting exchange rates historical timeseries data.
Expand All @@ -144,8 +143,7 @@ s = coinapi.CoinAPI(
api_key="<YOUR_API_KEY_HERE>",
)


res = s.exchange_rates.get_v1_exchangerate_history_periods()
res = s.exchange_rates.get_v1_history_periods()

if res.content is not None:
# handle response
Expand All @@ -155,14 +153,14 @@ if res.content is not None:

### Response

**[operations.GetV1ExchangerateHistoryPeriodsResponse](../../models/operations/getv1exchangeratehistoryperiodsresponse.md)**
**[operations.GetV1HistoryPeriodsResponse](../../models/operations/getv1historyperiodsresponse.md)**
### Errors

| Error Object | Status Code | Content Type |
| --------------- | --------------- | --------------- |
| errors.CoinAPIError | 4x-5xx | */* |

## get_v1_exchangerate_asset_id_base_asset_id_quote_history
## get_v1_pair_history

Get the historical exchange rates between two assets in the form of the timeseries.

Expand All @@ -176,12 +174,12 @@ s = coinapi.CoinAPI(
api_key="<YOUR_API_KEY_HERE>",
)

req = operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryRequest(
req = operations.GetV1PairHistoryRequest(
asset_id_base='<value>',
asset_id_quote='<value>',
)

res = s.exchange_rates.get_v1_exchangerate_asset_id_base_asset_id_quote_history(req)
res = s.exchange_rates.get_v1_pair_history(req)

if res.content is not None:
# handle response
Expand All @@ -192,12 +190,12 @@ if res.content is not None:

| Parameter | Type | Required | Description |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `request` | [operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryRequest](../../models/operations/getv1exchangerateassetidbaseassetidquotehistoryrequest.md) | :heavy_check_mark: | The request object to use for the request. |
| `request` | [operations.GetV1PairHistoryRequest](../../models/operations/getv1pairhistoryrequest.md) | :heavy_check_mark: | The request object to use for the request. |


### Response

**[operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryResponse](../../models/operations/getv1exchangerateassetidbaseassetidquotehistoryresponse.md)**
**[operations.GetV1PairHistoryResponse](../../models/operations/getv1pairhistoryresponse.md)**
### Errors

| Error Object | Status Code | Content Type |
Expand Down
32 changes: 16 additions & 16 deletions src/coinapi/exchange_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class ExchangeRates(Base):
1. By traversing the tree structure using the BFS algorithm and our secret sauce, we are able to establish the final exchange rates.
"""

def get_specific_rate(
def get_v1_specific_rate(
self,
asset_id_base: str,
asset_id_quote: str,
time: str | None = None,
accept_header_override: AcceptEnum | None = None,
) -> operations.GetSpecificRateResponse:
) -> operations.GetV1SpecificRateResponse:
r"""[exchange rates] Get specific rate.
Retrieves the exchange rate for a specific base and quote asset at a given time or the current rate.
Expand All @@ -41,23 +41,23 @@ def get_specific_rate(
"""
return self._make_request(
"Get specific rate",
operations.GetSpecificRateRequest(
operations.GetV1SpecificRateRequest(
asset_id_base=asset_id_base,
asset_id_quote=asset_id_quote,
time=time,
),
operations.GetSpecificRateResponse,
operations.GetV1SpecificRateResponse,
accept_header_override=accept_header_override,
)

def get_v1_exchangerate_asset_id_base( # noqa: PLR0913
def get_v1_base_rates( # noqa: PLR0913
self,
asset_id_base: str,
filter_asset_id: str | None = None,
invert: bool | None = None,
time: str | None = None,
accept_header_override: AcceptEnum | None = None,
) -> operations.GetV1ExchangerateAssetIDBaseResponse:
) -> operations.GetV1BaseRatesResponse:
r"""[exchange rates] Get all current rates.
Get the current exchange rate between requested asset and all other assets.
Expand All @@ -72,20 +72,20 @@ def get_v1_exchangerate_asset_id_base( # noqa: PLR0913
"""
return self._make_request(
"get_/v1/exchangerate/{asset_id_base}",
operations.GetV1ExchangerateAssetIDBaseRequest(
operations.GetV1BaseRatesRequest(
asset_id_base=asset_id_base,
filter_asset_id=filter_asset_id,
invert=invert,
time=time,
),
operations.GetV1ExchangerateAssetIDBaseResponse,
operations.GetV1BaseRatesResponse,
accept_header_override=accept_header_override,
)

def get_v1_exchangerate_history_periods(
def get_v1_history_periods(
self,
accept_header_override: AcceptEnum | None = None,
) -> operations.GetV1ExchangerateHistoryPeriodsResponse:
) -> operations.GetV1HistoryPeriodsResponse:
r"""[exchange rates] Timeseries periods.
You can also obtain historical exchange rates of any asset pair, grouped into time periods.
Expand All @@ -101,23 +101,23 @@ def get_v1_exchangerate_history_periods(
"""
return self._make_request(
"get_/v1/exchangerate/history/periods",
operations.GetV1ExchangerateHistoryPeriodsRequest(),
operations.GetV1ExchangerateHistoryPeriodsResponse,
operations.GetV1HistoryPeriodsRequest(),
operations.GetV1HistoryPeriodsResponse,
accept_header_override=accept_header_override,
)

def get_v1_exchangerate_asset_id_base_asset_id_quote_history(
def get_v1_pair_history(
self,
request: operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryRequest,
request: operations.GetV1PairHistoryRequest,
accept_header_override: AcceptEnum | None = None,
) -> operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryResponse:
) -> operations.GetV1PairHistoryResponse:
r"""[exchange rates] Timeseries data.
Get the historical exchange rates between two assets in the form of the timeseries.
"""
return self._make_request(
"get_/v1/exchangerate/{asset_id_base}/{asset_id_quote}/history",
request,
operations.GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryResponse,
operations.GetV1PairHistoryResponse,
accept_header_override=accept_header_override,
)
26 changes: 15 additions & 11 deletions src/coinapi/models/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
__all__ = (
"CoinAPIRequest",
"CoinAPIResponse",
"GetSpecificRateRequest",
"GetSpecificRateResponse",
"GetV1AssetsAssetIDRequest",
"GetV1AssetsAssetIDResponse",
"GetV1AssetsIconsSizeRequest",
"GetV1AssetsIconsSizeResponse",
"GetV1AssetsRequest",
"GetV1AssetsResponse",
"GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryRequest",
"GetV1ExchangerateAssetIDBaseAssetIDQuoteHistoryResponse",
"GetV1ExchangerateAssetIDBaseRequest",
"GetV1ExchangerateAssetIDBaseResponse",
"GetV1ExchangerateHistoryPeriodsResponse",
"GetV1BaseRatesRequest",
"GetV1BaseRatesResponse",
"GetV1ExchangesExchangeIDRequest",
"GetV1ExchangesExchangeIDResponse",
"GetV1ExchangesIconsSizeRequest",
"GetV1ExchangesIconsSizeResponse",
"GetV1ExchangesRequest",
"GetV1ExchangesResponse",
"GetV1HistoryPeriodsResponse",
"GetV1IndexesIndexIDHistoryRequest",
"GetV1IndexesIndexIDHistoryResponse",
"GetV1IndexesIndexIDRequest",
Expand Down Expand Up @@ -70,6 +66,8 @@
"GetV1OrderbooksSymbolIDHistoryResponse",
"GetV1OrderbooksSymbolIDLatestRequest",
"GetV1OrderbooksSymbolIDLatestResponse",
"GetV1PairHistoryRequest",
"GetV1PairHistoryResponse",
"GetV1QuotesCurrentRequest",
"GetV1QuotesCurrentResponse",
"GetV1QuotesLatestRequest",
Expand All @@ -80,6 +78,8 @@
"GetV1QuotesSymbolIDHistoryResponse",
"GetV1QuotesSymbolIDLatestRequest",
"GetV1QuotesSymbolIDLatestResponse",
"GetV1SpecificRateRequest",
"GetV1SpecificRateResponse",
"GetV1SymbolsExchangeIDRequest",
"GetV1SymbolsExchangeIDResponse",
"GetV1SymbolsMapExchangeIDRequest",
Expand All @@ -96,17 +96,16 @@
"PutV1IndexesIndexIDJSONRequest",
"PutV1IndexesIndexIDJSONResponse",
)

from coinapi.models.operations.base import CoinAPIRequest, CoinAPIResponse
from coinapi.models.operations.get_specific_rate import *
from coinapi.models.operations.get_v1_assets import *
from coinapi.models.operations.get_v1_assets_asset_id_ import *
from coinapi.models.operations.get_v1_assets_icons_size_ import *
from coinapi.models.operations.get_v1_exchangerate_asset_id_base_ import *
from coinapi.models.operations.get_v1_exchangerate_asset_id_base_asset_id_quote_history import *
from coinapi.models.operations.get_v1_exchangerate_history_periods import *
from coinapi.models.operations.get_v1_base_rates import *
from coinapi.models.operations.get_v1_exchanges import *
from coinapi.models.operations.get_v1_exchanges_exchange_id_ import *
from coinapi.models.operations.get_v1_exchanges_icons_size_ import *
from coinapi.models.operations.get_v1_history_periods import *
from coinapi.models.operations.get_v1_indexes import *
from coinapi.models.operations.get_v1_indexes_index_id_ import *
from coinapi.models.operations.get_v1_indexes_index_id_history import *
Expand All @@ -133,11 +132,16 @@
from coinapi.models.operations.get_v1_orderbooks_symbol_id_depth_current import *
from coinapi.models.operations.get_v1_orderbooks_symbol_id_history import *
from coinapi.models.operations.get_v1_orderbooks_symbol_id_latest import *
from coinapi.models.operations.get_v1_pair_history import (
GetV1PairHistoryRequest,
GetV1PairHistoryResponse,
)
from coinapi.models.operations.get_v1_quotes_current import *
from coinapi.models.operations.get_v1_quotes_latest import *
from coinapi.models.operations.get_v1_quotes_symbol_id_current import *
from coinapi.models.operations.get_v1_quotes_symbol_id_history import *
from coinapi.models.operations.get_v1_quotes_symbol_id_latest import *
from coinapi.models.operations.get_v1_specific_rate import *
from coinapi.models.operations.get_v1_symbols import *
from coinapi.models.operations.get_v1_symbols_exchange_id_ import *
from coinapi.models.operations.get_v1_symbols_map_exchange_id_ import *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

import msgspec

from coinapi.models.components import (
v1_exchangeratesrate as components_v1_exchangeratesrate,
)
from coinapi.models.components import v1_exchangeratesrate
from coinapi.models.operations.base import CoinAPIRequest, CoinAPIResponse


class GetV1ExchangerateAssetIDBaseRequest(CoinAPIRequest, frozen=True):
class GetV1BaseRatesRequest(CoinAPIRequest, frozen=True):
"""Get specific exchange rate for a specific base and quote asset at a given time or the current rate."""

method = "GET"
Expand Down Expand Up @@ -69,10 +67,8 @@ class GetV1ExchangerateAssetIDBaseRequest(CoinAPIRequest, frozen=True):

# NOTE: the spec for this response is wrong. Supposedly, the `V1ExchangeRatesRate` array is returned directly,
# but the actual response is a JSON object with a `rates` field containing the array.
class GetV1ExchangerateAssetIDBaseResponse(CoinAPIResponse, omit_defaults=True):
class GetV1BaseRatesResponse(CoinAPIResponse, omit_defaults=True):
"""Get specific exchange rate for a specific base and quote asset at a given time or the current rate."""

content: components_v1_exchangeratesrate.V1ExchangeRates | None = msgspec.field(
default=None,
)
content: v1_exchangeratesrate.V1ExchangeRates | None = msgspec.field(default=None)
r"""successful operation"""
Loading

0 comments on commit de1ea57

Please sign in to comment.