-
Notifications
You must be signed in to change notification settings - Fork 155
Adding Polymarket Cookbook #858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
474bf3a
Adding Polymarket Cookbook
MichaelMacaulay b3c56bb
Fixing errors
MichaelMacaulay 7191ead
Update website/pages/en/subgraphs/cookbook/polymarket.mdx
MichaelMacaulay bf649e4
Update website/pages/en/subgraphs/cookbook/polymarket.mdx
MichaelMacaulay 5f66913
Update website/pages/en/subgraphs/cookbook/polymarket.mdx
MichaelMacaulay 8bec6f2
Edits
MichaelMacaulay d464387
Fixing errors
MichaelMacaulay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
title: Querying Blockchain Data from Polymarket with Subgraphs on The Graph | ||
--- | ||
|
||
Query Polymarket’s onchain data using GraphQL via subgraphs on The Graph Network. Subgraphs are decentralized APIs powered by The Graph, a protocol for indexing & querying data from blockchains. | ||
|
||
## Polymarket Subgraph on Graph Explorer | ||
|
||
You can see an interactive query playground on the [Polymarket subgraph’s page on The Graph Explorer](https://thegraph.com/explorer/subgraphs/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp?view=Query&chain=arbitrum-one), where you can test any query. | ||
|
||
 | ||
|
||
## How to use the Visual Query Editor | ||
|
||
The visual query editor helps you test sample queries from your subgraph. | ||
|
||
You can use the GraphiQL Explorer to compose your GraphQL queries by clicking on the fields you want. | ||
|
||
### Example Query: Get the top 5 highest payouts from Polymarket | ||
|
||
``` | ||
{ | ||
redemptions(orderBy: payout, orderDirection: desc, first: 5) { | ||
payout | ||
redeemer | ||
id | ||
timestamp | ||
} | ||
} | ||
``` | ||
|
||
### Example output | ||
|
||
``` | ||
{ | ||
"data": { | ||
"redemptions": [ | ||
{ | ||
"id": "0x8fbb68b7c0cbe9aca6024d063a843a23d046b5522270fd25c6a81c511cf517d1_0x3b", | ||
"payout": "6274509531681", | ||
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c", | ||
"timestamp": "1722929672" | ||
}, | ||
{ | ||
"id": "0x2b2826448fcacde7931828cfcd3cc4aaeac8080fdff1e91363f0589c9b503eca_0x7", | ||
"payout": "2246253575996", | ||
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c", | ||
"timestamp": "1726701528" | ||
}, | ||
{ | ||
"id": "0x983b71c64b5075fc1179f4e03849af9c727be60de71c9e86e37ad0b3e43f9db9_0x26", | ||
"payout": "2135448291991", | ||
"redeemer": "0x5a181dcf3eb53a09fb32b20a5a9312fb8d26f689", | ||
"timestamp": "1704932625" | ||
}, | ||
{ | ||
"id": "0x2b2826448fcacde7931828cfcd3cc4aaeac8080fdff1e91363f0589c9b503eca_0xa", | ||
"payout": "1917395333835", | ||
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c", | ||
"timestamp": "1726701528" | ||
}, | ||
{ | ||
"id": "0xfe82e117201f5169abc822281ccf0469e6b3740fcb4e799d1b599f83b8f11656_0x30", | ||
"payout": "1862505580000", | ||
"redeemer": "0xfffe4013adfe325c6e02d36dc66e091f5476f52c", | ||
"timestamp": "1722929866" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Polymarket's GraphQL Schema | ||
|
||
The schema for this subgraph is defined [here in Polymarket’s GitHub](https://github.com/Polymarket/polymarket-subgraph/blob/main/polymarket-subgraph/schema.graphql). | ||
|
||
### Polymarket Subgraph Endpoint | ||
|
||
https://gateway.thegraph.com/api/{api-key}/subgraphs/id/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp | ||
|
||
The Polymarket Subgraph endpoint is available on [Graph Explorer](https://thegraph.com/explorer). | ||
|
||
 | ||
|
||
## How to Get your own API Key | ||
|
||
1. Go to [https://thegraph.com/studio](http://thegraph.com/studio) and connect your wallet | ||
2. Go to https://thegraph.com/studio/apikeys/ to create an API key | ||
|
||
You can use this API key on any subgraph in [Graph Explorer](https://thegraph.com/explorer), and it’s not limited to just Polymarket. | ||
|
||
100k queries per month are free which is perfect for your side project! | ||
|
||
## Additional Polymarket Subgraphs | ||
|
||
- [Polymarket](https://thegraph.com/explorer/subgraphs/81Dm16JjuFSrqz813HysXoUPvzTwE7fsfPk2RTf66nyC?view=Query&chain=arbitrum-one) | ||
- [Polymarket Activity Polygon](https://thegraph.com/explorer/subgraphs/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp?view=Query&chain=arbitrum-one) | ||
- [Polymarket Profit & Loss](https://thegraph.com/explorer/subgraphs/6c58N5U4MtQE2Y8njfVrrAfRykzfqajMGeTMEvMmskVz?view=Query&chain=arbitrum-one) | ||
- [Polymarket Open Interest](https://thegraph.com/explorer/subgraphs/ELaW6RtkbmYNmMMU6hEPsghG9Ko3EXSmiRkH855M4qfF?view=Query&chain=arbitrum-one) | ||
|
||
## How to Query with the API | ||
|
||
You can pass any GraphQL query to the Polymarket endpoint and receive data in json format. | ||
|
||
This following code example will return the exact same output as above. | ||
|
||
### Sample Code from node.js | ||
|
||
``` | ||
const axios = require('axios'); | ||
|
||
const graphqlQuery = `{ | ||
positions(first: 5) { | ||
condition | ||
outcomeIndex | ||
} | ||
}; | ||
|
||
const queryUrl = 'https://gateway.thegraph.com/api/{api-key}/subgraphs/id/Bx1W4S7kDVxs9gC3s2G6DS8kdNBJNVhMviCtin2DiBp' | ||
|
||
const graphQLRequest = { | ||
method: 'post', | ||
url: queryUrl, | ||
data: { | ||
query: graphqlQuery, | ||
}, | ||
}; | ||
|
||
// Send the GraphQL query | ||
axios(graphQLRequest) | ||
.then((response) => { | ||
// Handle the response here | ||
const data = response.data.data | ||
console.log(data) | ||
|
||
}) | ||
.catch((error) => { | ||
// Handle any errors | ||
console.error(error); | ||
}); | ||
``` | ||
|
||
### Additional resources | ||
|
||
For more information about querying data from your subgraph, read more [here](/subgraphs/querying/introduction/). | ||
|
||
To explore all the ways you can optimize & customize your subgraph for a better performance, read more about [creating a subgraph here](/developing/creating-a-subgraph/). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.