Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions balpy/balpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2069,8 +2069,18 @@ def balGetLinkToFrontend(self, poolId):
else:
return("")

def balGetApiEndpoint(self, endpoint):
return(os.path.join(self.apiEndpoint, endpoint, str(self.networkParams[self.network]["id"])));

def balGetApiEndpointSor(self):
return(os.path.join(self.apiEndpoint, "sor", str(self.networkParams[self.network]["id"])));
return(self.balGetApiEndpoint("sor"));

def balGetApiEndpointPools(self, poolId=None):
endpoint = self.balGetApiEndpoint("pools");
if poolId is None:
return(endpoint);
else:
return(os.path.join(endpoint, poolId));

def balSorQuery(self, data):
query = data["sor"];
Expand Down Expand Up @@ -2100,6 +2110,35 @@ def balSorQuery(self, data):

return(batch_swap)

def balApiGetPools(self):
url = self.balGetApiEndpointPools()
success = False
resp = None;
maxRetries = 5
retries = 0
delay = 3
while not success or retries > maxRetries:
response = requests.get(
url,
headers={'Content-Type': 'application/json'}
);
if response.status_code == 200:
success = True
resp = response.json()
else:
retries += 1
print("Query failed, trying in", delay, "seconds")
time.sleep(delay)
return(resp)

def balApiGetPool(self, poolId):
url = self.balGetApiEndpointPools(poolId)
response = requests.get(
url,
headers={'Content-Type': 'application/json'}
);
return(response.json())

def balSorResponseToBatchSwapFormat(self, query, response):
sor = query["sor"];
del query["sor"];
Expand Down Expand Up @@ -2203,7 +2242,7 @@ def getOnchainData(self, pools):
pidAndFns.append((poolId, "getPausedState"));

# === using weighted math ===
if poolType in ["Weighted", "LiquidityBootstrapping", "Investment"]:
if poolType in ["Weighted", "LiquidityBootstrapping", "Investment", "Managed"]:
self.mc.addCall(currPool.address, currPool.abi, 'getNormalizedWeights');
pidAndFns.append((poolId, "getNormalizedWeights"));

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "balpy"
version = "0.0.0a84"
version = "0.0.0a85"
description = "Balancer V2 Python API"
authors = ["Greg <greg@orb.cl>"]
authors = ["Greg <greg@threerocks.io>"]
license = "GNU GPL 3"

[tool.poetry.dependencies]
Expand Down
21 changes: 21 additions & 0 deletions samples/api/apiQuerySample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import balpy
import json

def main():

network = "mainnet";
poolId = "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014";

bal = balpy.balpy.balpy(network)

print("Querying single pool", poolId)
pool = bal.balApiGetPool(poolId);
print(json.dumps(pool, indent=4))
print()

print("Querying all pools on", network)
pools = bal.balApiGetPools();
print(json.dumps(pools, indent=4))

if __name__ == '__main__':
main();