diff --git a/examples/javascript/get-all-pools.md b/examples/javascript/get-all-pools.md new file mode 100644 index 0000000..eed7664 --- /dev/null +++ b/examples/javascript/get-all-pools.md @@ -0,0 +1,34 @@ +## Ocean-subgraph javascript example + +Query to get all datatoken pools + +```javascript +const axios = require('axios'); + +const BASE_URL = 'https://subgraph.rinkeby.oceanprotocol.com'; +const SUBGRAPHS_QUERY_ROUTE = '/subgraphs/name/oceanprotocol/ocean-subgraph'; + +const url = BASE_URL + SUBGRAPHS_QUERY_ROUTE; + +async function getAllPoolDatatokenAddresses(url) { + const requestBody = { query: '{ pools(first:1000, orderBy: oceanReserve, orderDirection: desc) { id valueLocked name consumePrice totalShares symbol cap datatokenAddress tokens { id balance name symbol } } }' }; + const response = await axios.post(url, requestBody).catch((error) => { + const { status, statusText, data } = error.response; + console.error('Error getting data from subgraph: ', status, statusText, data); + throw new Error(statusText); + }); + const { data: { data: { pools }, }, } = response; + return pools.filter((pool) => pool.datatokenAddress).map((pool) => pool.datatokenAddress); +} + +getAllPoolDatatokenAddresses(url).then(result => { + console.log(result) +}); + +``` + + +### Credits +- German Navarro - Github user: gmanavarro - Discord user: Naga#2072 +- Axel Diaz - Github user: axeldiaz10 - Discord user: axeldiaz10#0085 +- Juan Arrillaga - Github user: jarrillaga - Discord user: juanarri#3482 \ No newline at end of file diff --git a/examples/python/get-orders.md b/examples/python/get-orders.md new file mode 100644 index 0000000..3fc70bd --- /dev/null +++ b/examples/python/get-orders.md @@ -0,0 +1,35 @@ +## Ocean-subgraph python example + +Query to fetch all datatoken `Transfer` events + +```python +import requests +import json + +datatoken_address = "0x00b43f5905ff736526294ac6de52d1dcd35821c9" +base_url = "https://subgraph.rinkeby.oceanprotocol.com" +route = "/subgraphs/name/oceanprotocol/ocean-subgraph" +url = base_url + route + +query = """{{ + tokenOrders(where:{{datatokenId:"{0}"}}, first: 5, orderBy: timestamp, orderDirection: desc) {{ + id + consumer {{id}} + payer {{id}} + serviceId + marketFeeCollector {{id}} + marketFee + tx + block + }} + }}""".format(datatoken_address) + +headers = {"Content-Type": "application/json"} + +payload = json.dumps({"query": query}) +response = requests.request("POST", url, headers=headers, data=payload) +result = json.loads(response.text) + + +print(result) +``` \ No newline at end of file diff --git a/examples/python/global-statistics.md b/examples/python/global-statistics.md new file mode 100644 index 0000000..b7a7b8f --- /dev/null +++ b/examples/python/global-statistics.md @@ -0,0 +1,34 @@ + +## Ocean-subgraph python example + +Query global statistics like `totalValueLocked`, `totalOceanLiquidity`, `orderCount`, etc. + +```python +import requests +import json + +base_url = "https://subgraph.rinkeby.oceanprotocol.com" +route = "/subgraphs/name/oceanprotocol/ocean-subgraph" +url = base_url + route + +query = """ +{ +globals { + id + totalValueLocked + totalOceanLiquidity + totalSwapVolume + totalOrderVolume + orderCount + poolCount +} +}""" + +headers = {"Content-Type": "application/json"} + +payload = json.dumps({"query": query}) +response = requests.request("POST", url, headers=headers, data=payload) +result = json.loads(response.text) + +print(result) +``` diff --git a/examples/python/list-datatokens.md b/examples/python/list-datatokens.md new file mode 100644 index 0000000..a405053 --- /dev/null +++ b/examples/python/list-datatokens.md @@ -0,0 +1,41 @@ +## Ocean-subgraph python example + +Query to fetch all datatoken "Transfer" events + +```python +import requests +import json + +datatoken_address = "0xd0a8540db74bab9ef5847a2424ee3fc26b4518a5" +base_url = "https://subgraph.rinkeby.oceanprotocol.com" +route = "/subgraphs/name/oceanprotocol/ocean-subgraph" +url = base_url + route + +query_string = """{{tokenTransactions(skip: {0}, first: {1}, + where:{{event:"Transfer",datatokenAddress:"{2}"}}, + orderBy: timestamp, orderDirection: asc) {{ + id, + event + timestamp + block + }}}}""" + +headers = {"Content-Type": "application/json"} + +skip = 0 +limit = 1000 +result = [] +while True: + query = query_string.format(skip, limit, datatoken_address) + payload = json.dumps({"query": query}) + response = requests.request("POST", url, headers=headers, data=payload) + if response.status_code != 200: + break + data = json.loads(response.text) + if (len(data["data"]["tokenTransactions"])) == 0: + break + result.append(data["data"]) + skip = skip + limit + +print(result) +``` \ No newline at end of file