Skip to content

Commit

Permalink
Add 'Pair' API (#14)
Browse files Browse the repository at this point in the history
* feat: add 'Pair' api [#12]

* docs: add pair example [#12]

* chore: version bump [#12]
  • Loading branch information
nickatnight authored Dec 17, 2024
1 parent eac50ca commit 31a9dfb
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 3 deletions.
2 changes: 1 addition & 1 deletion birdeyepy/birdeye.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
)


__version__ = "0.0.7"
__version__ = "0.0.8"


class BirdEye:
Expand Down
2 changes: 2 additions & 0 deletions birdeyepy/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .defi import DeFi
from .pair import Pair
from .token import Token
from .trader import Trader

Expand All @@ -7,4 +8,5 @@
"defi": DeFi,
"token": Token,
"trader": Trader,
"pair": Pair,
}
40 changes: 40 additions & 0 deletions birdeyepy/resources/pair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import cast

from birdeyepy.utils import BirdEyeApiUrls, BirdEyeRequestParams, IHttp, as_api_args


class Pair:
def __init__(self, http: IHttp) -> None:
self.http = http

@as_api_args
def overview_multiple(
self,
*,
list_address: list[str],
) -> dict:
"""Get overview of multiple pairs.
:param list_address: A list of addresses
"""
params = {"list_address": list_address}
request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.PAIR_OVERVIEW_MULTIPLE, **request)

return cast(dict, response)

@as_api_args
def overview_single(
self,
*,
address: str,
) -> dict:
"""Get overview of single pair
:param list_address: A list of addresses
"""
params = {"address": address}
request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.PAIR_OVERVIEW_SINGLE, **request)

return cast(dict, response)
4 changes: 4 additions & 0 deletions birdeyepy/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class BirdEyeApiUrls:
WALLET_TRANSACTION_HISTORY_MULTICHAIN = "v1/wallet/multichain_tx_list"
WALLET_TRANSACTION_SIMULATION = "v1/wallet/simulate"

# PAIR
PAIR_OVERVIEW_MULTIPLE = "defi/v3/pair/overview/multiple"
PAIR_OVERVIEW_SINGLE = "defi/v3/pair/overview/single"


class BirdEyeChainEnum(SimpleEnum):
# Solana
Expand Down
11 changes: 11 additions & 0 deletions docs/source/code_overview/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BirdEye Client
resources/token
resources/trader
resources/wallet
resources/pair


.. note::
Expand Down Expand Up @@ -159,3 +160,13 @@ APIs
# https://docs.birdeye.so/reference/get_defi-v3-token-holder
client.token.holder(address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ")
# PAIR
# https://docs.birdeye.so/reference/get_defi-v3-pair-overview-multiple
client.pair.overview_multiple(
list_address=["Cv5w6oLCquS4M3WN7DcwFrFiCCJwiL31MCJu3jTXpump", "FMNB4a8TFNvo3go6tkUQmr2YJHBxhiuT39bt3j6qjGJc"]
)
# https://docs.birdeye.so/reference/get_defi-v3-pair-overview-single
client.pair.overview_single(address="Cv5w6oLCquS4M3WN7DcwFrFiCCJwiL31MCJu3jTXpump")
5 changes: 5 additions & 0 deletions docs/source/code_overview/resources/pair.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Pair
====

.. autoclass:: birdeyepy.resources.pair.Pair
:members:
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "birdeye-py"
version = "0.0.7"
version = "0.0.8"
description = "Python wrapper for birdeye.so api"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/resources/test_pair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from unittest.mock import MagicMock

from birdeyepy.resources.pair import Pair
from birdeyepy.utils import BirdEyeApiUrls


def test_pair_overview_multiple_called_with_expected_args() -> None:
# Arrange
mock_http = MagicMock()

# Act
client = Pair(http=mock_http)
client.overview_multiple(list_address=["test1", "test2"])

# Assert
mock_http.send.assert_called_once_with(
path=BirdEyeApiUrls.PAIR_OVERVIEW_MULTIPLE,
params={"list_address": "test1,test2"},
)


def test_pair_overview_single_called_with_expected_args() -> None:
# Arrange
mock_http = MagicMock()

# Act
client = Pair(http=mock_http)
client.overview_single(address="test1")

# Assert
mock_http.send.assert_called_once_with(
path=BirdEyeApiUrls.PAIR_OVERVIEW_SINGLE,
params={"address": "test1"},
)
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31a9dfb

Please sign in to comment.