Skip to content

Commit 287d8f8

Browse files
justmark0gryumovartememelin
authored
Add binance historical trades endpoint (#47)
Co-authored-by: Stanislav Gryumov <33372067+gryumov@users.noreply.github.com> Co-authored-by: Artem Emelin <153018291+artememelin@users.noreply.github.com>
1 parent e53db45 commit 287d8f8

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
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.25.1"
3+
version = "0.25.2"
44

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

docs/src/pages/Binance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ CryptoAPIs.Binance.USDMFutures.candle
3535
CryptoAPIs.Binance.USDMFutures.continuous_candle
3636
CryptoAPIs.Binance.USDMFutures.exchange_info
3737
CryptoAPIs.Binance.USDMFutures.funding_rate
38+
CryptoAPIs.Binance.USDMFutures.historical_trades
3839
CryptoAPIs.Binance.USDMFutures.long_short_ratio
3940
CryptoAPIs.Binance.USDMFutures.open_interest_hist
4041
CryptoAPIs.Binance.USDMFutures.order_book

examples/Binance/USDMFutures.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Binance.USDMFutures.exchange_info()
2828

2929
Binance.USDMFutures.funding_rate(; symbol = "BTCUSDT")
3030

31+
Binance.USDMFutures.historical_trades(; symbol = "BTCUSDT")
32+
3133
Binance.USDMFutures.long_short_ratio(;
3234
symbol = "BTCUSDT",
3335
period = Binance.USDMFutures.LongShortRatio.h1,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
module HistoricalTrades
2+
3+
export HistoricalTradesQuery,
4+
HistoricalTradesData,
5+
historical_trades
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Binance
11+
using CryptoAPIs: Maybe, APIsRequest
12+
13+
Base.@kwdef struct HistoricalTradesQuery <: BinancePublicQuery
14+
symbol::String
15+
limit::Maybe{Int64} = nothing
16+
fromtId::Maybe{Int64} = nothing
17+
end
18+
19+
struct HistoricalTradesData <: BinanceData
20+
id::Maybe{Int64}
21+
price::Maybe{Float64}
22+
qty::Maybe{Float64}
23+
quoteQty::Maybe{Float64}
24+
time::NanoDate
25+
isBuyerMaker::Bool
26+
end
27+
28+
"""
29+
historical_trades(client::BinanceClient, query::HistoricalTradesQuery)
30+
historical_trades(client::BinanceClient = Binance.USDMFutures.public_client; kw...)
31+
32+
[`GET fapi/v1/historicalTrades`](https://binance-docs.github.io/apidocs/futures/en/#old-trades-lookup-market_data)
33+
34+
## Parameters:
35+
36+
| Parameter | Type | Required | Description |
37+
|:----------|:-------|:---------|:-------------------------------------------------------|
38+
| symbol | String | true | |
39+
| limit | Int64 | false | Default: 500; Max: 1000 |
40+
| fromId | Int64 | false | TradeId to fetch from. Default gets most recent trades |
41+
42+
## Code samples:
43+
44+
```julia
45+
using Serde
46+
using CryptoAPIs.Binance
47+
48+
result = Binance.USDMFutures.historical_trades(;
49+
symbol = "BTCUSDT"
50+
)
51+
52+
to_pretty_json(result.result)
53+
```
54+
55+
## Result:
56+
57+
```json
58+
[
59+
{
60+
"id":3697954552,
61+
"price":66428.01,
62+
"qty":0.0038,
63+
"quoteQty":252.426438,
64+
"time":"2024-07-23T12:50:24.951000064",
65+
"isBuyerMaker":false
66+
},
67+
...
68+
]
69+
```
70+
"""
71+
function historical_trades(client::BinanceClient, query::HistoricalTradesQuery)
72+
return APIsRequest{Vector{HistoricalTradesData}}("GET", "/api/v3/historicalTrades", query)(client)
73+
end
74+
75+
function historical_trades(client::BinanceClient = Binance.USDMFutures.public_client; kw...)
76+
return historical_trades(client, HistoricalTradesQuery(; kw...))
77+
end
78+
79+
end
80+

src/Binance/USDMFutures/USDMFutures.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ using .ExchangeInfo
2020
include("API/FundingRate.jl")
2121
using .FundingRate
2222

23+
include("API/HistoricalTrades.jl")
24+
using .HistoricalTrades
25+
2326
include("API/LongShortRatio.jl")
2427
using .LongShortRatio
2528

0 commit comments

Comments
 (0)