Skip to content

Commit

Permalink
Add binance historical trades endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
justmark0 committed Jul 23, 2024
1 parent 5b1e347 commit b66a77b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/pages/Binance.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CryptoAPIs.Binance.USDMFutures.candle
CryptoAPIs.Binance.USDMFutures.continuous_candle
CryptoAPIs.Binance.USDMFutures.exchange_info
CryptoAPIs.Binance.USDMFutures.funding_rate
CryptoAPIs.Binance.USDMFutures.historical_trades
CryptoAPIs.Binance.USDMFutures.long_short_ratio
CryptoAPIs.Binance.USDMFutures.open_interest_hist
CryptoAPIs.Binance.USDMFutures.order_book
Expand Down
2 changes: 2 additions & 0 deletions examples/Binance/USDMFutures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Binance.USDMFutures.exchange_info()

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

Binance.USDMFutures.historical_trades(;symbol = "BTCUSDT")

Binance.USDMFutures.long_short_ratio(;
symbol = "BTCUSDT",
period = Binance.USDMFutures.LongShortRatio.h1,
Expand Down
79 changes: 79 additions & 0 deletions src/Binance/USDMFutures/API/HistoricalTrades.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module HistoricalTrades

export HistoricalTradesQuery,
HistoricalTradesData,
historical_trades

using Serde
using Dates, NanoDates, TimeZones

using CryptoAPIs.Binance
using CryptoAPIs: Maybe, APIsRequest

Base.@kwdef struct HistoricalTradesQuery <: BinancePublicQuery
symbol::String
limit::Maybe{Int64} = nothing
fromtId::Maybe{Int64} = nothing
end

struct HistoricalTradesData <: BinanceData
id::Maybe{Int64}
price::Maybe{Float64}
qty::Maybe{Float64}
quoteQty::Maybe{Float64}
time::NanoDate
isBuyerMaker::Bool
end

"""
historical_trades(client::BinanceClient, query::HistoricalTradesQuery)
historical_trades(client::BinanceClient = Binance.USDMFutures.public_client; kw...)
[`GET fapi/v1/historicalTrades`](https://binance-docs.github.io/apidocs/futures/en/#old-trades-lookup-market_data)
## Parameters:
| Parameter | Type | Required | Description |
|:----------|:-------|:---------|:-------------------------------------------------------|
| symbol | String | true | |
| limit | Int64 | false | Default: 500; Max: 1000 |
| fromId | Int64 | false | TradeId to fetch from. Default gets most recent trades |
## Code samples:
```julia
using Serde
using CryptoAPIs.Binance
result = Binance.USDMFutures.historical_trades(;
symbol = "BTCUSDT"
)
to_pretty_json(result.result)
```
## Result:
```json
[
{
"id": 28457,
"price": "4.00000100",
"qty": "12.00000000",
"quoteQty": "8000.00",
"time": 1499865549590,
"isBuyerMaker": true,
}
]
```
"""
function historical_trades(client::BinanceClient, query::HistoricalTradesQuery)
return APIsRequest{Vector{HistoricalTradesData}}("GET", "/api/v3/historicalTrades", query)(client)
end

function historical_trades(client::BinanceClient = Binance.USDMFutures.public_client; kw...)
return historical_trades(client, HistoricalTradesQuery(; kw...))
end

end

3 changes: 3 additions & 0 deletions src/Binance/USDMFutures/USDMFutures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ using .ExchangeInfo
include("API/FundingRate.jl")
using .FundingRate

include("API/HistoricalTrades.jl")
using .HistoricalTrades

include("API/LongShortRatio.jl")
using .LongShortRatio

Expand Down

0 comments on commit b66a77b

Please sign in to comment.