Skip to content

Commit

Permalink
Add remaining defi apis (#11)
Browse files Browse the repository at this point in the history
* test: add defi tests [#4]

* docs: update docs with defi apis [#4]
  • Loading branch information
nickatnight authored Nov 25, 2024
1 parent 93f8aa8 commit eac50ca
Show file tree
Hide file tree
Showing 7 changed files with 505 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.6"
__version__ = "0.0.7"


class BirdEye:
Expand Down
230 changes: 230 additions & 0 deletions birdeyepy/resources/defi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,233 @@ def history(
response = self.http.send(path=BirdEyeApiUrls.DEFI_HISTORY_PRICE, **request)

return cast(dict, response)

def supported_networks(self) -> dict:
"""Get a list of all supported networks."""
response = self.http.send(path=BirdEyeApiUrls.DEFI_SUPPORTED_NETWORKS)

return cast(dict, response)

@as_api_args
def price_multiple(
self,
*,
addresses: list | str,
check_liquidity: Optional[int] = 100,
include_liquidity: Optional[bool] = None,
) -> dict:
"""Get price updates of multiple tokens in a single API call. Maximum 100 tokens
:param addresses: The addresses of the tokens.
:param check_liquidity: The minimum liquidity to check.
:param include_liquidity: Include liquidity in the response.
"""
params = {"list_address": addresses, "check_liquidity": check_liquidity}

if include_liquidity is not None:
params["include_liquidity"] = include_liquidity

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_PRICE_MULTIPLE, **request)

return cast(dict, response)

def history_by_unix(self, *, address: str, unixtime: int) -> dict:
"""Get historical price of a token at a specific Unix time.
:param address: The address of the token.
:param unixtime: The Unix time.
"""
params = {"address": address, "time": unixtime}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(
path=BirdEyeApiUrls.DEFI_HISTORY_PRICE_BY_UNIX, **request
)

return cast(dict, response)

def trades_token(
self,
*,
address: Optional[str] = DEFAULT_SOL_ADDRESS,
tx_type: Optional[str] = "swap",
sort_type: Optional[str] = "desc",
offset: Optional[int] = 0,
limit: Optional[int] = 50,
) -> dict:
"""Get trades of a token.
:param address: The address of the token.
:param tx_type: The type of transaction.
:param sort_type: The type of sorting.
:param limit: The limit.
"""
params = {
"address": address,
"tx_type": tx_type,
"sort_type": sort_type,
"offset": offset,
"limit": limit,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_TRADES_TOKEN, **request)

return cast(dict, response)

def trades_pair(
self,
*,
address: str,
tx_type: Optional[str] = "swap",
sort_type: Optional[str] = "desc",
offset: Optional[int] = 0,
limit: Optional[int] = 50,
) -> dict:
"""Get list of trades of a certain pair or market.
:param address: The address of the token.
:param tx_type: The type of transaction.
:param sort_type: The type of sorting.
:param limit: The limit.
"""
params = {
"address": address,
"tx_type": tx_type,
"sort_type": sort_type,
"offset": offset,
"limit": limit,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_TRADES_PAIR, **request)

return cast(dict, response)

def trades_token_by_time(
self,
*,
address: Optional[str] = DEFAULT_SOL_ADDRESS,
tx_type: Optional[str] = "swap",
sort_type: Optional[str] = "desc",
offset: Optional[int] = 0,
limit: Optional[int] = 50,
before_time: Optional[int] = 0,
after_time: Optional[int] = 0,
) -> dict:
"""Get list of trades of a token with time bound option."""
params = {
"address": address,
"tx_type": tx_type,
"sort_type": sort_type,
"offset": offset,
"limit": limit,
"before_time": before_time,
"after_time": after_time,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(
path=BirdEyeApiUrls.DEFI_TRADES_TOKEN_BY_TIME, **request
)

return cast(dict, response)

def trades_pair_by_time(
self,
*,
address: Optional[str] = DEFAULT_SOL_ADDRESS,
tx_type: Optional[str] = "swap",
sort_type: Optional[str] = "desc",
offset: Optional[int] = 0,
limit: Optional[int] = 50,
before_time: Optional[int] = 0,
after_time: Optional[int] = 0,
) -> dict:
"""Get list of trades of a certain pair or market with time bound option."""
params = {
"address": address,
"tx_type": tx_type,
"sort_type": sort_type,
"offset": offset,
"limit": limit,
"before_time": before_time,
"after_time": after_time,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(
path=BirdEyeApiUrls.DEFI_TRADES_PAIR_BY_TIME, **request
)

return cast(dict, response)

def ohlcv(
self,
*,
address: str,
time_from: int,
time_to: int,
type_in_time: Optional[str] = "15m",
) -> dict:
"""Get OHLCV price of a token.
:param address: The address of the token.
:param time_from: Specify the start time using Unix timestamps in seconds
:param time_to: Specify the end time using Unix timestamps in seconds
:param type_in_time: The type of time...defaults to '15m'
"""
params = {
"address": address,
"time_from": time_from,
"time_to": time_to,
"type": type_in_time,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_OHLCV, **request)

return cast(dict, response)

def ohlcv_pair(
self,
*,
address: str,
time_from: int,
time_to: int,
type_in_time: Optional[str] = "15m",
) -> dict:
"""Get OHLCV price of a pair.
:param address: The address of the token.
:param time_from: Specify the start time using Unix timestamps in seconds
:param time_to: Specify the end time using Unix timestamps in seconds
:param type_in_time: The type of time...defaults to '15m'
"""
params = {
"address": address,
"time_from": time_from,
"time_to": time_to,
"type": type_in_time,
}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_OHLCV_PAIR, **request)

return cast(dict, response)

def volume_price_single(
self, *, address: str, type_in_time: Optional[str] = "24h"
) -> dict:
"""Get volume and price of a token.
:param address: The address of the token.
:param type_in_time: The type of time...defaults to '24h'
"""
params = {"address": address, "type": type_in_time}

request: BirdEyeRequestParams = {"params": params}
response = self.http.send(path=BirdEyeApiUrls.DEFI_VOLUME_SINGLE, **request)

return cast(dict, response)
10 changes: 10 additions & 0 deletions birdeyepy/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class BirdEyeApiUrls:
DEFI_PRICE = "defi/price"
DEFI_TOKEN_LIST = "defi/tokenlist"
DEFI_HISTORY_PRICE = "defi/history_price"
DEFI_SUPPORTED_NETWORKS = "defi/networks"
DEFI_PRICE_MULTIPLE = "defi/multi_price"
DEFI_HISTORY_PRICE_BY_UNIX = "defi/historical_price_unix"
DEFI_TRADES_TOKEN = "defi/txs/token"
DEFI_TRADES_PAIR = "defi/txs/pair"
DEFI_TRADES_TOKEN_BY_TIME = "defi/txs/token/seek_by_time"
DEFI_TRADES_PAIR_BY_TIME = "defi/txs/pair/seek_by_time"
DEFI_OHLCV = "defi/ohlcv"
DEFI_OHLCV_PAIR = "defi/ohlcv/pair"
DEFI_VOLUME_SINGLE = "defi/price_volume/single"

# TRADER
TRADER_GAINERS_LOSERS = "trader/gainers-losers"
Expand Down
57 changes: 57 additions & 0 deletions docs/source/code_overview/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,63 @@ APIs
type_in_time="15m" # default
)
# https://docs.birdeye.so/reference/get_defi-networks
client.defi.supported_networks()
# https://docs.birdeye.so/reference/get_defi-multi-price
client.defi.price_multiple(
addresses=["Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ", "AGQZRtz7hZtz3VJ1CoXRMNMyh2ZMZ1g6pv4aGMUSpump"],
) # can also use comma separated strings 'Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ,AGQZRtz7hZtz3VJ1CoXRMNMyh2ZMZ1g6pv4aGMUSpump'
# https://docs.birdeye.so/reference/get_defi-historical-price-unix
client.defi.history_by_unix(
address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ",
unixtime=1732398942
)
# https://docs.birdeye.so/reference/get_defi-txs-token
client.defi.trades_token(
address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ
)
# https://docs.birdeye.so/reference/get_defi-txs-pair
client.defi.trades_pair(
address="9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT
)
# https://docs.birdeye.so/reference/get_defi-txs-token-seek-by-time
client.defi.trades_token_by_time(
address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ",
before_time=1732398942,
after_time=1732398961
)
# https://docs.birdeye.so/reference/get_defi-txs-pair-seek-by-time
client.defi.trades_pair_by_time(
address="9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT",
before_time=1732398942,
after_time=1732398961
)
# https://docs.birdeye.so/reference/get_defi-ohlcv
client.defi.ohlcv(
address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ",
time_from=1732398942,
time_to=1732398961
)
# https://docs.birdeye.so/reference/get_defi-ohlcv-pair
client.defi.ohlcv_pair(
address="9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT",
time_from=1732398942,
time_to=1732398961
)
# https://docs.birdeye.so/reference/get_defi-price-volume-single
client.defi.volume_price_single(
address="Gr11mosZNZjwpqnemXNnWs9E2Bnv7R6vzaKwJTdjo8zQ"
)
# TOKEN
# https://docs.birdeye.so/reference/get_defi-tokenlist
Expand Down
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.6"
version = "0.0.7"
description = "Python wrapper for birdeye.so api"
readme = "README.md"
requires-python = ">=3.9"
Expand Down
Loading

0 comments on commit eac50ca

Please sign in to comment.