Skip to content

API Setup Guide

A short and simple API Setup guide to get you rolling quick!
It assumes bare minimum knowledge about GRVT. So anyone can get through these steps. (ideally!)

Step 1: Create Web2 Account

Link: https://testnet.grvt.io/exchange/sign-up

create account

Follow the instructions to create your Personal Or Business Account.

Step 2: Create Wallet

create wallet create wallet

Follow the instructions to link your wallet to GRVT. You may link any of your existing wallets, or create a convenient web wallet on GRVT.

Step 3: Create Web3 Accounts

GRVT has a two tier account structure.

  • Funding (main) Account: Used to bridge funds in and out of GRVT, acts as an administrative layer.
  • Trading (sub) Account: Used for derivative trading.

create wallet

Follow the instructions to complete the setup.

You have to sign on-chain to create your accounts, since this is the way we protect your self-custody.

Step 4: Mint Tokens & Transfer

In testnet, we give you a convenient way to mint tokens, so that you can get up and testing quicker.
Please remember to mint sufficient funds, and transfer some to your trading accounts.
You may always revisit this link https://testnet.grvt.io/exchange/deposit to get more.

mint mint

Step 5: Create API Key

Finally we are getting to the heart of things!
Create an API Key at this site https://testnet.grvt.io/exchange/account/api-keys.

Create API Key Create API Key Create API Key Create API Key

Step 6: API Docs Auth

Authentication

In order to authenticate, you must first provision a valid API key. API keys can be provisioned via the GRVT UI.

# These are the variables you will need to set manually
GRVT_API_KEY="<insert_key_here>"
GRVT_SUB_ACCOUNT_ID="<insert_sub_account_id_here>"

Then, choose the environment you want to authenticate against.

# dev
GRVT_AUTH_ENDPOINT="https://edge.dev.gravitymarkets.io/auth/api_key/login"
# staging
GRVT_AUTH_ENDPOINT="https://edge.staging.gravitymarkets.io/auth/api_key/login"
# testnet
GRVT_AUTH_ENDPOINT="https://edge.testnet.grvt.io/auth/api_key/login"
# prod
GRVT_AUTH_ENDPOINT="https://edge.grvt.io/auth/api_key/login"

Now, let’s authenticate and retrieve both the session cookie and the X-Grvt-Account-Id header value that you’ll need to access any endpoints requiring authentication.

echo $GRVT_API_KEY
echo $GRVT_SUB_ACCOUNT_ID
echo $GRVT_AUTH_ENDPOINT

RESPONSE=$(
    curl $GRVT_AUTH_ENDPOINT \
        -H 'Content-Type: application/json' \
        -H 'Cookie: rm=true;' \
        -d '{"api_key": "'$GRVT_API_KEY'"}' \
        -s -i
)

GRVT_COOKIE=$(echo "$RESPONSE" | grep -i 'set-cookie:' | grep -o 'gravity=[^;]*')
GRVT_ACCOUNT_ID=$(echo "$RESPONSE" | grep 'x-grvt-account-id:' | awk '{print $2}' | tr -d '\r')

echo "$GRVT_COOKIE"
echo "$GRVT_ACCOUNT_ID"

The above section is inlined at every authenticated RPC & WS.

Follow the instructions to authenticate using your API Key.

Step 7: API Docs (Try It Out)

At every part of our API Docs, there's a working example you may use to test things out. You should be all set now! But don't hesitate to contact our team if you need any further help!

Try It Out!

Step 8: Order Creation

This is the most frequently asked question.

Python SDK

We have a Python SDK available for usage. (link)

pip install grvt-pysdk

Step-by-Step Guide

For specific information on how to sign and create an order, here's a step-by-step guide, using our Python SDK:

Chain IDs

Network Ethereum L1 Chain ID GRVT L2 Chain ID
Sepolia (Dev) 11155111 327
Sepolia (Stg) 11155111 327
Sepolia (Testnet) 11155111 326
Mainnet 1 325