With Bybit API [1] it is possible to get public data (price, volume, last trading records) and also place own orders using API Key. All the next examples do not need API Key, because open public data is used here.
First, install jq for read json data and search in it to get only fields we need.
apt install jq
Bitcoin price in Spot trading from Bybit API. Ticker BTCUSDT info
This price is from latest finished orders.
echo BTCUSDT `curl -s 'https://api.bybit.com/spot/quote/v1/ticker/price?symbol=BTCUSDT' | jq -r '.result.price'`
BTCUSDT 23203.03
Bitcoin price from order book: asks and bids
This price is that people are ready to buy or sell.
R='\033[0;31m' G='\033[0;32m' N='\033[0m' d=`curl -s 'https://api.bybit.com/spot/quote/v1/depth?symbol=BTCUSDT&limit=1' | jq -r '.result'`; echo -e BTCUSDT ${R}Sell${N}: `echo $d | jq -r '.asks[][0]'` "\n"BTCUSDT $G Buy${N}: `echo $d | jq -r '.bids[][0]'`
BTCUSDT Sell: 23211.11
BTCUSDT Buy: 23211.1
All available trading pairs
curl -s 'https://api.bybit.com/spot/v1/symbols' | jq -r '.result[].name'
BTCUSDT
ETHUSDT
XRPUSDT
...
There are 266 pairs now.
Bitcoin Short price in Spot trading: BTC3SUSDT
echo BTC3SUSDT `curl -s 'https://api.bybit.com/spot/quote/v1/ticker/price?symbol=BTC3SUSDT' | jq -r '.result.price'`
BTC3SUSDT 16.566
There are also "Inverse Perpetual", "USDT Perpetual", "Inverse Futures" markets and their API.
curl cannot verify certificates on Android
Also, I had a problem getting data via HTTPS on Android with curl:
curl 'https://api-testnet.bybit.com/public/linear/recent-trading-records?symbol=BTCUSDT&limit=1'
curl: (77) error setting certificate verify locations:
CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
First, I used option -k for curl does not check certificates. But then I fixed this with [2], need to install ca-certificates:
apt install ca-certificates
Links
[1] Bybit API https://bybit-exchange.github.io/docs/inverse/#t-querysymbol
[2] Curl error 77 problem with the SSL CA cert https://bobcares.com/blog/curl-error-77-problem-with-the-ssl-ca-cert/