Skip to content

Commit 6fdcec0

Browse files
aniani
authored andcommitted
better context management
1 parent 7036e70 commit 6fdcec0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pythclient/hermes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(self, feed_ids: list[str], endpoint=HERMES_ENDPOINT_HTTPS, ws_endpo
3030
self.feed_ids = feed_ids
3131
self.pending_feed_ids = feed_ids
3232
self.prices_dict: dict[str, PriceFeed] = {}
33-
self.client = httpx.AsyncClient()
3433
self.endpoint = endpoint
3534
self.ws_endpoint = ws_endpoint
3635
self.feed_batch_size = feed_batch_size # max number of feed IDs to query at once in https requests
@@ -42,7 +41,8 @@ async def get_price_feed_ids(self) -> list[str]:
4241

4342
url = os.path.join(self.endpoint, "api/price_feed_ids")
4443

45-
data = (await self.client.get(url)).json()
44+
async with httpx.AsyncClient() as client:
45+
data = (await client.get(url)).json()
4646

4747
return data
4848

@@ -102,7 +102,8 @@ async def get_pyth_prices_latest(self, feedIds: list[str], version=2) -> list[Pr
102102
else:
103103
parse_unsupported_version(version)
104104

105-
data = (await self.client.get(url, params=params)).json()
105+
async with httpx.AsyncClient() as client:
106+
data = (await client.get(url, params=params)).json()
106107

107108
if version==1:
108109
results = []
@@ -127,7 +128,8 @@ async def get_pyth_price_at_time(self, feed_id: str, timestamp: int, version=2)
127128
else:
128129
parse_unsupported_version(version)
129130

130-
data = (await self.client.get(url, params=params)).json()
131+
async with httpx.AsyncClient() as client:
132+
data = (await client.get(url, params=params)).json()
131133

132134
if version==1:
133135
price_feed = self.extract_price_feed_v1(data)

0 commit comments

Comments
 (0)