Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CryptoExchangeAPIs"
uuid = "5e3d4798-c815-4641-85e1-deed530626d3"
version = "0.32.0"
version = "0.33.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
16 changes: 13 additions & 3 deletions examples/Bybit/Spot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ using CryptoExchangeAPIs
using CryptoExchangeAPIs.Bybit

Bybit.Spot.candle(;
category = Bybit.Spot.Candle.SPOT,
symbol = "ADAUSDT",
interval = Bybit.Spot.Candle.m1,
startTime = DateTime("2022-10-27T08:00:00"),
endTime = DateTime("2022-10-27T08:00:00") + Hour(1),
limit = 4,
)

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

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

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

bybit_client = BybitClient(;
base_url = "https://api.bybit.com",
Expand Down
76 changes: 41 additions & 35 deletions src/Bybit/Spot/API/Candle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,61 @@ using CryptoExchangeAPIs.Bybit
using CryptoExchangeAPIs.Bybit: Data, List, Rows
using CryptoExchangeAPIs: Maybe, APIsRequest

@enum Category SPOT LINEAR INVERSE
@enum TimeInterval m1 m3 m5 m15 m30 h1 h2 h4 h6 h8 h12 d1 d3 w1 M1

Base.@kwdef struct CandleQuery <: BybitPublicQuery
category::Category
symbol::String
interval::TimeInterval
endTime::Maybe{DateTime} = nothing
limit::Maybe{Int64} = nothing
startTime::Maybe{DateTime} = nothing
end

function Serde.ser_type(::Type{<:CandleQuery}, x::Category)::String
x == SPOT && return "spot"
x == LINEAR && return "linear"
x == INVERSE && return "inverse"
end

function Serde.ser_type(::Type{<:CandleQuery}, x::TimeInterval)::String
x == m1 && return "1m"
x == m3 && return "3m"
x == m5 && return "5m"
x == m15 && return "15m"
x == m30 && return "30m"
x == h1 && return "1h"
x == h2 && return "2h"
x == h4 && return "4h"
x == h6 && return "6h"
x == h8 && return "8h"
x == h12 && return "12h"
x == d1 && return "1d"
x == d3 && return "3d"
x == w1 && return "1w"
x == M1 && return "1M"
x == m1 && return "1"
x == m3 && return "3"
x == m5 && return "5"
x == m15 && return "15"
x == m30 && return "30"
x == h1 && return "60"
x == h2 && return "120"
x == h4 && return "240"
x == h6 && return "360"
x == h12 && return "720"
x == d1 && return "D"
x == w1 && return "W"
x == M1 && return "M"
end

struct CandleData <: BybitData
c::Maybe{Float64}
h::Maybe{Float64}
l::Maybe{Float64}
o::Maybe{Float64}
s::Maybe{String}
sn::Maybe{String}
t::Maybe{NanoDate}
v::Maybe{Float64}
start::Maybe{NanoDate}
open::Maybe{Float64}
high::Maybe{Float64}
low::Maybe{Float64}
close::Maybe{Float64}
volume::Maybe{Float64}
turnover::Maybe{Float64}
end

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

[`GET /spot/v3/public/quote/kline`](https://bybit-exchange.github.io/docs/spot/public/kline#http-request)
[`GET /v5/market/kline`](https://bybit-exchange.github.io/docs/v5/market/kline)

## Parameters:

| Parameter | Type | Required | Description |
|:----------|:-------------|:---------|:------------------------------------------------|
| category | Category | true | SPOT LINEAR INVERSE |
| symbol | String | true | |
| interval | TimeInterval | true | m1 m3 m5 m15 m30 h1 h2 h4 h6 h8 h12 d1 d3 w1 M1 |
| endTime | DateTime | false | |
Expand All @@ -73,6 +79,7 @@ using Serde
using CryptoExchangeAPIs.Bybit

result = Bybit.Spot.candle(;
category = Bybit.Spot.Candle.SPOT,
symbol = "ADAUSDT",
interval = Bybit.Spot.Candle.M1,
)
Expand All @@ -89,27 +96,26 @@ to_pretty_json(result.result)
"result":{
"list":[
{
"c":1.97,
"h":2.303,
"l":1.822,
"o":2.105,
"s":"ADAUSDT",
"sn":"ADAUSDT",
"t":"2021-10-01T00:00:00",
"v":2.7565224e6
"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":null
"category":"spot"
},
"retExtInfo":{},
"time":"2024-03-25T18:36:39.372"
"time":"2025-01-13T11:19:18.851000064"
}
```
"""
function candle(client::BybitClient, query::CandleQuery)
return APIsRequest{Data{List{CandleData}}}("GET", "spot/v3/public/quote/kline", query)(client)
return APIsRequest{Data{List{CandleData}}}("GET", "/v5/market/kline", query)(client)
end

function candle(client::BybitClient = Bybit.Spot.public_client; kw...)
Expand Down
7 changes: 4 additions & 3 deletions src/Bybit/Spot/API/CoinInfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ struct Chain <: BybitData
minAccuracy::Int64
withdrawFee::Maybe{Float64}
withdrawMin::Maybe{Float64}
withdrawPercentageFee::Maybe{Float64}
end

struct CoinInfoData <: BybitData
chains::Vector{Chain}
coin::String
name::String
name::Maybe{String}
remainAmount::Maybe{Int64}
end

Expand All @@ -53,7 +54,7 @@ end

Query Coin Information.

[`GET asset/v3/private/coin-info/query`](https://bybit-exchange.github.io/docs/account-asset/coin-info#http-request)
[`GET /v5/asset/coin/query-info`](https://bybit-exchange.github.io/docs/v5/asset/coin-info#http-request)

## Parameters:

Expand Down Expand Up @@ -118,7 +119,7 @@ to_pretty_json(result.result)
```
"""
function coin_info(client::BybitClient, query::CoinInfoQuery)
return APIsRequest{Data{Rows{CoinInfoData}}}("GET", "asset/v3/private/coin-info/query", query)(client)
return APIsRequest{Data{Rows{CoinInfoData}}}("GET", "/v5/asset/coin/query-info", query)(client)
end

function coin_info(client::BybitClient; kw...)
Expand Down
6 changes: 4 additions & 2 deletions src/Bybit/Spot/API/Deposit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ struct DepositData <: BybitData
toAddress::Maybe{String}
txID::Maybe{String}
txIndex::Maybe{Int64}
batchReleaseLimit::Maybe{String}
depositType::Maybe{Int64}
end

function Serde.isempty(::Type{<:DepositData}, x)::Bool
Expand All @@ -49,7 +51,7 @@ end

Query Deposit Records.

[`GET asset/v3/private/deposit/record/query`](https://bybit-exchange.github.io/docs/account-asset/deposit-record)
[`GET /v5/asset/deposit/query-record`](https://bybit-exchange.github.io/docs/v5/asset/deposit/deposit-record)

## Parameters:

Expand Down Expand Up @@ -127,7 +129,7 @@ to_pretty_json(result.result)
```
"""
function deposit(client::BybitClient, query::DepositQuery)
return APIsRequest{Data{Rows{DepositData}}}("GET", "asset/v3/private/deposit/record/query", query)(client)
return APIsRequest{Data{Rows{DepositData}}}("GET", "/v5/asset/deposit/query-record", query)(client)
end

function deposit(client::BybitClient; kw...)
Expand Down
58 changes: 36 additions & 22 deletions src/Bybit/Spot/API/OrderBook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,46 @@ using CryptoExchangeAPIs.Bybit
using CryptoExchangeAPIs.Bybit: Data, List, Rows
using CryptoExchangeAPIs: Maybe, APIsRequest

@enum Category OPTION SPOT LINEAR INVERSE

Base.@kwdef struct OrderBookQuery <: BybitPublicQuery
category::Category
symbol::String
limit::Maybe{Int64} = nothing
end

function Serde.ser_type(::Type{<:OrderBookQuery}, x::Category)::String
x == OPTION && return "option"
x == SPOT && return "spot"
x == LINEAR && return "linear"
x == INVERSE && return "inverse"
end

struct Level <: BybitData
price::Float64
size::Float64
end

struct OrderBookData <: BybitData
asks::Vector{Level}
bids::Vector{Level}
time::NanoDate
s::String
a::Vector{Level}
b::Vector{Level}
ts::NanoDate
end

"""
order_book(client::BybitClient, query::OrderBookQuery)
order_book(client::BybitClient = Bybit.Spot.public_client; kw...)

[`GET /spot/v3/public/quote/depth`](https://bybit-exchange.github.io/docs/spot/public/depth)
[`GET /v5/market/orderbook`](https://bybit-exchange.github.io/docs/v5/market/orderbook)

## Parameters:

| Parameter | Type | Required | Description |
|:----------|:-------|:---------|:------------|
| symbol | String | true | |
| limit | Int64 | false | |
| Parameter | Type | Required | Description |
|:----------|:---------|:---------|:-------------------------- |
| category | Category | true | SPOT LINEAR INVERSE OPTION |
| symbol | String | true | |
| limit | Int64 | false | |

## Code samples:

Expand All @@ -47,6 +59,7 @@ using Serde
using CryptoExchangeAPIs.Bybit

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

Expand All @@ -60,29 +73,30 @@ to_pretty_json(result.result)
"retCode":0,
"retMsg":"OK",
"result":{
"asks":[
"s":"ADAUSDT",
"a":[
{
"price":0.6627,
"size":2144.17
},
...
"price":0.9064,
"size":96.0
}
],
"bids":[
"b":[
{
"price":0.6625,
"size":447.02
},
...
"price":0.9062,
"size":1951.28
}
],
"time":"2024-03-25T18:48:45.454000128"
"ts":"2025-01-13T11:35:23.236999936"
},
"retExtInfo":{

},
"retExtInfo":{},
"time":"2024-03-25T18:48:45.454000128"
"time":"2025-01-13T11:35:23.382000128"
}
```
"""
function order_book(client::BybitClient, query::OrderBookQuery)
return APIsRequest{Data{OrderBookData}}("GET", "/spot/v3/public/quote/depth", query)(client)
return APIsRequest{Data{OrderBookData}}("GET", "/v5/market/orderbook", query)(client)
end

function order_book(client::BybitClient = Bybit.Spot.public_client; kw...)
Expand Down
Loading
Loading