Skip to content

Commit cf6ef44

Browse files
authored
Move all endpoint parameters to query (#53)
1 parent 3a6502c commit cf6ef44

File tree

12 files changed

+113
-71
lines changed

12 files changed

+113
-71
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "CryptoExchangeAPIs"
22
uuid = "5e3d4798-c815-4641-85e1-deed530626d3"
3-
version = "0.28.0"
3+
version = "0.29.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/Coinbase/Spot/API/Candle.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ using CryptoExchangeAPIs: Maybe, APIsRequest
1414

1515
Base.@kwdef struct CandleQuery <: CoinbasePublicQuery
1616
granularity::TimeInterval
17+
product_id::String
1718
start::Maybe{DateTime} = nothing
1819
_end::Maybe{DateTime} = nothing
1920
end
2021

22+
Serde.SerQuery.ser_ignore_field(::Type{CandleQuery}, ::Val{:product_id}) = true
23+
2124
function Serde.ser_type(::Type{<:CandleQuery}, x::TimeInterval)::String
2225
x == m1 && return "60"
2326
x == m5 && return "300"
@@ -49,6 +52,7 @@ Get rates for a single product by product ID, grouped in buckets.
4952
| Parameter | Type | Required | Description |
5053
|:------------|:-------------|:---------|:-------------------|
5154
| granularity | TimeInterval | true | m1 m5 m15 h1 h6 d1 |
55+
| product_id | String | true | |
5256
| start | DateTime | false | |
5357
| _end | DateTime | false | |
5458
@@ -59,7 +63,8 @@ using Serde
5963
using CryptoExchangeAPIs.Coinbase
6064
6165
result = Coinbase.Spot.candle(;
62-
granularity = Coinbase.Spot.Candle.d1
66+
granularity = Coinbase.Spot.Candle.d1,
67+
product_id = "BTC-USD",
6368
)
6469
6570
to_pretty_json(result.result)
@@ -81,12 +86,12 @@ to_pretty_json(result.result)
8186
]
8287
```
8388
"""
84-
function candle(client::CoinbaseClient, query::CandleQuery; product_id::String)
85-
return APIsRequest{Vector{CandleData}}("GET", "products/$product_id/candles", query)(client)
89+
function candle(client::CoinbaseClient, query::CandleQuery;)
90+
return APIsRequest{Vector{CandleData}}("GET", "products/$(query.product_id)/candles", query)(client)
8691
end
8792

88-
function candle(client::CoinbaseClient = Coinbase.Spot.public_client; product_id::String, kw...)
89-
return candle(client, CandleQuery(; kw...); product_id = product_id)
93+
function candle(client::CoinbaseClient = Coinbase.Spot.public_client; kw...)
94+
return candle(client, CandleQuery(; kw...))
9095
end
9196

9297
end

src/Coinbase/Spot/API/ProductStats.jl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ using CryptoExchangeAPIs.Coinbase
1111
using CryptoExchangeAPIs: Maybe, APIsRequest
1212

1313
Base.@kwdef struct ProductStatsQuery <: CoinbasePublicQuery
14-
#__ empty
14+
product_id::String
1515
end
1616

17+
Serde.SerQuery.ser_ignore_field(::Type{ProductStatsQuery}, ::Val{:product_id}) = true
18+
1719
struct ProductStatsData <: CoinbaseData
1820
open::Float64
1921
high::Float64
@@ -35,13 +37,21 @@ Get rates for a single product by product ID, grouped in buckets.
3537
3638
[`GET products/{product_id}/stats`](https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductstats)
3739
40+
## Parameters:
41+
42+
| Parameter | Type | Required | Description |
43+
|:-----------|:---------|:---------|:------------|
44+
| product_id | String | true | |
45+
3846
## Code samples:
3947
4048
```julia
4149
using Serde
4250
using CryptoExchangeAPIs.Coinbase
4351
44-
result = Coinbase.Spot.product_stats()
52+
result = Coinbase.Spot.product_stats(;
53+
product_id = "BTC-USD",
54+
)
4555
4656
to_pretty_json(result.result)
4757
```
@@ -63,12 +73,12 @@ to_pretty_json(result.result)
6373
}
6474
```
6575
"""
66-
function product_stats(client::CoinbaseClient, query::ProductStatsQuery; product_id::String)
67-
return APIsRequest{ProductStatsData}("GET", "products/$product_id/stats", query)(client)
76+
function product_stats(client::CoinbaseClient, query::ProductStatsQuery;)
77+
return APIsRequest{ProductStatsData}("GET", "products/$(query.product_id)/stats", query)(client)
6878
end
6979

70-
function product_stats(client::CoinbaseClient = Coinbase.Spot.public_client; product_id::String, kw...)
71-
return product_stats(client, ProductStatsQuery(; kw...); product_id = product_id)
80+
function product_stats(client::CoinbaseClient = Coinbase.Spot.public_client; kw...)
81+
return product_stats(client, ProductStatsQuery(; kw...))
7282
end
7383

7484
end

src/Coinbase/Spot/API/Ticker.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ using CryptoExchangeAPIs.Coinbase
1111
using CryptoExchangeAPIs: Maybe, APIsRequest
1212

1313
Base.@kwdef struct TickerQuery <: CoinbasePublicQuery
14-
#__ empty
14+
product_id::String
1515
end
1616

17+
Serde.SerQuery.ser_ignore_field(::Type{TickerQuery}, ::Val{:product_id}) = true
18+
1719
struct TickerData <: CoinbaseData
1820
ask::Float64
1921
bid::Float64
@@ -32,6 +34,12 @@ Gets snapshot information about the last trade (tick), best bid/ask and 24h volu
3234
3335
[`GET products/{product_id}/ticker`](https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker)
3436
37+
## Parameters:
38+
39+
| Parameter | Type | Required | Description |
40+
|:-----------|:---------|:---------|:------------|
41+
| product_id | String | true | |
42+
3543
## Code samples:
3644
3745
```julia
@@ -59,12 +67,12 @@ to_pretty_json(result.result)
5967
}
6068
```
6169
"""
62-
function ticker(client::CoinbaseClient, query::TickerQuery; product_id::String)
63-
return APIsRequest{TickerData}("GET", "products/$product_id/ticker", query)(client)
70+
function ticker(client::CoinbaseClient, query::TickerQuery;)
71+
return APIsRequest{TickerData}("GET", "products/$(query.product_id)/ticker", query)(client)
6472
end
6573

66-
function ticker(client::CoinbaseClient = Coinbase.Spot.public_client; product_id::String, kw...)
67-
return ticker(client, TickerQuery(; kw...); product_id = product_id)
74+
function ticker(client::CoinbaseClient = Coinbase.Spot.public_client; kw...)
75+
return ticker(client, TickerQuery(; kw...))
6876
end
6977

7078
end

src/Gateio/Futures/API/Candle.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,25 @@ end
2323

2424
struct CandleQuery <: GateioPublicQuery
2525
contract::Contract
26+
settle::Settle
2627
from::Maybe{DateTime}
2728
to::Maybe{DateTime}
2829
limit::Maybe{Int64}
2930
interval::Maybe{TimeInterval}
3031
end
3132

33+
Serde.SerQuery.ser_ignore_field(::Type{CandleQuery}, ::Val{:settle}) = true
34+
3235
function CandleQuery(;
3336
type::ContractType,
3437
name::String,
38+
settle::Settle,
3539
from::Maybe{DateTime} = nothing,
3640
to::Maybe{DateTime} = nothing,
3741
limit::Maybe{Int64} = nothing,
3842
interval::Maybe{TimeInterval} = nothing,
3943
)
40-
return CandleQuery(Contract(type, name), from, to, limit, interval)
44+
return CandleQuery(Contract(type, name), settle, from, to, limit, interval)
4145
end
4246

4347
function Serde.ser_type(::Type{<:CandleQuery}, x::Contract)::String
@@ -81,6 +85,7 @@ Get futures candlesticks.
8185
| Parameter | Type | Required | Description |
8286
|:----------|:-------------|:---------|:-------------------------------------|
8387
| contract | String | true | |
88+
| settle | Settle | true | btc usdt usd |
8489
| interval | TimeInterval | false | s10 m1 m5 m15 m30 h1 h4 h8 d1 d7 d30 |
8590
| from | DateTime | false | |
8691
| to | DateTime | false | |
@@ -119,12 +124,12 @@ to_pretty_json(result.result)
119124
]
120125
```
121126
"""
122-
function candle(client::GateioClient, settle::Settle, query::CandleQuery)
123-
return APIsRequest{Vector{CandleData}}("GET", "api/v4/futures/$settle/candlesticks", query)(client)
127+
function candle(client::GateioClient, query::CandleQuery)
128+
return APIsRequest{Vector{CandleData}}("GET", "api/v4/futures/$(query.settle)/candlesticks", query)(client)
124129
end
125130

126-
function candle(client::GateioClient = Gateio.Futures.public_client; settle::Settle, kw...)
127-
return candle(client, settle, CandleQuery(; kw...))
131+
function candle(client::GateioClient = Gateio.Futures.public_client; kw...)
132+
return candle(client, CandleQuery(; kw...))
128133
end
129134

130135
end

src/Gateio/Futures/API/Contract.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ using CryptoExchangeAPIs: Maybe, APIsRequest
1313
@enum Settle btc usdt usd
1414

1515
Base.@kwdef struct ContractQuery <: GateioPublicQuery
16+
settle::Settle
1617
limit::Maybe{Int64} = nothing
1718
offset::Maybe{Int64} = nothing
1819
end
1920

21+
Serde.SerQuery.ser_ignore_field(::Type{ContractQuery}, ::Val{:settle}) = true
22+
2023
struct ContractData <: GateioData
2124
name::String
2225
type::String
@@ -72,10 +75,11 @@ List all futures contracts.
7275
7376
## Parameters:
7477
75-
| Parameter | Type | Required | Description |
76-
|:----------|:---------|:---------|:------------|
77-
| limit | Int64 | false | |
78-
| offset | Int64 | false | |
78+
| Parameter | Type | Required | Description |
79+
|:----------|:---------|:---------|:-------------|
80+
| settle | Settle | true | btc usdt usd |
81+
| limit | Int64 | false | |
82+
| offset | Int64 | false | |
7983
8084
## Code samples:
8185
@@ -139,12 +143,12 @@ to_pretty_json(result.result)
139143
]
140144
```
141145
"""
142-
function contract(client::GateioClient, settle::Settle, query::ContractQuery)
143-
return APIsRequest{Vector{ContractData}}("GET", "api/v4/futures/$settle/contracts", query)(client)
146+
function contract(client::GateioClient, query::ContractQuery)
147+
return APIsRequest{Vector{ContractData}}("GET", "api/v4/futures/$(query.settle)/contracts", query)(client)
144148
end
145149

146-
function contract(client::GateioClient = Gateio.Futures.public_client; settle::Settle, kw...)
147-
return contract(client, settle, ContractQuery(; kw...))
150+
function contract(client::GateioClient = Gateio.Futures.public_client; kw...)
151+
return contract(client, ContractQuery(; kw...))
148152
end
149153

150154
end

src/Gateio/Futures/API/FundingRate.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ using CryptoExchangeAPIs: Maybe, APIsRequest
1414

1515
Base.@kwdef struct FundingRateQuery <: GateioPublicQuery
1616
contract::String
17+
settle::Settle
1718
limit::Maybe{Int64} = nothing
1819
end
1920

21+
Serde.SerQuery.ser_ignore_field(::Type{FundingRateQuery}, ::Val{:settle}) = true
22+
2023
struct FundingRateData <: GateioData
2124
t::NanoDate
2225
r::Maybe{Float64}
@@ -32,10 +35,11 @@ Funding rate history.
3235
3336
## Parameters:
3437
35-
| Parameter | Type | Required | Description |
36-
|:----------|:---------|:---------|:------------|
37-
| contract | String | true | |
38-
| limit | Int64 | false | |
38+
| Parameter | Type | Required | Description |
39+
|:----------|:---------|:---------|:-------------|
40+
| settle | Settle | true | btc usdt usd |
41+
| contract | String | true | |
42+
| limit | Int64 | false | |
3943
4044
## Code samples:
4145
@@ -63,12 +67,12 @@ to_pretty_json(result.result)
6367
]
6468
```
6569
"""
66-
function funding_rate(client::GateioClient, settle::Settle, query::FundingRateQuery)
67-
return APIsRequest{Vector{FundingRateData}}("GET", "api/v4/futures/$settle/funding_rate", query)(client)
70+
function funding_rate(client::GateioClient, query::FundingRateQuery)
71+
return APIsRequest{Vector{FundingRateData}}("GET", "api/v4/futures/$(query.settle)/funding_rate", query)(client)
6872
end
6973

70-
function funding_rate(client::GateioClient = Gateio.Futures.public_client; settle::Settle, kw...)
71-
return funding_rate(client, settle, FundingRateQuery(; kw...))
74+
function funding_rate(client::GateioClient = Gateio.Futures.public_client; kw...)
75+
return funding_rate(client, FundingRateQuery(; kw...))
7276
end
7377

7478
end

src/Gateio/Futures/API/OrderBook.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ using CryptoExchangeAPIs: Maybe, APIsRequest
1414

1515
Base.@kwdef struct OrderBookQuery <: GateioPublicQuery
1616
contract::String
17+
settle::Settle
1718
interval::Maybe{String} = nothing
1819
limit::Maybe{Int64} = nothing
1920
with_id::Maybe{Bool} = nothing
2021
end
2122

23+
Serde.SerQuery.ser_ignore_field(::Type{OrderBookQuery}, ::Val{:settle}) = true
24+
2225
struct Order <: GateioData
2326
p::String
2427
s::Int64
@@ -46,12 +49,13 @@ Futures order book.
4649
4750
## Parameters:
4851
49-
| Parameter | Type | Required | Description |
50-
|:----------|:---------|:---------|:------------|
51-
| contract | String | true | |
52-
| interval | String | false | |
53-
| limit | Int64 | false | |
54-
| with_id | Bool | false | |
52+
| Parameter | Type | Required | Description |
53+
|:----------|:---------|:---------|:-------------|
54+
| contract | String | true | |
55+
| settle | Settle | true | btc usdt usd |
56+
| interval | String | false | |
57+
| limit | Int64 | false | |
58+
| with_id | Bool | false | |
5559
5660
## Code samples:
5761
@@ -91,12 +95,12 @@ to_pretty_json(result.result)
9195
}
9296
```
9397
"""
94-
function order_book(client::GateioClient, settle::Settle, query::OrderBookQuery)
95-
return APIsRequest{OrderBookData}("GET", "api/v4/futures/$settle/order_book", query)(client)
98+
function order_book(client::GateioClient, query::OrderBookQuery)
99+
return APIsRequest{OrderBookData}("GET", "api/v4/futures/$(query.settle)/order_book", query)(client)
96100
end
97101

98-
function order_book(client::GateioClient = Gateio.Futures.public_client; settle::Settle, kw...)
99-
return order_book(client, settle, OrderBookQuery(; kw...))
102+
function order_book(client::GateioClient = Gateio.Futures.public_client; kw...)
103+
return order_book(client, OrderBookQuery(; kw...))
100104
end
101105

102106
end

src/Gateio/Futures/API/Ticker.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ using CryptoExchangeAPIs: Maybe, APIsRequest
1313
@enum Settle btc usdt usd
1414

1515
Base.@kwdef struct TickerQuery <: GateioPublicQuery
16+
settle::Settle
1617
contract::Maybe{String} = nothing
1718
end
1819

20+
Serde.SerQuery.ser_ignore_field(::Type{TickerQuery}, ::Val{:settle}) = true
21+
1922
struct TickerData <: GateioData
2023
contract::String
2124
last::Maybe{Float64}
@@ -47,9 +50,10 @@ List futures tickers.
4750
4851
## Parameters:
4952
50-
| Parameter | Type | Required | Description |
51-
|:----------|:---------|:---------|:------------|
52-
| contract | String | false | |
53+
| Parameter | Type | Required | Description |
54+
|:----------|:---------|:---------|:-------------|
55+
| settle | Settle | true | btc usdt usd |
56+
| contract | String | false | |
5357
5458
## Code samples:
5559
@@ -89,12 +93,12 @@ to_pretty_json(result.result)
8993
]
9094
```
9195
"""
92-
function ticker(client::GateioClient, settle::Settle, query::TickerQuery)
93-
return APIsRequest{Vector{TickerData}}("GET", "api/v4/futures/$settle/tickers", query)(client)
96+
function ticker(client::GateioClient, query::TickerQuery)
97+
return APIsRequest{Vector{TickerData}}("GET", "api/v4/futures/$(query.settle)/tickers", query)(client)
9498
end
9599

96-
function ticker(client::GateioClient = Gateio.Futures.public_client; settle::Settle, kw...)
97-
return ticker(client, settle, TickerQuery(; kw...))
100+
function ticker(client::GateioClient = Gateio.Futures.public_client; kw...)
101+
return ticker(client, TickerQuery(; kw...))
98102
end
99103

100104
end

0 commit comments

Comments
 (0)