Skip to content

Commit a5b6163

Browse files
Add Kucoin Futures exchange (#36)
1 parent fa8bb4d commit a5b6163

File tree

13 files changed

+576
-2
lines changed

13 files changed

+576
-2
lines changed

Project.toml

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

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

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ Then, to install CryptoAPIs, simply use the Julia package manager:
103103
<td><a href="src/Kucoin/Spot">CryptoAPIs.Kucoin.Spot</a></td>
104104
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Kucoin/#Spot">Spot</a></td>
105105
</tr>
106+
<tr>
107+
<td><img src="docs/src/assets/kucoin.png" alt="Kucoin Logo" width="20" height="20"></td>
108+
<td><a href="https://www.kucoin.com/">Kucoin</a></td>
109+
<td><a href="https://www.kucoin.com/docs/beginners/introduction">Futures</a></td>
110+
<td><a href="src/Kucoin/Futures">CryptoAPIs.Kucoin.Futures</a></td>
111+
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Kucoin/#Futures">Futures</a></td>
112+
</tr>
106113
<tr>
107114
<td><img src="docs/src/assets/okex.png" alt="Okex Logo" width="20" height="20"></td>
108115
<td><a href="https://www.okx.com/">Okex</a></td>

docs/src/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ Then, to install CryptoAPIs, simply use the Julia package manager:
9797
<td><a href="src/Kucoin/Spot">CryptoAPIs.Kucoin.Spot</a></td>
9898
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Kucoin/#Spot">Spot</a></td>
9999
</tr>
100+
<tr>
101+
<td><img src="assets/kucoin.png" alt="Kucoin Logo" width="20" height="20"></td>
102+
<td><a href="https://www.kucoin.com/">Kucoin</a></td>
103+
<td><a href="https://www.kucoin.com/docs/beginners/introduction">Futures</a></td>
104+
<td><a href="src/Kucoin/Futures">CryptoAPIs.Kucoin.Futures</a></td>
105+
<td><a href="https://bhftbootcamp.github.io/CryptoAPIs.jl/stable/pages/Kucoin/#Futures">Futures</a></td>
106+
</tr>
100107
<tr>
101108
<td><img src="assets/okex.png" alt="Okex Logo" width="20" height="20"></td>
102109
<td><a href="https://www.okx.com/">Okex</a></td>

docs/src/pages/Kucoin.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ CryptoAPIs.Kucoin.Spot.public_client
1717
CryptoAPIs.Kucoin.Spot.candle
1818
CryptoAPIs.Kucoin.Spot.deposit
1919
```
20+
21+
## Futures
22+
23+
```@docs
24+
CryptoAPIs.Kucoin.Futures.public_client
25+
```
26+
27+
```@docs
28+
CryptoAPIs.Kucoin.Futures.candle
29+
CryptoAPIs.Kucoin.Futures.contract
30+
CryptoAPIs.Kucoin.Futures.private_funding_history
31+
CryptoAPIs.Kucoin.Futures.public_funding_history
32+
```

examples/Kucoin/Futures.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Kucoin/Futures
2+
# https://docs.kucoin.com/
3+
4+
using NanoDates
5+
using CryptoAPIs
6+
using CryptoAPIs.Kucoin
7+
8+
CryptoAPIs.Kucoin.Futures.candle(;
9+
symbol = ".KXBT",
10+
granularity = Kucoin.Futures.Candle.m1,
11+
)
12+
13+
CryptoAPIs.Kucoin.Futures.contract()
14+
15+
CryptoAPIs.Kucoin.Futures.public_funding_history(;
16+
symbol = "IDUSDTM",
17+
from = NanoDate("2023-11-18T12:31:40"),
18+
to = NanoDate("2023-12-11T16:05:00"),
19+
)
20+
21+
kucoin_client = KucoinClient(;
22+
base_url = "https://api-futures.kucoin.com",
23+
public_key = ENV["KUCOIN_PUBLIC_KEY"],
24+
secret_key = ENV["KUCOIN_SECRET_KEY"],
25+
passphrase = ENV["KUCOIN_PASSPHRASE"],
26+
)
27+
28+
CryptoAPIs.Kucoin.Futures.private_funding_history(
29+
kucoin_client;
30+
symbol = "XBTUSDM",
31+
)

src/Kucoin/Futures/API/Candle.jl

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
module Candle
2+
3+
export CandleQuery,
4+
CandleData,
5+
candle
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Kucoin
11+
using CryptoAPIs.Kucoin: Data, Page
12+
using CryptoAPIs: Maybe, APIsRequest
13+
14+
@enum TimeInterval m1 m5 m15 m30 h1 h2 h4 h8 h12 d1 w1
15+
16+
Base.@kwdef struct CandleQuery <: KucoinPublicQuery
17+
symbol::String
18+
granularity::TimeInterval
19+
from::Maybe{NanoDate} = nothing
20+
to::Maybe{NanoDate} = nothing
21+
end
22+
23+
function Serde.ser_type(::Type{<:CandleQuery}, x::TimeInterval)::String
24+
x == m1 && return "1"
25+
x == m5 && return "5"
26+
x == m15 && return "15"
27+
x == m30 && return "30"
28+
x == h1 && return "60"
29+
x == h2 && return "120"
30+
x == h4 && return "240"
31+
x == h8 && return "480"
32+
x == h12 && return "720"
33+
x == d1 && return "1440"
34+
x == w1 && return "10080"
35+
end
36+
37+
struct CandleData <: KucoinData
38+
time::NanoDate
39+
open::Maybe{Float64}
40+
close::Maybe{Float64}
41+
high::Maybe{Float64}
42+
low::Maybe{Float64}
43+
volume::Maybe{Float64}
44+
end
45+
46+
"""
47+
candle(client::KucoinClient, query::CandleQuery)
48+
candle(client::KucoinClient = Kucoin.Futures.public_client; kw...)
49+
50+
Request via this endpoint to get the kline of the specified symbol.
51+
52+
[`GET api/v1/kline/query`](https://www.kucoin.com/docs/rest/futures-trading/market-data/get-klines)
53+
54+
## Parameters:
55+
56+
| Parameter | Type | Required | Description |
57+
|:-----------------|:-------------|:---------|:------------------------------------|
58+
| symbol | String | true | |
59+
| granularity | TimeInterval | true | m1 m5 m15 m30 h1 h2 h4 h8 h12 d1 w1 |
60+
| from | NanoDate | false | |
61+
| to | NanoDate | false | |
62+
63+
## Code samples:
64+
65+
```julia
66+
using Serde
67+
using CryptoAPIs.Kucoin
68+
69+
result = Kucoin.Futures.candle(;
70+
symbol = ".KXBT",
71+
granularity = Kucoin.Futures.Candle.m1,
72+
)
73+
74+
to_pretty_json(result.result)
75+
```
76+
77+
## Result:
78+
79+
```json
80+
{
81+
"code":200000,
82+
"data":[
83+
{
84+
"time":"2024-05-14T20:37:00",
85+
"open":61593.03,
86+
"close":61593.82,
87+
"high":61593.02,
88+
"low":61593.82,
89+
"volume":0.0
90+
},
91+
...
92+
]
93+
}
94+
```
95+
"""
96+
function candle(client::KucoinClient, query::CandleQuery)
97+
return APIsRequest{Data{Vector{CandleData}}}("GET", "api/v1/kline/query", query)(client)
98+
end
99+
100+
function candle(client::KucoinClient = Kucoin.Futures.public_client; kw...)
101+
return candle(client, CandleQuery(; kw...))
102+
end
103+
104+
end

src/Kucoin/Futures/API/Contract.jl

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
module Contract
2+
3+
export ContractQuery,
4+
ContractData,
5+
contract
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Kucoin
11+
using CryptoAPIs.Kucoin: Data, Page
12+
using CryptoAPIs: Maybe, APIsRequest
13+
14+
Base.@kwdef struct ContractQuery <: KucoinPublicQuery
15+
#__ empty
16+
end
17+
18+
struct ContractData <: KucoinData
19+
symbol::String
20+
rootSymbol::String
21+
type::String
22+
firstOpenDate::NanoDate
23+
expireDate::Maybe{NanoDate}
24+
settleDate::Maybe{NanoDate}
25+
baseCurrency::String
26+
quoteCurrency::String
27+
settleCurrency::String
28+
maxOrderQty::Maybe{Int64}
29+
maxPrice::Maybe{Float64}
30+
lotSize::Maybe{Int64}
31+
tickSize::Maybe{Float64}
32+
indexPriceTickSize::Maybe{Float64}
33+
multiplier::Maybe{Float64}
34+
initialMargin::Maybe{Float64}
35+
maintainMargin::Maybe{Float64}
36+
maxRiskLimit::Maybe{Int64}
37+
minRiskLimit::Maybe{Int64}
38+
riskStep::Maybe{Int64}
39+
makerFeeRate::Maybe{Float64}
40+
takerFeeRate::Maybe{Float64}
41+
takerFixFee::Maybe{Float64}
42+
makerFixFee::Maybe{Float64}
43+
settlementFee::Maybe{Float64}
44+
isDeleverage::Bool
45+
isQuanto::Bool
46+
isInverse::Bool
47+
markMethod::Maybe{String}
48+
fairMethod::Maybe{String}
49+
fundingBaseSymbol::Maybe{String}
50+
fundingQuoteSymbol::Maybe{String}
51+
fundingRateSymbol::Maybe{String}
52+
indexSymbol::Maybe{String}
53+
settlementSymbol::Maybe{String}
54+
status::String
55+
fundingFeeRate::Maybe{Float64}
56+
predictedFundingFeeRate::Maybe{Float64}
57+
openInterest::Maybe{String}
58+
turnoverOf24h::Maybe{Float64}
59+
volumeOf24h::Maybe{Float64}
60+
markPrice::Maybe{Float64}
61+
indexPrice::Maybe{Float64}
62+
lastTradePrice::Maybe{Float64}
63+
nextFundingRateTime::Maybe{Int64}
64+
maxLeverage::Maybe{Int64}
65+
sourceExchanges::Maybe{Vector}
66+
premiumsSymbol1M::Maybe{String}
67+
premiumsSymbol8H::Maybe{String}
68+
fundingBaseSymbol1M::Maybe{String}
69+
fundingQuoteSymbol1M::Maybe{String}
70+
lowPrice::Maybe{Float64}
71+
highPrice::Maybe{Float64}
72+
priceChgPct::Maybe{Float64}
73+
priceChg::Maybe{Float64}
74+
end
75+
76+
"""
77+
contract(client::KucoinClient, query::ContractQuery)
78+
contract(client::KucoinClient = Kucoin.Futures.public_client; kw...)
79+
80+
Submit request to get the info of all open contracts.
81+
82+
[`GET api/v1/contracts/active`](https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list)
83+
84+
## Code samples:
85+
86+
```julia
87+
using Serde
88+
using CryptoAPIs.Kucoin
89+
90+
result = Kucoin.Futures.contract()
91+
92+
to_pretty_json(result.result)
93+
```
94+
95+
## Result:
96+
97+
```json
98+
{
99+
"code":200000,
100+
"data":[
101+
{
102+
"symbol":"XEMUSDTM",
103+
"rootSymbol":"USDT",
104+
"type":"FFWCSX",
105+
"firstOpenDate":"2021-04-09T08:00:00",
106+
"expireDate":null,
107+
"settleDate":null,
108+
"baseCurrency":"XEM",
109+
"quoteCurrency":"USDT",
110+
"settleCurrency":"USDT",
111+
"maxOrderQty":1000000,
112+
"maxPrice":1.0e6,
113+
"lotSize":1,
114+
"tickSize":1.0e-5,
115+
"indexPriceTickSize":1.0e-5,
116+
"multiplier":1.0,
117+
"initialMargin":0.034,
118+
"maintainMargin":0.017,
119+
"maxRiskLimit":10000,
120+
"minRiskLimit":10000,
121+
"riskStep":5000,
122+
"makerFeeRate":0.0002,
123+
"takerFeeRate":0.0006,
124+
"takerFixFee":0.0,
125+
"makerFixFee":0.0,
126+
"settlementFee":null,
127+
"isDeleverage":true,
128+
"isQuanto":false,
129+
"isInverse":false,
130+
"markMethod":"FairPrice",
131+
"fairMethod":"FundingRate",
132+
"fundingBaseSymbol":".XEMINT8H",
133+
"fundingQuoteSymbol":".USDTINT8H",
134+
"fundingRateSymbol":".XEMUSDTMFPI8H",
135+
"indexSymbol":".KXEMUSDT",
136+
"settlementSymbol":"",
137+
"status":"Open",
138+
"fundingFeeRate":7.2e-5,
139+
"predictedFundingFeeRate":-1.5e-5,
140+
"openInterest":"14240708",
141+
"turnoverOf24h":39512.89870461,
142+
"volumeOf24h":1.114053e6,
143+
"markPrice":0.03541,
144+
"indexPrice":0.03541,
145+
"lastTradePrice":0.03535,
146+
"nextFundingRateTime":12755619,
147+
"maxLeverage":30,
148+
"sourceExchanges":[
149+
"binance",
150+
"okex",
151+
"kucoin",
152+
"bitget",
153+
"gateio"
154+
],
155+
"premiumsSymbol1M":".XEMUSDTMPI",
156+
"premiumsSymbol8H":".XEMUSDTMPI8H",
157+
"fundingBaseSymbol1M":".XEMINT",
158+
"fundingQuoteSymbol1M":".USDTINT",
159+
"lowPrice":0.03469,
160+
"highPrice":0.03585,
161+
"priceChgPct":-0.0106,
162+
"priceChg":-0.00038
163+
},
164+
...
165+
]
166+
}
167+
```
168+
"""
169+
function contract(client::KucoinClient, query::ContractQuery)
170+
return APIsRequest{Data{Vector{ContractData}}}("GET", "api/v1/contracts/active", query)(client)
171+
end
172+
173+
function contract(client::KucoinClient = Kucoin.Futures.public_client; kw...)
174+
return contract(client, ContractQuery(; kw...))
175+
end
176+
177+
end

0 commit comments

Comments
 (0)