Mayson Monorepo Documentation
    Preparing search index...

    Class GhostExchange

    Ghost exchange implementation for simulated/paper trading

    This exchange doesn't place real orders - instead it:

    1. Fetches real prices from Binance public API (no auth needed)
    2. Simulates order execution at current market prices
    3. Returns fake order data with realistic fill information

    Used for "education" trading mode (ghost trading)

    const ghost = new GhostExchange();
    ghost.initialize({}); // No credentials needed
    ghost.setVirtualBalances([{ asset: "USDT", free: "10000", locked: "0", total: "10000" }]);
    const order = await ghost.marketBuy("BTCUSDT", 100, true);
    // Returns simulated order at real BTC price

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    name: "binance" = ...

    The name of the exchange

    testnet: false

    Whether the exchange is connected to testnet

    Methods

    • Format an asset to a trading symbol

      Parameters

      • asset: string

        The base asset (e.g., "ETH")

      • quoteAsset: string = "USDT"

        The quote asset (default: "USDT")

      Returns string

      Formatted symbol (e.g., "ETHUSDT")

    • Parse a symbol into base and quote assets

      Parameters

      • symbol: string

        The trading pair symbol

      Returns { base: string; quote: string }

      Object with base and quote assets

    • Initialize the ghost exchange (no-op since we don't need credentials)

      Parameters

      Returns void

    • Verify credentials always returns true for ghost exchange

      Returns Promise<boolean>

      Always true

    • Set virtual balances for simulated trading This should be called before executing trades to provide the ghost exchange with the user's current virtual portfolio balances from the database.

      Parameters

      • balances: ExchangeBalance[]

        Array of virtual balances from VirtualPortfolio

      Returns void

    • Clear virtual balances (useful when switching users or resetting)

      Returns void

    • Get account balances from the stored virtual balances

      Parameters

      • Optionalasset: string

        Optional asset to filter by

      Returns Promise<ExchangeBalance[]>

      Virtual balances (must be set via setVirtualBalances first)

    • Get current price for a trading pair from Binance public API

      Parameters

      • symbol: string

        Trading pair symbol (e.g., "BTCUSDT")

      Returns Promise<ExchangePrice>

      Current price information

    • Get all available trading pairs from Binance

      Returns Promise<string[]>

      Array of trading pair symbols

    • Get candlestick/OHLCV data for technical analysis from Binance public API

      Parameters

      • symbol: string

        Trading pair symbol (e.g., "BTCUSDT")

      • interval: KlineInterval

        Candle interval (e.g., "1h", "4h", "1d")

      • limit: number = 200

        Number of candles to fetch (default: 200)

      Returns Promise<Kline[]>

      Array of kline data

    • Get 24-hour ticker statistics from Binance public API

      Parameters

      • symbol: string

        Trading pair symbol (e.g., "BTCUSDT")

      Returns Promise<Ticker24hr>

      24-hour ticker statistics

    • Simulate a market buy order

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to buy

      • quantityIsQuote: boolean = false

        If true, quantity is in quote currency (e.g., USDT)

      Returns Promise<ExchangeOrder>

      Simulated order with real price data

    • Simulate a market sell order

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to sell in base currency

      Returns Promise<ExchangeOrder>

      Simulated order with real price data

    • Simulate a limit buy order (executes immediately at limit price for simplicity)

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to buy

      • price: number

        Limit price

      Returns Promise<ExchangeOrder>

      Simulated order

    • Simulate a limit sell order

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to sell

      • price: number

        Limit price

      Returns Promise<ExchangeOrder>

      Simulated order

    • Simulate a stop loss order

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to sell

      • stopPrice: number

        Stop trigger price

      • OptionallimitPrice: number

        Optional limit price

      Returns Promise<ExchangeOrder>

      Simulated order

    • Simulate a take profit order

      Parameters

      • symbol: string

        Trading pair symbol

      • quantity: number

        Amount to sell

      • price: number

        Take profit trigger price

      • OptionallimitPrice: number

        Optional limit price

      Returns Promise<ExchangeOrder>

      Simulated order

    • Cancel order (always succeeds for ghost exchange)

      Parameters

      • _orderId: string

        Order ID to cancel

      • _symbol: string

        Trading pair symbol

      Returns Promise<boolean>

      Always true

    • Get order - returns a mock filled order

      Parameters

      • orderId: string

        Order ID

      • symbol: string

        Trading pair symbol

      Returns Promise<ExchangeOrder>

      Mock order data

    • Get open orders - always empty for ghost exchange (orders fill instantly)

      Parameters

      • Optional_symbol: string

        Trading pair symbol

      Returns Promise<ExchangeOrder[]>

      Empty array