|
| 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 | + |
0 commit comments