NOTE: The Graph compiles to WASM. This is AssemblyScript, not TypeScript. Please review the AssemblyScript documentation.
Notable limitations: No JSON, deconstruction, closures, global importing.
Please show successful build output when submitting PRs.
Because gTrade is on Polygon, subgraphs are part of The Graph's Hosted Service offering.
Polygon subgraph: https://thegraph.com/hosted-service/subgraph/dreamstreet-xyz/gtrade-v6
Mumbai subgraph: https://thegraph.com/hosted-service/subgraph/dreamstreet-xyz/gtrade-v6-mumbai
yarn configure:<network>
- Be sure you've created a subgraph and have your token available.
- Update subgraph details in
package.json
GRAPH_ACCESS_TOKEN=<token> yarn deploy:<network>
Decentralized leverage trading platform from Gains Network
Subgraph constructs and tracks:
- Trades across states pre open, open, close
- Orders: open limit orders, nft orders, slupdateorders, market orders
- Beginnings of traders and NFT holders
Subgraph listens to the following events:
- GNSTradingV6
- ChainlinkCallbackTimeout
- MarketOrderInitiated
- NftOrderInitiated
- OpenLimitCanceled
- OpenLimitPlaced
- OpenLimitUpdated
- SlUpdateInitiated
- SlUpdated
- TpUpdated
- GNSTradingCallbacksV6
- LimitExecuted
- MarketCloseCanceled
- MarketExecuted
- MarketOpenCanceled
- SlCanceled
- SlUpdated
- GNSTradingVaultV5
- Sent
- ToClaim
Please refer to schemas for fields available.
Rule of thumb: anything stored or emitted from the blockchain is stored (there are some derived fields as well).
Tracks a trade across its lifecycle, from pre-open to close.
LIMIT_ORDER_PENDING
- limit order is requestedLIMIT_ORDER_CANCELED
- limit order is canceled before fulfillmentOPENING
- pricing information is requested for open of tradeOPEN
- trade is openCANCELED
- trade is canceledOPEN_TIMED_OUT
- trade is canceled because of price request timeoutCLOSING
- pricing information is requsted for close of tradeCLOSE_TIMED_OUT
- pricing request timed out for close of tradeCLOSED
- trade is closed
Derived trade information is stored as well, such as pnl, fees, percent profit, etc.
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/trade/Trade.gql
Tracks a price order across its lifecycle, from requested to received.
REQUESTED
- price order is requestedTIMED_OUT
- price request timed outRECEIVED
- price order is received
Three kinds of price orders(these are all their own entities):
Open or close requested by trader
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/order/price/MarketOrder.gql
Open or close requested by nft holder
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/order/price/NftOrder.gql
SL update requested by trader
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/order/price/SlUpdateOrder.gql
Tracks an open limit order across its lifecycle, from opened to fulfilled
OPEN
- limit order is openCANCELED
- limit order is canceled before fulfillmentFULFILLING
- limit order is fulfilling (price request is in progress)FULFILLED
- limit order is fulfilled
Address of the NFT holder
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/user/NftHolder.gql
Address of the trader
Schema: https://github.com/Dreamstreet-xyz/gtrade-subgraph/blob/main/schema/user/Trader.gql
The following query will provide you with the same details as My Trades history on gains.trade:
Replace <lower-case-address>
with your address in lower case.
{
trades(where: {trader: "<lower-case-address>", status: CLOSED}, orderBy: createdAtBlockNumber, orderDirection: asc) {
createdAtTimestamp
pairIndex
createdAtBlockNumber
trader {
id
}
marketOrders(where: {type_in: [MARKET_CLOSE]}) {
type
price
transactions
}
nftOrders(where: {type_in: [LIMIT_CLOSE]}) {
type
price
transactions
}
closePrice
buy
positionSizeDai
leverage
pnl
}
}
The following query will provide the same details as All Trades (24h) on gains.trade:
Replace <block_24h_ago>
with the block 24hrs ago.
{
trades(where:{createdAtBlockNumber_gte: <block_24h_ago>, status:CLOSED}, orderBy: createdAtBlockNumber, orderDirection: asc){
createdAtTimestamp
createdAtBlockNumber
pairIndex
trader{
id
}
type
openPrice
closePrice
leverage
positionSizeDai
pnl
}
}
When opening a trade there are number of issues that might cause you to lose track of it. The following query will help troubleshoot the state:
Replace <lower-case-address>
with your address in lower case, and pair-index
with the your pair index just opened.
{
trader(id:"<lower-case-address>"){
trades(where:{status_not_in:[CLOSED], pairIndex: <pair-index>}){
createdAtTimestamp
status
positionSizeDai
marketOrders{
type
status
transactions
}
nftOrders{
type
status
transactions
}
}
}
}
From this, you can see what the status is and corresponding states of orders + transactions to further the troubleshooting.
The following query will provide the same details as Your Open Trades on gains.trade:
Replace lower-case-address
with your address in lower case.
{
trader(id:"<lower-case-address>"){
trades(where:{status:OPEN}){
pairIndex
index
positionSizeDai
leverage
openPrice
openFeeDai
buy
sl
tp
}
}
}
- See when your Open Limit Order was triggered, down to the transaction
- See what NFT holder triggered your liquidation
- Confirm you updated your SL
- See close price of your trade
- etc...