Skip to Content
API Endpoints

Morpher Trading API

Welcome to the Morpher Trading Platform API documentation. Our API provides access to market data, user portfolios, trading positions, and more via tRPC endpoints.

The base URL for all API endpoints is: https://api.morpher.com/v2

API Usage

All query endpoints are accessible using a tRPC client. You can use the provided type definitions and the @trpc/client package to interact with the API programmatically. See the endpoint examples below for usage patterns.

The All query endpoints are accessible using a tRPC client. You can use the provided type definitions and the @trpc/client package to interact with the API programmatically. See the endpoint examples below for usage patterns. type definition is available at: https://github.com/Morpher-io/morpher-trading-sdk/blob/master/src/v2.router.d.ts 

See the tRPC documentation for mor information: https://trpc.io/docs/client/vanilla 

All query endpoints can also be accessed via HTTP GET requests. The input parameters should be provided as a URL-encoded JSON object in the input query parameter.

For example, to call the getMarketList endpoint with the parameter { "type": "stock" }, you would make a GET request to: https://api.morpher.com/v2/getMarketList?input=%7B%22type%22%3A%22stock%22%7D


Endpoints

getExchangeRates

Fetch current USD exchange rates for all supported tokens (MPH/ETH/USDC).

URL: https://api.morpher.com/v2/getExchangeRates

Method: GET

Input Parameters: None.

Output Type:

{ data: { mph_price: string; eth_price: string; usdc_price: string; } }

Example Output:

{ "data": { "mph_price": "0.015988", "eth_price": "3840.63", "usdc_price": "0.9998" } }

Example Request:


getMarketList

Fetch a list of supported markets for a given market type.

URL: https://api.morpher.com/v2/getMarketList

Method: GET

Input Parameters:

  • market_id (optional, string): Fetch a single market by its ID.
  • type (optional, string): Filter markets by type. Enum: 'stock', 'crypto', 'commodity', 'forex', 'index', 'unique', 'prediction', 'f1', 'mlb', 'position'.
  • cursor (optional, number): The starting point for pagination.

Output Type:

{ markets: { [market: string]: { market_id: string; name: string; type: string; symbol: string; open: number; high: number; low: number; close: number; change_percent: number; is_paused: boolean; pause_reason?: string; volume?: number; spread?: number; change?: number; timestamp?: number; exchange: string; status: string; nextStatus?: string; nextStatusTimestamp?: number; exchangeTimezone: string; exchangeOpen: string; exchangeClose: string; market_delay?: number; sector?: string; limit_direction?: string; max_leverage?: number; min_position_age?: number; country?: string; market_cap?: number; logo_image?: number; }; }; nextCursor: number | null; }

Example Output:

{ "markets": { "STOCK_AAPL": { "market_id": "STOCK_AAPL", "name": "Apple Inc.", "type": "stock", "symbol": "AAPL", "open": 150.00, "high": 152.00, "low": 149.50, "close": 151.80, "change_percent": 1.2, "is_paused": false, "exchange": "NASDAQ", "status": "open", "exchangeTimezone": "America/New_York", "exchangeOpen": "09:30", "exchangeClose": "16:00" } }, "nextCursor": 1 }

Example Request (fetch stock markets):


getMarketData

Fetch market detail data and history data points for a given market. This is normally used when a market is selected or market details are required.

URL: https://api.morpher.com/v2/getMarketData

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • market_id (string): A valid market ID.

Output Type:

{ market_id: string; name: string; type: string; symbol: string; open: number; high: number; low: number; close: number; change_percent: number; is_paused: boolean; pause_reason?: string; volume?: number; spread?: number; change?: number; timestamp?: number; exchange: string; status: string; nextStatus?: string; nextStatusTimestamp?: number; exchangeTimezone: string; exchangeOpen: string; exchangeClose: string; market_delay?: number; sector?: string; limit_direction?: string; max_leverage?: number; min_position_age?: number; country?: string; market_cap?: number; logo_image?: number; pending_order_id?: string; position_id?: string; data_minutely?: [number, number, number, number, number][]; data_hourly?: [number, number, number, number, number][]; data_daily?: [number, number, number, number, number][]; }

Example Output:

{ "market_id": "STOCK_AAPL", "name": "Apple Inc.", "type": "stock", "symbol": "AAPL", "open": 150.00, "high": 152.00, "low": 149.50, "close": 151.80, "change_percent": 1.2, "is_paused": false, "exchange": "NASDAQ", "status": "open", "exchangeTimezone": "America/New_York", "exchangeOpen": "09:30", "exchangeClose": "16:00", "pending_order_id": null, "position_id": "pos_123", "data_daily": [ [1672531200000, 150.00, 152.00, 149.50, 151.80] ] }

Example Request:


getOrders

Fetch the order history for a given Ethereum address.

URL: https://api.morpher.com/v2/getOrders

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • market_id (optional, string): Filter orders by market ID.
  • order_id (optional, string): Fetch a single order by its ID.
  • tx_hash (optional, string): Fetch an order by its transaction hash.

Output Type:

Array<{ id: string; position_id?: string; eth_address: string; market_id?: string; direction: string; status: string; type: string; created_at: number; oracle_called_at?: number; completed_at?: number; tx_hash?: string; callback_hash?: string; price?: string; shares?: string; leverage?: string; spread?: string; liquidation_timestamp?: number; token_amount?: string; price_above?: string; price_below?: string; good_from?: string; good_until?: string; open_mph_token_amount?: string; close_shares_amount?: string; mph_price?: string; unadjusted_price?: string; chain_id?: number; }>

Example Output:

[ { "id": "order_123", "position_id": "pos_123", "eth_address": "0x...", "market_id": "STOCK_AAPL", "direction": "Long", "status": "Completed", "type": "Market", "created_at": 1672531200, "price": "151.00", "shares": "10", "leverage": "1" } ]

Example Request:


getPortfolio

Fetch the portfolio summary for a given Ethereum address. The portfolio is created once the eth address “signs up” or first trades.

URL: https://api.morpher.com/v2/getPortfolio

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.

Output Type:

{ user_id: string; eth_address: string; email: string; timestamp: number; status: "email" | "airdrop" | "kyc" | "confirmed" | "email updated" | "migrated" | "migrating"; chain_id: number; current_value: string; // Corresponds to bigint cash_balance: string; // Corresponds to bigint eth_balance: string; // Corresponds to bigint tradeable_balance: string; // Corresponds to bigint locked_rewards: string; // Corresponds to bigint transferable_balance: string; // Corresponds to bigint usdc_balance: string; position_count: number; }

Example Output:

{ "user_id": "user_abc", "eth_address": "0x...", "email": "user@example.com", "timestamp": 1672531200, "status": "confirmed", "chain_id": 1, "current_value": "1000000000000000000000", "cash_balance": "500000000000000000000", "eth_balance": "1000000000000000000", "tradeable_balance": "500000000000000000000", "locked_rewards": "0", "transferable_balance": "500000000000000000000", "usdc_balance": "500.00", "position_count": 1 }

Example Request:


getPositions

Fetch a list of open positions and details for a given Ethereum address.

URL: https://api.morpher.com/v2/getPositions

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • market_id (optional, string): Filter positions by market ID.
  • position_id (optional, string): Fetch a single position by its ID.

Output Type:

Array<{ id: string; eth_address: string; market_id: string; direction: string; average_price: string; average_spread: string; average_leverage: string; long_shares: string; short_shares: string; liquidation_price?: string; liquidation_timestamp?: number; timestamp?: number; created_at?: number; chain_id?: number; value?: string; total_return?: string; total_return_percent?: string; total_interest?: string; logo_image?: string; name?: string; symbol?: string; }>

Example Output:

[ { "id": "pos_123", "eth_address": "0x...", "market_id": "STOCK_AAPL", "direction": "Long", "average_price": "150.00", "average_spread": "0.01", "average_leverage": "1", "long_shares": "10", "short_shares": "0", "value": "1518.00", "total_return": "18.00", "total_return_percent": "1.2" } ]

Example Request:


getReturns

Fetch the returns history for a given Ethereum address. Fetches history for the last day, week, month, or 90 days as specified in the type parameter. Defaults to day (‘d’).

URL: https://api.morpher.com/v2/getReturns

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • type (optional, string): The time frame for the returns history. Enum: 'd', 'w', 'm', 'y'.

Output Type:

Array<{ timestamp: number; cash: number; stake: number; positions: number; total: number; returns: number; }> | null

Example Output:

[ { "timestamp": 1672531200, "cash": 500, "stake": 0, "positions": 1518, "total": 2018, "returns": 18 } ]

Example Request:


getPositionValue

Get the current value of the given position to be validated when the user creates an open or a close order. Also checks market status and current position to make sure the trade should be executable.

URL: https://api.morpher.com/v2/getPositionValue

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • market_id (string): A valid market ID.

Output Type:

{ id: string; eth_address: string; market_id: string; direction: string; average_price: string; average_spread: string; average_leverage: string; long_shares: string; short_shares: string; liquidation_price?: string; liquidation_timestamp?: number; timestamp?: number; created_at?: number; chain_id?: number; value?: string; total_return?: string; total_return_percent?: string; total_interest?: string; logo_image?: string; name?: string; symbol?: string; } | undefined

Example Output:

{ "id": "pos_123", "eth_address": "0x...", "market_id": "STOCK_AAPL", "direction": "Long", "average_price": "150.00", "average_spread": "0.01", "average_leverage": "1", "long_shares": "10", "short_shares": "0", "value": "1518.00", "total_return": "18.00", "total_return_percent": "1.2" }

Example Request:


getPositionSplitValue

Get the market splits for a position. This is used to display the correct opening price and position history for a position that had market splits after opening.

URL: https://api.morpher.com/v2/getPositionSplitValue

Method: GET

Input Parameters:

  • eth_address (string): A valid Ethereum address.
  • market_id (string): A valid market ID.
  • price_above (string): The upper price bound.
  • price_below (string): The lower price bound.

Output Type:

{ eth_address: `0x${string}`; market_id: string; price_above: string; price_below: string; price_multiplier: number; splits: any[]; }

Example Output:

{ "eth_address": "0x...", "market_id": "STOCK_TSLA", "price_above": "300", "price_below": "200", "price_multiplier": 1, "splits": [] }

Example Request:


getConfig

Get the current addresses for the tokens and relevant contracts from the backend. Also fetches the paymaster and chain info. This provides everything required to execute trades.

URL: https://api.morpher.com/v2/getConfig

Method: GET

Input Parameters: None.

Output Type:

{ chain_id: number; tokenAddress: `0x${string}`; usdcAddress: `0x${string}`; stateAddress: `0x${string}`; oracleAddress: `0x${string}`; bundler: string; paymaster: string; }

Example Output:

{ "chain_id": 8453, "tokenAddress": "0x...", "usdcAddress": "0x...", "stateAddress": "0x...", "oracleAddress": "0x...", "bundler": "https://bundler.example.com", "paymaster": "https://paymaster.example.com" }

Example Request:


WebSocket Subscriptions

The API also provides real-time data through WebSocket subscriptions. The base URL for WebSocket connections is wss://api.morpher.com/graphql.

marketDataV2

This websocket returns delayed and rate limited market ticks for a specified market.

These are graphql based subscriptions and can be accessed directly using graphql-ws for via the apollo client.

Subscription Query:

subscription marketDataV2($market_id: String) { marketDataV2(market_id: $market_id) }

Variables:

  • market_id (string): A valid market ID (e.g., 'STOCK_AAPL').

Example Usage with graphql-ws:

import { createClient } from "graphql-ws"; const client = createClient({ url: "wss://api.morpher.com/graphql", retryAttempts: Infinity, shouldRetry: () => true, keepAlive: 10000, }); const market_id = "STOCK_AAPL"; // Example market ID const unsubscribe = client.subscribe( { query: `subscription marketDataV2($market_id: String) { marketDataV2(market_id: $market_id) }`, variables: { market_id }, }, { next: (data) => { console.log("Market update:", data?.data?.marketDataV2); // Handle market data update }, error: (error) => { console.error("Subscription error:", error); }, complete: () => { console.log("Subscription complete."); }, } ); // To stop listening for updates, call the unsubscribe function: // unsubscribe();

orderExecutionV2

This websocket returns order execution data for a specified eth address.

Subscription Query:

subscription orderExecutionV2($eth_address: String) { orderExecutionV2(eth_address: $eth_address) }

Variables:

  • eth_address (string): A valid Ethereum address (e.g., '0x...').

Example Usage with graphql-ws:

import { createClient } from "graphql-ws"; const client = createClient({ url: "wss://api.morpher.com/graphql", retryAttempts: Infinity, shouldRetry: () => true, keepAlive: 10000, }); const eth_address = "0x..."; // Example Ethereum address const unsubscribe = client.subscribe( { query: `subscription orderExecutionV2($eth_address: String) { orderExecutionV2(eth_address: $eth_address) }`, variables: { eth_address }, }, { next: (data) => { console.log("Order update:", data?.data?.orderExecutionV2); // Handle order execution data update }, error: (error) => { console.error("Subscription error:", error); }, complete: () => { console.log("Subscription complete."); }, } ); // To stop listening for updates, call the unsubscribe function: // unsubscribe();