Skip to content

Commit

Permalink
Enhance Spot Tickers API functionality (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlo committed Sep 24, 2024
1 parent f785baa commit 734ca49
Show file tree
Hide file tree
Showing 18 changed files with 421 additions and 22 deletions.
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.30.0"
version = "0.31.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/Kucoin.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CryptoExchangeAPIs.Kucoin.Spot.public_client
```@docs
CryptoExchangeAPIs.Kucoin.Spot.candle
CryptoExchangeAPIs.Kucoin.Spot.deposit
CryptoExchangeAPIs.Kucoin.Spot.ticker
CryptoExchangeAPIs.Kucoin.Spot.ticker_all
```

## Futures
Expand Down
10 changes: 10 additions & 0 deletions docs/src/pages/Okex.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ CryptoExchangeAPIs.Okex.OkexAPIError
CryptoExchangeAPIs.Okex.Data
```

## Common

```@docs
CryptoExchangeAPIs.Okex.Common.public_client
```

```@docs
CryptoExchangeAPIs.Okex.Common.ticker
```

## Spot

```@docs
Expand Down
1 change: 1 addition & 0 deletions docs/src/pages/Upbit.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ CryptoExchangeAPIs.Upbit.Spot.market_list
CryptoExchangeAPIs.Upbit.Spot.order_book
CryptoExchangeAPIs.Upbit.Spot.status_wallet
CryptoExchangeAPIs.Upbit.Spot.ticker
CryptoExchangeAPIs.Upbit.Spot.ticker_all
```
4 changes: 2 additions & 2 deletions src/Bithumb/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Ticker

export TikerQuery,
TikerData,
export TickerQuery,
TickerData,
ticker

using Serde
Expand Down
4 changes: 2 additions & 2 deletions src/Bybit/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Base.@kwdef struct TickerQuery <: BybitPublicQuery
end

struct TickerData <: BybitData
s::String
ap::Float64
bp::Float64
h::Float64
l::Float64
lp::Float64
o::Float64
qv::Float64
s::String
t::NanoDate
v::Float64
end
Expand Down Expand Up @@ -60,14 +60,14 @@ to_pretty_json(result.result)
"retCode":0,
"retMsg":"OK",
"result":{
"s":"ADAUSDT",
"ap":0.6636,
"bp":0.6634,
"h":0.6687,
"l":0.6315,
"lp":0.6633,
"o":0.6337,
"qv":1.1594252877069e7,
"s":"ADAUSDT",
"t":"2024-03-25T19:05:35.491000064",
"v":1.780835204e7
},
Expand Down
6 changes: 3 additions & 3 deletions src/Cryptocom/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Base.@kwdef struct TickerQuery <: CryptocomPublicQuery
end

struct TickerInfo <: CryptocomData
i::String
h::Float64
l::Maybe{Float64}
a::Maybe{Float64}
i::String
v::Float64
vv::Float64
oi::Float64
oi::Maybe{Float64}
c::Maybe{Float64}
b::Maybe{Float64}
k::Maybe{Float64}
Expand Down Expand Up @@ -76,10 +76,10 @@ to_pretty_json(result.result)
"result":{
"data":[
{
"i":"BTCUSD-PERP",
"h":63090.7,
"l":59671.8,
"a":62296.2,
"i":"BTCUSD-PERP",
"v":10797.3637,
"vv":6.6340329849e8,
"oi":1844.5729,
Expand Down
5 changes: 4 additions & 1 deletion src/Deribit/Common/API/Instrument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export InstrumentQuery,
InstrumentData,
instrument

export Currency,
InstrumentKind

using Serde
using Dates, NanoDates, TimeZones

Expand Down Expand Up @@ -85,7 +88,7 @@ using Serde
using CryptoExchangeAPIs.Deribit
result = Deribit.Common.instrument(;
currency = CryptoExchangeAPIs.Deribit.Common.Instrument.BTC
currency = Deribit.Common.Instrument.BTC
)
to_pretty_json(result.result)
Expand Down
4 changes: 2 additions & 2 deletions src/Deribit/Common/API/Ticker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct Stats <: DeribitData
end

struct TickerData <: DeribitData
instrument_name::String
ask_iv::Maybe{Float64}
best_ask_amount::Maybe{Float64}
best_ask_price::Maybe{Float64}
Expand All @@ -44,7 +45,6 @@ struct TickerData <: DeribitData
funding_8h::Maybe{Float64}
greeks::Maybe{Greeks}
index_price::Maybe{Float64}
instrument_name::String
interest_rate::Maybe{Float64}
interest_value::Maybe{Float64}
last_price::Maybe{Float64}
Expand Down Expand Up @@ -103,6 +103,7 @@ to_pretty_json(result.result)
"usOut":"2024-05-17T12:10:28.639980032",
"usIn":"2024-05-17T12:10:28.639770880",
"result":{
"instrument_name":"BTC-PERPETUAL",
"ask_iv":null,
"best_ask_amount":227380.0,
"best_ask_price":66265.0,
Expand All @@ -115,7 +116,6 @@ to_pretty_json(result.result)
"funding_8h":2.703e-5,
"greeks":null,
"index_price":66245.52,
"instrument_name":"BTC-PERPETUAL",
"interest_rate":null,
"interest_value":0.011170326646787519,
"last_price":66265.0,
Expand Down
4 changes: 2 additions & 2 deletions src/Gateio/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Base.@kwdef struct TickerQuery <: GateioPublicQuery
end

struct TickerData <: GateioData
currency_pair::String
base_volume::Maybe{Float64}
change_percentage::Float64
change_utc0::Maybe{Float64}
change_utc8::Maybe{Float64}
currency_pair::String
etf_leverage::Maybe{Float64}
etf_net_value::Maybe{Float64}
etf_pre_net_value::Maybe{Float64}
Expand Down Expand Up @@ -70,11 +70,11 @@ to_pretty_json(result.result)
```json
[
{
"currency_pair":"ADA_USDT",
"base_volume":2.0167711540647e7,
"change_percentage":-4.77,
"change_utc0":null,
"change_utc8":null,
"currency_pair":"ADA_USDT",
"etf_leverage":null,
"etf_net_value":null,
"etf_pre_net_value":null,
Expand Down
4 changes: 2 additions & 2 deletions src/Huobi/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Base.@kwdef struct TickerQuery <: HuobiPublicQuery
end

struct TickerData <: HuobiData
symbol::String
amount::Maybe{Float64}
ask::Maybe{Float64}
askSize::Maybe{Float64}
Expand All @@ -26,7 +27,6 @@ struct TickerData <: HuobiData
high::Maybe{Float64}
low::Maybe{Float64}
open::Maybe{Float64}
symbol::String
vol::Maybe{Float64}
end

Expand Down Expand Up @@ -59,6 +59,7 @@ to_pretty_json(result.result)
"code":null,
"data":[
{
"symbol":"sylousdt",
"amount":5.379805390589e8,
"ask":0.001716,
"askSize":90895.4464,
Expand All @@ -69,7 +70,6 @@ to_pretty_json(result.result)
"high":0.001773,
"low":0.001683,
"open":0.001716,
"symbol":"sylousdt",
"vol":924950.6866947605
},
...
Expand Down
167 changes: 167 additions & 0 deletions src/Kucoin/Spot/API/Ticker.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
module Ticker

export TickerQuery,
TickerAllQuery,
TickerData,
TickerAllData,
ticker,
ticker_all

using Serde
using Dates, NanoDates, TimeZones

using CryptoExchangeAPIs.Kucoin
using CryptoExchangeAPIs.Kucoin: Data
using CryptoExchangeAPIs: Maybe, APIsRequest

Base.@kwdef struct TickerQuery <: KucoinPublicQuery
symbol::Maybe{String}
end

Base.@kwdef struct TickerAllQuery <: KucoinPublicQuery
#__ empty
end

struct TickerData <: KucoinData
symbol::String
averagePrice::Maybe{Float64}
buy::Maybe{Float64}
changePrice::Maybe{Float64}
changeRate::Maybe{Float64}
high::Maybe{Float64}
last::Maybe{Float64}
low::Maybe{Float64}
makerCoefficient::Maybe{Float64}
makerFeeRate::Maybe{Float64}
sell::Maybe{Float64}
takerCoefficient::Maybe{Float64}
takerFeeRate::Maybe{Float64}
time::Maybe{NanoDate}
vol::Maybe{Float64}
volValue::Maybe{Float64}
end

struct TickerAllData <: KucoinData
time::Maybe{NanoDate}
ticker::Vector{TickerData}
end

"""
ticker(client::KucoinClient, query::TickerQuery)
ticker(client::KucoinClient = Kucoin.Spot.public_client; kw...)
Request via this endpoint to get the statistics of the specified ticker in the last 24 hours.
[`GET api/v1/market/stats`](https://www.kucoin.com/docs/rest/spot-trading/market-data/get-24hr-stats)
## Parameters:
| Parameter | Type | Required | Description |
|:-----------|:-------|:---------|:------------|
| symbol | String | true | |
## Code samples:
```julia
using Serde
using CryptoExchangeAPIs.Kucoin
result = Kucoin.Spot.ticker(; symbol = "BTC")
to_pretty_json(result.result)
```
## Result:
```json
{
"code":200000,
"data":{
"symbol":"BTC",
"averagePrice":null,
"buy":null,
"changePrice":null,
"changeRate":null,
"high":null,
"last":null,
"low":null,
"makerCoefficient":null,
"makerFeeRate":null,
"sell":null,
"takerCoefficient":null,
"takerFeeRate":null,
"time":"2024-09-23T15:48:26.456999936",
"vol":null,
"volValue":null
}
}
```
"""
function ticker(client::KucoinClient, query::TickerQuery)
return APIsRequest{Data{TickerData}}("GET", "api/v1/market/stats", query)(client)
end

function ticker(client::KucoinClient = Kucoin.Spot.public_client; kw...)
return ticker(client, TickerQuery(; kw...))
end

"""
ticker_all(client::KucoinClient, query::TickerQuery)
ticker_all(client::KucoinClient = Kucoin.Spot.public_client; kw...)
Request market tickers for all the trading pairs in the market (including 24h volume).
[`GET api/v1/market/allTickers`](https://www.kucoin.com/docs/rest/spot-trading/market-data/get-all-tickers)
## Code samples:
```julia
using Serde
using CryptoExchangeAPIs.Kucoin
result = Kucoin.Spot.ticker_all()
to_pretty_json(result.result)
```
## Result:
```json
{
"code":200000,
"data":{
"time":"2024-09-23T15:54:48.020999936",
"ticker":[
{
"symbol":"HLG-USDT",
"averagePrice":0.0015635,
"buy":0.00156,
"changePrice":3.0e-5,
"changeRate":0.0194,
"high":0.00161,
"last":0.00157,
"low":0.00152,
"makerCoefficient":2.0,
"makerFeeRate":0.001,
"sell":0.00158,
"takerCoefficient":2.0,
"takerFeeRate":0.001,
"time":null,
"vol":1.6744577e6,
"volValue":2626.113078
},
...
]
}
}
```
"""
function ticker_all(client::KucoinClient, query::TickerAllQuery)
return APIsRequest{Data{TickerAllData}}("GET", "api/v1/market/allTickers", query)(client)
end

function ticker_all(client::KucoinClient = Kucoin.Spot.public_client; kw...)
return ticker_all(client, TickerAllQuery(; kw...))
end

end
3 changes: 3 additions & 0 deletions src/Kucoin/Spot/Spot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ using .Candle
include("API/Deposit.jl")
using .Deposit

include("API/Ticker.jl")
using .Ticker

end
Loading

0 comments on commit 734ca49

Please sign in to comment.