1+ module ContinuousCandle
2+
3+ export ContinuousCandleQuery,
4+ ContinuousCandleData,
5+ continuous_candle
6+
7+ using Serde
8+ using Dates, NanoDates, TimeZones
9+
10+ using CryptoAPIs. Binance
11+ using CryptoAPIs: Maybe, APIsRequest
12+
13+ @enum TimeInterval m1 m3 m5 m15 m30 h1 h2 h4 h6 h8 h12 d1 d3 w1 M1
14+
15+ @enum ContractType PERPETUAL CURRENT_QUARTER NEXT_QUARTER
16+
17+ Base. @kwdef struct ContinuousCandleQuery <: BinancePublicQuery
18+ pair:: String
19+ contractType:: ContractType
20+ interval:: TimeInterval
21+ limit:: Maybe{Int64} = nothing
22+ endTime:: Maybe{DateTime} = nothing
23+ startTime:: Maybe{DateTime} = nothing
24+ end
25+
26+ function Serde. ser_type (:: Type{<:ContinuousCandleQuery} , x:: TimeInterval ):: String
27+ x == m1 && return " 1m"
28+ x == m3 && return " 3m"
29+ x == m5 && return " 5m"
30+ x == m15 && return " 15m"
31+ x == m30 && return " 30m"
32+ x == h1 && return " 1h"
33+ x == h2 && return " 2h"
34+ x == h4 && return " 4h"
35+ x == h6 && return " 6h"
36+ x == h8 && return " 8h"
37+ x == h12 && return " 12h"
38+ x == d1 && return " 1d"
39+ x == d3 && return " 3d"
40+ x == w1 && return " 1w"
41+ x == M1 && return " 1M"
42+ end
43+
44+ struct ContinuousCandleData <: BinanceData
45+ openTime:: NanoDate
46+ openPrice:: Maybe{Float64}
47+ highPrice:: Maybe{Float64}
48+ lowPrice:: Maybe{Float64}
49+ closePrice:: Maybe{Float64}
50+ volume:: Maybe{Float64}
51+ closeTime:: NanoDate
52+ quoteAssetVolume:: Maybe{Float64}
53+ tradesNumber:: Maybe{Int64}
54+ takerBuyVolume:: Maybe{Float64}
55+ takerBuyQuoteAssetVolume:: Maybe{Float64}
56+ end
57+
58+ """
59+ continuous_candle(client::BinanceClient, query::ContinuousCandleQuery)
60+ continuous_candle(client::BinanceClient = Binance.USDMFutures.public_client; kw...)
61+
62+ Kline/candlestick bars for a specific contract type.
63+
64+ [`GET fapi/v1/continuousKlines`](https://binance-docs.github.io/apidocs/futures/en/#continuous-contract-kline-candlestick-data)
65+
66+ ## Parameters:
67+
68+ | Parameter | Type | Required | Description |
69+ |:-------------|:---------------|:---------|:--------------------------------------------------------------|
70+ | pair | String | true | |
71+ | contractType | ContractType | true | PERPETUAL, CURRENT\\ _QUARTER, NEXT\\ _QUARTER |
72+ | interval | TimeInterval | true | m1, m3, m5, m15, m30, h1, h2, h4, h6, h8, h12, d1, d3, w1, M1 |
73+ | endTime | DateTime | false | |
74+ | limit | Int64 | false | |
75+ | startTime | DateTime | false |
76+
77+ ## Code samples:
78+
79+ ```julia
80+ using Serde
81+ using CryptoAPIs.Binance
82+
83+ result = Binance.USDMFutures.continuous_candle(;
84+ pair = "BTCUSDT",
85+ contractType = Binance.USDMFutures.ContinuousCandle.PERPETUAL,
86+ interval = Binance.USDMFutures.ContinuousCandle.M1,
87+ )
88+
89+ to_pretty_json(result.result)
90+ ```
91+
92+ ## Result:
93+
94+ ```json
95+ [
96+ {
97+ "openTime":"2019-09-01T00:00:00",
98+ "openPrice":8042.08,
99+ "highPrice":10475.54,
100+ "lowPrice":7700.67,
101+ "closePrice":8041.96,
102+ "volume":608742.1109999999,
103+ "closeTime":"2019-09-30T23:59:59.999000064",
104+ "quoteAssetVolume":5.61187924896223e9,
105+ "tradesNumber":998055,
106+ "takerBuyVolume":298326.244,
107+ "takerBuyQuoteAssetVolume":2.7368038906708302e9
108+ },
109+ ...
110+ ]
111+ ```
112+ """
113+ function continuous_candle (client:: BinanceClient , query:: ContinuousCandleQuery )
114+ return APIsRequest {Vector{ContinuousCandleData}} (" GET" , " fapi/v1/continuousKlines" , query)(client)
115+ end
116+
117+ function continuous_candle (client:: BinanceClient = Binance. USDMFutures. public_client; kw... )
118+ return continuous_candle (client, ContinuousCandleQuery (; kw... ))
119+ end
120+
121+ end
0 commit comments