LogoLogo
  • Introduction
    • 🔴Welcome to IntentX
    • 💢The Omnichain DEX
    • ⚡User Experience Focus
    • 🌐The Meta Front-End
  • On-Chain Derivatives Overview
    • ❓What Problem Does IntentX Solve?
    • 📊Current On-Chain Derivatives Landscape
    • 💡IntentX Solution & Architecture Overview
    • ✅Comparison and Advantages of IntentX
  • IntentX Platform
    • 📈Trading on IntentX
      • 📖Trading Basics
      • 🏫Trading Tutorials
        • 🏫Web3 Wallet
        • 🏫Account Abstracted Wallet
      • 🌡️Liquidations, Margin Management (CVA), and Account Health
      • 📊Instant 1-Click Trading
      • 🛑Take Profit and Stop Loss
      • 💵Collateral & Cross-Margin Accounts
      • 💸Understanding Funding Rates
      • 💰Pricing Data and the Role of Oracles
      • ↕️Unrealized Profit and Loss (uPNL)
      • 📏Open Interest (OI) and Market Activity
      • 🔐Withdrawal Process and Security Measures
      • 📈Advanced Charts by TradingView
    • 🔢Pair List
    • 🌀IntentX Solver Network
      • 🌀Example Solver Order Flow
    • 🫂Referral Program
    • 📱Mobile and Progressive Web App
  • Trading API
    • Introduction
    • Rest API V1
    • Typescript SDK
      • Examples
        • Opening Positions
        • Closing Positions
        • Cancel Positions
        • List Subaccounts
        • List Positions
        • Private Key Authentication
        • Enable Instant Actions
  • Tokenomics
    • 🪙INTX Token and xINTX Staking
    • 🔄Trade & Earn xINTX
    • 📅Token Allocation and Release Schedule
  • Technical Docs (WIP)
    • ⚙️Infrastructure Overview
      • 🔩Technical Docs
      • 🌐Sample Solver Docs
  • Additional Information
    • ❓FAQ
    • 🌐Official Links
    • 📃Terms & Conditions
    • 🔐Security & Audits
    • 🌟Brand & Media Assets
    • 💾Contracts
Powered by GitBook
On this page
  • Introduction
  • JWT Authentication
  1. Trading API

Rest API V1

PreviousIntroductionNextTypescript SDK

Last updated 1 month ago

Introduction

The trading API uses an API Key based authentication system to operate with accounts.

When it comes to managing your account API keys and other actions associated with your wallet, the API uses a JWT based system associated with your evm wallet.

The API Keys works with a permission based system. In the trading API, you can delegate access to one of your subaccounts to an specific API key with an associated scope

For the API spec, use

JWT Authentication

Certain components of the trading API require the user to login with their wallet to manage API keys and account permissions.

To authenticate with your wallet in the API and get your JWT auth to be able to manage your API keys, the first step is to generate a typed data message.

export function generateIntentXJWTIssueMessage(
  account: Address,
  scopes: AllowedScopes[],
  expiration: AllowedExpiration
): RegisterTypedData {
  const message: RegisterTypedData = {
    domain: {
      name: "IntentX",
      version: "1",
    },
    message: {
      userAddress: account,
      scope: scopes,
      expiration: expiration,
      signatureExpiration: parseInt(((Date.now() + 1000 * 60 * 10) / 1000).toFixed(0)), // 10 minutes from now
    },
    primaryType: "Session",
    types: {
      Session: [
        { name: "userAddress", type: "address" },
        { name: "scope", type: "string[]" },
        { name: "expiration", type: "string" },
      ],
    },
  };

  return message;
}

Then, you'll have to sign with your wallet the generated message.

// Create wallet from private key
const wallet = new ethers.Wallet(privateKey);
const address = wallet.address;
​
// Generate typed data for JWT token
const typedData: RegisterTypedData = generateIntentXJWTIssueMessage(
address as 0x${string},
"frontendAuth", // Required scope for API key management
"30d"
);
​
// Sign typed data
const signature = await wallet.signTypedData(typedData.domain, typedData.types, typedData.message);

Finally, you can interact with the JWT issuer app:

const response = await axios.post<{ token?: string; message?: string }>(
  "https://app-authentication-bb6ukllqqa-ew.a.run.app/register",
  {
    message,
    signature,
  },
  {
    headers: {
      "Content-Type": "application/json",
    },
  }
);

Then, with the 'token' you have got in the response, you will be able to interact with the API keys management in the Trading API.

You are required to use the following header with your generated token

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
https://gw.intentx.io/api