Skip to content

v1.3.5

Choose a tag to compare

@tigusigalpa tigusigalpa released this 25 Apr 01:01
· 17 commits to main since this release

v1.3.5 — TradFi Support

What's New

This release adds a dedicated TradFi module (BybitTradFi) for trading traditional financial instruments — gold, silver, forex pairs, stock CFDs, and indices — all available on Bybit as linear perpetuals through the standard V5 API.


New Class: BybitTradFi

Instantiate via composition: $tradfi = new BybitTradFi($client)

Market Data

  • getInstruments — fetch all available TradFi instruments; accepts optional asset class filter: metal, forex, stock, index, commodity
  • getTicker — get a ticker snapshot for a single TradFi symbol
  • getTickers — get tickers for a list of symbols (or all linear instruments when empty)
  • getMetalsTickers — shortcut for gold (XAUUSD), silver (XAGUSD), and platinum (XPTUSD)
  • getForexTickers — shortcut for major forex pairs: EURUSD, GBPUSD, USDJPY, and more
  • getStockTickers — shortcut for US stock CFDs: AAPL, TSLA, NVDA, META, and more
  • getIndexTickers — shortcut for major indices: US500USD, US100USD, DE40USD, and more
  • getKline — candlestick data; supports all V5 intervals (1, 5, 15, 60, D, W, etc.)
  • getOrderbook — order book depth for a TradFi symbol; configurable depth up to 200
  • getSwapFee — overnight swap/financing fee info via instruments-info endpoint

Trading

  • placeOrder — place a limit or market order; supports takeProfit, stopLoss, reduceOnly, positionIdx, and orderLinkId
  • closePosition — close an open position at market price with reduceOnly=true
  • setLeverage — set leverage for a TradFi symbol
  • cancelOrder — cancel by orderId or orderLinkId
  • getOpenOrders — query open/untriggered TradFi orders; optionally filtered by symbol
  • getOrderHistory — order history with configurable limit
  • getTradeHistory — execution history for TradFi instruments
  • getPositions — list open positions; optionally filtered by symbol
  • getFeeRate — trading fee rate for a TradFi symbol or all linear instruments

Utilities

  • isTradFiSymbol — static helper to detect whether a symbol is a TradFi instrument (metal, forex, or index) vs. a crypto perpetual
  • Predefined symbol constants: METALS, FOREX_MAJORS, FOREX_MINORS, US_STOCKS, INDICES

New Example

  • examples/13-tradfi.php — demonstrates market data fetching, kline and orderbook retrieval, open position inspection, order placement with TP/SL, order cancellation, and isTradFiSymbol detection across forex, metals, and index symbols

Notes

  • All methods use category=linear internally — no new API endpoints required beyond the standard V5 REST API
  • BybitTradFi uses composition, not inheritance — pass an existing BybitClient instance to the constructor
  • TradFi instruments are subject to market hours (unlike 24/7 crypto); outside trading sessions the API may return empty order books or stale prices
  • Swap fees apply when holding TradFi positions past daily market close — use getSwapFee to check the rate before sizing a position
  • Fully compatible with PHP 7.4+ — no str_starts_with / str_ends_with dependencies