Skip to content

Full API Reference

Igor Sazonov edited this page Jul 12, 2026 · 1 revision

This page provides complete method signatures for all public classes in the coinglass-php SDK.

CoinGlassClient

Namespace: Tigusigalpa\CoinGlass

The central entry point for the SDK. Holds the configuration and HTTP client, and provides access to all resource groups and the WebSocket client.

Static Factory

Method Description
static make(string $apiKey, array $options = []): self Creates a new client from an API key and optional override array. Recognized keys: base_url, timeout, retry_attempts, retry_delay.

Constructor

public function __construct(
    CoinGlassConfig $config,
    ?ClientInterface $httpClient = null,
    ?RequestFactoryInterface $requestFactory = null,
    ?StreamFactoryInterface $streamFactory = null,
    ?UriFactoryInterface $uriFactory = null,
)

Resource Accessors

Method Return Type Description
futures() FuturesResource Access the Futures resource group.
spot() SpotResource Access the Spot resource group.
options() OptionsResource Access the Options resource group.
etf() EtfResource Access the ETF resource group.
onChain() OnChainResource Access the On-Chain resource group.
indicators() IndicatorsResource Access the Indicators resource group.
websocket(array $options = []) CoinGlassWebSocketClient Access the WebSocket client.

Low-Level Request

Method Description
request(string $path, array $query = []): mixed Sends a GET request and returns the decoded data payload. Throws CoinGlassException on error.

CoinGlassConfig

Namespace: Tigusigalpa\CoinGlass

Immutable configuration object for the REST client.

Constructor Parameters

Parameter Type Default Description
$apiKey string (required) Coinglass API v4 key, sent via the CG-API-KEY header.
$baseUrl string https://open-api-v4.coinglass.com Base URL of the Coinglass API.
$timeout float 15.0 Request timeout in seconds.
$retryAttempts int 3 Number of automatic retries on HTTP 429.
$retryDelay float 1.0 Base delay in seconds for exponential backoff.

Static Factories

Method Description
static fromArray(array $config): self Creates an instance from an associative array. Keys: api_key, base_url, timeout, retry_attempts, retry_delay.
static fromEnv(): self Creates an instance from environment variables: COINGLASS_API_KEY, COINGLASS_BASE_URL, COINGLASS_TIMEOUT, COINGLASS_RETRY_ATTEMPTS, COINGLASS_RETRY_DELAY.

FuturesResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->futures()

Method Parameters HTTP Endpoint
supportedCoins() GET /futures/supported-coins
supportedExchangePairs() ?string $exchange GET /api/futures/supported-exchange-pairs
pairsMarkets() ?string $symbol, ?string $exchange, ?int $limit GET /api/futures/pairs-markets
coinsMarkets() ?string $symbol, ?int $limit GET /api/futures/coins-markets
priceChangeList() GET /futures/price-change-list
priceOhlcHistory() string $symbol, string $interval, ?int $limit, ?int $startTime, ?int $endTime GET /api/price/ohlc-history
openInterestOhlcHistory() string $symbol, string $interval, ?int $limit, ?int $startTime, ?int $endTime GET /api/futures/openInterest/ohlc-history
openInterestAggregatedHistory() string $symbol, string $interval, ?int $limit, ?int $startTime, ?int $endTime GET /api/futures/openInterest/ohlc-aggregated-history
openInterestExchangeList() string $symbol, string $interval, ?int $limit, ?string $exchange GET /api/futures/openInterest/exchange-list
fundingRateOhlcHistory() string $symbol, string $interval, ?int $limit, ?int $startTime, ?int $endTime GET /api/futures/fundingRate/ohlc-history
fundingRateOiWeighted() string $symbol, string $interval, ?int $limit GET /api/futures/fundingRate/oi-weight-ohlc-history
fundingRateExchangeList() string $symbol, ?string $interval, ?int $limit GET /api/futures/fundingRate/exchange-list
fundingRateArbitrage() ?string $symbol, ?int $limit GET /api/futures/fundingRate/arbitrage
longShortAccountRatioHistory() string $symbol, string $interval, ?int $limit, ?string $exchange GET /api/futures/global-long-short-account-ratio/history
topLongShortAccountRatio() string $symbol, string $interval, ?int $limit, ?string $exchange GET /api/futures/top-long-short-account-ratio/history
liquidationHistory() string $symbol, string $pair, string $interval, ?int $limit GET /api/futures/liquidation/history
liquidationAggregatedHistory() string $symbol, string $interval, ?int $limit GET /api/futures/liquidation/aggregated-history
liquidationCoinList() ?string $symbol, ?int $limit GET /api/futures/liquidation/coin-list
liquidationHeatmap() string $model, string $symbol, string $interval, ?int $limit GET /api/futures/liquidation/heatmap/model{1,2,3}
liquidationMap() string $symbol, string $pair, string $interval, ?int $limit GET /api/futures/liquidation/map
orderbookHistory() string $symbol, string $exchange, string $interval, ?int $limit GET /api/futures/orderbook/history
orderbookLargeOrders() string $symbol, string $exchange, ?int $limit GET /api/futures/orderbook/large-limit-order
takerBuySellHistory() string $symbol, string $exchange, string $interval, ?int $limit GET /api/futures/taker-buy-sell-volume/history
whaleBuySellHistory() ?string $symbol, ?int $limit GET /api/hyperliquid/whale-alert

SpotResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->spot()

Method Parameters HTTP Endpoint
supportedCoins() GET /api/spot/supported-coins
coinsMarkets() ?string $symbol, ?int $limit GET /api/spot/coins-markets
pairsMarkets() ?string $symbol, ?string $exchange, ?int $limit GET /api/spot/pairs-markets
priceHistory() string $symbol, string $interval, ?int $limit, ?int $startTime, ?int $endTime GET /api/spot/price/history
orderbookHistory() string $symbol, string $exchange, string $interval, ?int $limit GET /api/spot/orderbook/history
takerBuySellHistory() string $symbol, string $exchange, string $interval, ?int $limit GET /api/spot/taker-buy-sell-volume/history

OptionsResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->options()

Method Parameters HTTP Endpoint
maxPain() string $underlying, ?int $expiry GET /api/option/max-pain
info() string $underlying, ?int $expiry GET /api/option/info
exchangeOiHistory() string $interval, ?int $limit GET /api/option/exchange-oi-history
exchangeVolHistory() string $interval, ?int $limit GET /api/option/exchange-vol-history

EtfResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->etf()

Method Parameters HTTP Endpoint
bitcoinList() GET /api/etf/bitcoin/list
bitcoinFlowHistory() string $interval, ?int $limit GET /api/etf/bitcoin/flow-history
bitcoinNetAssetsHistory() string $interval, ?int $limit GET /api/etf/bitcoin/net-assets/history
ethereumList() GET /api/etf/ethereum/list
ethereumFlowHistory() string $interval, ?int $limit GET /api/etf/ethereum/flow-history
grayscaleHoldings() GET /api/grayscale/holdings-list

OnChainResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->onChain()

Method Parameters HTTP Endpoint
exchangeAssets() GET /api/exchange/assets
exchangeBalanceList() ?string $symbol, ?string $exchange GET /api/exchange/balance/list
exchangeOnChainTransfers() ?string $symbol, ?int $limit GET /api/exchange/chain/tx/list

IndicatorsResource

Namespace: Tigusigalpa\CoinGlass\Resources — Access via $client->indicators()

Method Parameters HTTP Endpoint
fearGreedHistory() ?int $limit GET /api/index/fear-greed-history
rsiList() ?string $symbol, ?string $interval, ?int $limit GET /api/futures/rsi/list
basisHistory() string $symbol, string $interval, ?int $limit GET /api/futures/basis/history
coinbasePremiumIndex() ?int $limit GET /api/coinbase-premium-index
bitcoinRainbowChart() GET /api/index/bitcoin/rainbow-chart
stockToFlow() GET /api/index/stock-flow
stablecoinMarketCap() ?int $limit GET /api/index/stableCoin-marketCap-history

CoinGlassWebSocketClient

Namespace: Tigusigalpa\CoinGlass\WebSocket — Access via $client->websocket()

Method Description
static make(string $apiKey, array $options = []): self Creates a new WebSocket client. Options: base_url, connect_timeout, ping_interval.
connect(): CoinGlassStream Opens a WebSocket connection and performs the RFC 6455 handshake. Throws WebSocketException on failure.

CoinGlassStream

Namespace: Tigusigalpa\CoinGlass\WebSocket — Returned by CoinGlassWebSocketClient::connect()

Method Description
subscribe(string ...$channels): void Subscribes to one or more channels.
unsubscribe(string ...$channels): void Unsubscribes from one or more channels.
subscriptions(): string[] Returns the list of currently subscribed channel names.
read(?float $timeout = null): ?Message Reads one message, blocking for up to $timeout seconds. Returns null on timeout.
listen(callable $onMessage, ?callable $onError = null): void Blocks indefinitely, calling $onMessage for each incoming message.
close(): void Sends a close frame and closes the socket.
isClosed(): bool Returns true if the stream has been closed.

Channels

Namespace: Tigusigalpa\CoinGlass\WebSocket

Static helper class for building WebSocket channel name strings.

Method Channel Format
static liquidationOrders(): string liquidation_orders
static spotTrades(string $exchange, string $symbol, int $minVolumeUsd): string spot_trades@{exchange}_{symbol}@{minVolumeUsd}
static futuresTrades(string $exchange, string $symbol, int $minVolumeUsd): string futures_trades@{exchange}_{symbol}@{minVolumeUsd}
static futuresTicker(string $exchange, string $symbol): string futures_ticker@{exchange}_{symbol}

CoinGlassDto

Namespace: Tigusigalpa\CoinGlass\Dto

Method / Property Description
readonly array $raw The original decoded JSON payload.
static fromArray(array $data): self Creates a DTO from an associative array.
__get(string $name): mixed Dynamic property access for any key in the payload.
__isset(string $name): bool Checks if a key is set in the payload.
get(string $key, mixed $default = null): mixed Gets a value by key with an optional default.
has(string $key): bool Checks if a key exists in the payload.
toArray(): array Returns the raw payload as an associative array.

CoinGlassCollection

Namespace: Tigusigalpa\CoinGlass\Collections

Method Return Type Description
static fromArray(array $data): self self Creates a collection from a list of associative arrays.
all() CoinGlassDto[] Returns all items as a plain PHP array.
first() ?CoinGlassDto Returns the first item, or null if empty.
last() ?CoinGlassDto Returns the last item, or null if empty.
isEmpty() bool Returns true if the collection is empty.
isNotEmpty() bool Returns true if the collection is not empty.
filter(callable $callback) CoinGlassCollection Returns a new collection with items matching the callback.
map(callable $callback) array Returns a plain PHP array of the mapped results.
toArray() array[] Converts the collection to a plain array of associative arrays.
count() int Returns the number of items.

Exceptions

All exceptions are in the Tigusigalpa\CoinGlass\Exceptions namespace.

Class Extends HTTP Status Additional Properties
CoinGlassException RuntimeException
ApiException CoinGlassException Any non-2xx $statusCode, $responseBody, $apiCode
UnauthorizedException ApiException 401
NotFoundException ApiException 404
RateLimitException ApiException 429 $retryAfter (int|null)
WebSocketException CoinGlassException

Clone this wiki locally