Bybit

CryptoExchangeAPIs.Bybit.BybitClientType
BybitClient <: AbstractAPIsClient

Client info.

Required fields

  • base_url::String: Base URL for the client.

Optional fields

  • public_key::String: Public key for authentication.
  • secret_key::String: Secret key for authentication.
  • interface::String: Interface for the client.
  • proxy::String: Proxy information for the client.
  • account_name::String: Account name associated with the client.
  • description::String: Description of the client.
source
CryptoExchangeAPIs.Bybit.BybitAPIErrorType
BybitAPIError{T} <: AbstractAPIsError

Exception thrown when an API method fails with code T.

Required fields

  • retCode::Int64: Error code.
  • retMsg::String: Error message.
  • result::Dict{String,Any}: Error result data.
  • retExtInfo::Dict{String,Any}: Extended error information.
  • time::NanoDate: Error timestamp (ms).
source
CryptoExchangeAPIs.Bybit.ListType
List{D} <: AbstractAPIsData

Required fields

  • list::Vector{D}: Result values.

Optional fields

  • nextPageCursor::String: Pagination cursor.
  • category::String: Product type
source
CryptoExchangeAPIs.Bybit.DataType
Data{D} <: AbstractAPIsData

Required fields

  • retCode::Int64: Return code.
  • retMsg::String: Return msg.
  • result::D: Request result data.
  • retExtInfo::Dict{String,Any}: Request extended information.
  • time::NanoDate: Current timestamp (ms).
source

Common

CryptoExchangeAPIs.Bybit.Common.Instrument.instrumentFunction
instrument(client::BybitClient, query::InstrumentQuery)
instrument(client::BybitClient = Bybit.Common.public_client; kw...)

Query for the instrument specification of online trading pairs.

GET /v5/market/instruments-info

Parameters:

ParameterTypeRequiredDescription
categoryProductTypetruespot linear inverse option
symbolStringfalse
statusStatusFilterfalsePreLaunch Trading Delivering Closed
baseCoinStringfalse
limitStringfalse
сгкыщкStringfalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Common.instrument(;
    category = Bybit.Common.Instrument.spot
)

to_pretty_json(result.result)

Result:


{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "list":[
      {
        "symbol":"BTCUSDT",
        "baseCoin":"BTC",
        "quoteCoin":"USDT",
        "innovation":false,
        "status":"Trading",
        "marginTrading":"utaOnly",
        "lotSizeFilter":{
          "basePrecision":1.0e-6,
          "quotePrecision":1.0e-8,
          "minOrderQty":4.8e-5,
          "maxOrderQty":71.73956243,
          "minOrderAmt":1.0,
          "maxOrderAmt":4.0e6
        },
        "priceFilter":{
          "tickSize":0.01
        },
        "riskParameters":{
          "limitParameter":0.03,
          "marketParameter":0.03
        }
      },
    ...
  ]
}
source

Spot

CryptoExchangeAPIs.Bybit.Spot.Candle.candleFunction
candle(client::BybitClient, query::CandleQuery)
candle(client::BybitClient = Bybit.Spot.public_client; kw...)

GET /v5/market/kline

Parameters:

ParameterTypeRequiredDescription
categoryCategorytrueSPOT LINEAR INVERSE
symbolStringtrue
intervalTimeIntervaltruem1 m3 m5 m15 m30 h1 h2 h4 h6 h12 d1 w1 M1
endTimeDateTimefalse
limitInt64false
startTimeDateTimefalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Spot.candle(;
    category = Bybit.Spot.Candle.SPOT,
    symbol = "ADAUSDT",
    interval = Bybit.Spot.Candle.M1,
)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "list":[
      {
        "start":"2025-01-01T00:00:00",
        "open":0.8451,
        "high":1.1519,
        "low":0.8382,
        "close":0.9103,
        "volume":6.6700225827e8,
        "turnover":6.724810699166e8
      },
      ...
    ],
    "nextPageCursor":null,
    "category":"spot"
  },
  "retExtInfo":{},
  "time":"2025-01-13T11:19:18.851000064"
}
source
CryptoExchangeAPIs.Bybit.Spot.CoinInfo.coin_infoFunction
coin_info(client::BybitClient, query::CoinInfoQuery)
coin_info(client::BybitClient; kw...)

Query Coin Information.

GET /v5/asset/coin/query-info

Parameters:

ParameterTypeRequiredDescription
coinStringfalse
api_keyStringfalse
recv_windowInt64falseDefault: 5000
signatureStringfalse
timestampDateTimefalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

bybit_client = BybitClient(;
    base_url = "https://api.bybit.com",
    public_key = ENV["BYBIT_PUBLIC_KEY"],
    secret_key = ENV["BYBIT_SECRET_KEY"],
)

result = Bybit.Spot.coin_info(bybit_client)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"",
  "result":{
    "rows":[
      {
        "chains":[
          {
            "chain":"ETH",
            "chainDeposit":1,
            "chainType":"ERC20",
            "chainWithdraw":1,
            "confirmation":6,
            "depositMin":0.0,
            "minAccuracy":8,
            "withdrawFee":3.0,
            "withdrawMin":3.0,
            "withdrawPercentageFee":0.0 
          }
        ],
        "coin":"AGLD",
        "name":"AGLD",
        "remainAmount":256400
      },
      ...
    ],
    "nextPageCursor":null
  },
  "retExtInfo":{},
  "time":"2024-03-27T14:22:12.088"
}
source
CryptoExchangeAPIs.Bybit.Spot.Deposit.depositFunction
deposit(client::BybitClient, query::DepositQuery)
deposit(client::BybitClient; kw...)

Query Deposit Records.

GET /v5/asset/deposit/query-record

Parameters:

ParameterTypeRequiredDescription
coinStringfalse
cursorStringfalse
endTimeDateTimefalse
limitInt64falseDefault: 50, Max: 50
startTimeDateTimefalse
api_keyStringfalse
recv_windowInt64falseDefault: 5000
signatureStringfalse
timestampDateTimefalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

bybit_client = BybitClient(;
    base_url = "https://api.bybit.com",
    public_key = ENV["BYBIT_PUBLIC_KEY"],
    secret_key = ENV["BYBIT_SECRET_KEY"],
)

result = Bybit.Spot.deposit(bybit_client)

to_pretty_json(result.result)

Result:

{
    "retCode": 0,
    "retMsg": "success",
    "result": {
        "rows": [
            {
                "coin": "USDT",
                "chain": "ETH",
                "amount": "10000",
                "txID": "1234567890",
                "status": 3,
                "toAddress": "xxxxxxxxxxx",
                "tag": "",
                "depositFee": "",
                "successAt": "2024-02-27T14:22:12.000",
                "confirmations": "10000",
                "txIndex": "",
                "batchReleaseLimit":null,
                "blockHash": "",
            },
            {
                "coin": "USDT",
                "chain": "ETH",
                "amount": "10000",
                "txID": "01234567890",
                "status": 3,
                "toAddress": "xxxxxxxxxxx",
                "tag": "",
                "depositFee": "",
                "successAt": "2023-12-15T12:03:40.000",
                "confirmations": "10000",
                "txIndex": "",
                "batchReleaseLimit":null,
                "blockHash": "",
            }
        ],
        "nextPageCursor": "X78...x89"
    },
    "retExtInfo": {},
    "time": "2024-03-27T14:22:12.088"
}
source
CryptoExchangeAPIs.Bybit.Spot.OrderBook.order_bookFunction
order_book(client::BybitClient, query::OrderBookQuery)
order_book(client::BybitClient = Bybit.Spot.public_client; kw...)

GET /v5/market/orderbook

Parameters:

ParameterTypeRequiredDescription
categoryCategorytrueSPOT LINEAR INVERSE OPTION
symbolStringtrue
limitInt64false

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Spot.order_book(;
    category = Bybit.Spot.OrderBook.SPOT,
    symbol = "ADAUSDT",
)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "s":"ADAUSDT",
    "a":[
      {
        "price":0.9064,
        "size":96.0
      }
      ...
    ],
    "b":[
      {
        "price":0.9062,
        "size":1951.28
      }
      ...
    ],
    "ts":"2025-01-13T11:35:23.236999936"
  },
  "retExtInfo":{},
  "time":"2025-01-13T11:35:23.382000128"
}
source
CryptoExchangeAPIs.Bybit.Spot.SymbolInfo.symbol_infoFunction
symbol_info(client::BybitClient, query::SymbolInfoQuery)
symbol_info(client::BybitClient = Bybit.Spot.public_client; kw...)

Query for the instrument specification of online trading pairs.

GET /v5/market/instruments-info

Parameters:

ParameterTypeRequiredDescription
categoryCategorytrueSPOT LINEAR INVERSE OPTION
symbolStringtrue
statusStringtrue
baseCoinStringtrue
limitInt64false
cursorStringtrue

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Spot.symbol_info(;
    category = Bybit.Spot.SymbolInfo.SPOT,
    symbol = "BTCUSDT",
)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "list":[
      {
        "symbol":"BTCUSDT",
        "baseCoin":"BTC",
        "quoteCoin":"USDT",
        "innovation":0,
        "status":"Trading",
        "lotSizeFilter":{
          "basePrecision":1.0e-6,
          "quotePrecision":1.0e-8,
          "minOrderQty":4.8e-5,
          "maxOrderQty":83.0,
          "minOrderAmt":1.0,
          "maxOrderAmt":8.0e6
        },
        "priceFilter":{
          "tickSize":0.01
        },
        "riskParameters":{
          "limitParameter":0.02,
          "marketParameter":0.02
        }
      }
    ],
    "nextPageCursor":null,
    "category":"spot"
  },
  "retExtInfo":{},
  "time":"2025-01-13T12:00:59.132"
}
source
CryptoExchangeAPIs.Bybit.Spot.Ticker.tickerFunction
ticker(client::BybitClient, query::TickerQuery)
ticker(client::BybitClient = Bybit.Spot.public_client; kw...)

GET /v5/market/tickers

Parameters:

ParameterTypeRequiredDescription
categoryCategorytrueSPOT LINEAR INVERSE OPTION
symbolStringfalse
baseCoinStringfalse
expDateStringfalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Spot.ticker(;
    category = Bybit.Spot.Ticker.SPOT,
    symbol = "BTCUSDT",
)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "list":[
      {
        "symbol":"BTCUSDT",
        "bid1Price":90977.73,
        "bid1Size":0.033508,
        "ask1Price":90977.74,
        "ask1Size":0.124391,
        "lastPrice":90976.95,
        "prevPrice24h":94379.41,
        "pice24hPcnt":null,
        "highPrice24h":95950.05,
        "lowPrice24h":90547.11,
        "turnover24h":2.838946290225581e9,
        "volume24h":30219.056193,
        "usdIndexPrice":90893.782055
      }
    ],
    "nextPageCursor":null,
    "category":"spot"
  },
  "retExtInfo":{},
  "time":"2025-01-13T12:14:58.473999872"
}
source
CryptoExchangeAPIs.Bybit.Spot.TradeHistory.trade_historyFunction
trade_history(client::BybitClient, query::TradeHistoryQuery)
trade_history(client::BybitClient; kw...)

Query users' execution records.

GET /v5/execution/list

Parameters:

ParameterTypeRequiredDescription
categoryStringtrue
symbolStringfalse
orderIdStringfalse
orderLinkIdStringfalse
baseCoinStringfalse
endTimeDateTimefalse
limitInt64falseDefault: 50, Max: 100
startTimeDateTimefalse
execTypeStringfalse
cursorStringfalse
api_keyStringfalse
recv_windowInt64falseDefault: 5000
signatureStringfalse
timestampDateTimefalse

Code samples:

using Serde
using CryptoExchangeAPIs.Bybit

bybit_client = BybitClient(;
    base_url = "https://api.bybit.com",
    public_key = ENV["BYBIT_PUBLIC_KEY"],
    secret_key = ENV["BYBIT_SECRET_KEY"],
)

result = Bybit.Spot.trade_history(
    bybit_client;
    category = Bybit.Spot.TradeHistory.LINEAR,
    limit = 1,
)

to_pretty_json(result.result)

Result:

{
  "retCode":0,
  "retMsg":"OK",
  "result":{
    "list":[
      {
        "symbol":"ETHPERP",
        "orderType":"Market",
        "underlyingPrice":nothing,
        "orderLinkId":nothing,
        "side":"Buy",
        "indexPrice":nothing,
        "orderId":"8c065341-7b52-4ca9-ac2c-37e31ac55c94",
        "stopOrderType":"UNKNOWN",
        "leavesQty":0.0,
        "execTime":"2022-12-29T02:58:42.428999936",
        "feeCurrency":nothing,
        "isMaker":false,
        "execFee":0.071409,
        "feeRate":0.0006,
        "execId":"e0cbe81d-0f18-5866-9415-cf319b5dab3b",
        "tradeIv":nothing,
        "blockTradeId":nothing,
        "markPrice":1183.54,
        "execPrice":1190.15,
        "markIv":nothing,
        "orderQty":0.1,
        "orderPrice":1236.9,
        "execValue":119.015,
        "execType":"Trade",
        "execQty":0.1,
        "closedSize":nothing,
        "seq":4688002127
      }
    ],
    "nextPageCursor":"132766%3A2%2C132766%3A2",
    "category":"linear",
  },
  "retExtInfo":{},
  "time":"2022-12-29T03:15:54.510"
}
source