Skip to content

Commit 38858b6

Browse files
sirion34gryumovartememelin
authored
Add AccountTrade, DepositLog, ExchangeInfo and WithdrawalLog to Binance Spot API (#16)
Co-authored-by: Stas Gryumov <33372067+gryumov@users.noreply.github.com> Co-authored-by: Artem Emelin <153018291+artememelin@users.noreply.github.com>
1 parent a604018 commit 38858b6

File tree

9 files changed

+636
-17
lines changed

9 files changed

+636
-17
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.8.0"
3+
version = "0.9.0"
44

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

docs/src/pages/Binance.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ CryptoAPIs.Binance.Spot.public_client
1212
```
1313

1414
```@docs
15-
CryptoAPIs.Binance.Spot.candle
15+
CryptoAPIs.Binance.Spot.account_trade
1616
CryptoAPIs.Binance.Spot.avg_price
17+
CryptoAPIs.Binance.Spot.candle
18+
CryptoAPIs.Binance.Spot.coin_information
19+
CryptoAPIs.Binance.Spot.deposit_log
20+
CryptoAPIs.Binance.Spot.exchange_info
1721
CryptoAPIs.Binance.Spot.order_book
1822
CryptoAPIs.Binance.Spot.ticker
19-
CryptoAPIs.Binance.Spot.coin_information
23+
CryptoAPIs.Binance.Spot.withdrawal_log
2024
```
2125

2226
## USDMFutures

examples/Binance/Spot.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Binance.Spot.candle(;
1515
limit = 4,
1616
)
1717

18+
Binance.Spot.exchange_info()
19+
1820
Binance.Spot.order_book(; symbol = "BTCUSDT", limit = 10)
1921

2022
Binance.Spot.ticker()
@@ -27,4 +29,13 @@ binance_client = BinanceClient(;
2729
secret_key = ENV["BINANCE_SECRET_KEY"],
2830
)
2931

32+
Binance.Spot.account_trade(
33+
binance_client;
34+
symbol = "BTCUSDT",
35+
)
36+
3037
Binance.Spot.coin_information(binance_client)
38+
39+
Binance.Spot.deposit_log(binance_client)
40+
41+
Binance.Spot.withdrawal_log(binance_client)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module AccountTrade
2+
3+
export AccountTradeQuery,
4+
AccountTradeData,
5+
account_trade
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Binance
11+
using CryptoAPIs: Maybe, APIsRequest
12+
13+
Base.@kwdef mutable struct AccountTradeQuery <: BinancePrivateQuery
14+
symbol::String
15+
orderId::Maybe{Int64} = nothing
16+
startTime::Maybe{DateTime} = nothing
17+
endTime::Maybe{DateTime} = nothing
18+
fromId::Maybe{Int64} = nothing
19+
limit::Maybe{Int64} = 1000
20+
21+
recvWindow::Maybe{Int64} = nothing
22+
timestamp::Maybe{DateTime} = nothing
23+
signature::Maybe{String} = nothing
24+
end
25+
26+
struct AccountTradeData <: BinanceData
27+
symbol::String
28+
id::Int64
29+
orderId::Int64
30+
orderListId::Int64
31+
price::Float64
32+
qty::Float64
33+
quoteQty::Float64
34+
commission::Float64
35+
commissionAsset::String
36+
time::NanoDate
37+
isBuyer::Bool
38+
isMaker::Bool
39+
isBestMatch::Bool
40+
end
41+
42+
"""
43+
account_trade(client::BinanceClient, query::AccountTradeQuery)
44+
account_trade(client::BinanceClient; kw...)
45+
46+
Get trades for a specific account and symbol.
47+
48+
[`GET api/v3/myTrades`](https://binance-docs.github.io/apidocs/spot/en/#account-trade-list-user_data)
49+
50+
## Parameters:
51+
52+
| Parameter | Type | Required | Description |
53+
|:-----------|:---------|:---------|:--------------|
54+
| symbol | String | true | |
55+
| orderId | Int64 | false | |
56+
| startTime | DateTime | false | |
57+
| endTime | DateTime | false | |
58+
| fromId | Int64 | false | |
59+
| limit | Int64 | false | Default: 1000 |
60+
| recvWindow | Int64 | false | |
61+
| signature | String | false | |
62+
| timestamp | DateTime | false | |
63+
64+
## Code samples:
65+
66+
```julia
67+
using Serde
68+
using CryptoAPIs.Binance
69+
70+
binance_client = BinanceClient(;
71+
base_url = "https://api.binance.com",
72+
public_key = ENV["BINANCE_PUBLIC_KEY"],
73+
secret_key = ENV["BINANCE_SECRET_KEY"],
74+
)
75+
76+
result = Binance.Spot.account_trade(
77+
binance_client;
78+
symbol = "BTCUSDT",
79+
)
80+
81+
to_pretty_json(result.result)
82+
```
83+
84+
## Result:
85+
86+
```json
87+
[
88+
{
89+
"symbol":"BNBBTC",
90+
"id":28457,
91+
"orderId":100234,
92+
"orderListId":-1,
93+
"price":4.00000100,
94+
"qty":12.00000000,
95+
"quoteQty":48.000012,
96+
"commission":10.10000000,
97+
"commissionAsset":"BNB",
98+
"time":"2017-07-12T13:19:09",
99+
"isBuyer":true,
100+
"isMaker":false,
101+
"isBestMatch":true
102+
},
103+
...
104+
]
105+
```
106+
"""
107+
function account_trade(client::BinanceClient, query::AccountTradeQuery)
108+
return APIsRequest{Vector{AccountTradeData}}("GET", "api/v3/myTrades", query)(client)
109+
end
110+
111+
function account_trade(client::BinanceClient; kw...)
112+
return account_trade(client, AccountTradeQuery(; kw...))
113+
end
114+
115+
end

src/Binance/Spot/API/Candle.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,20 @@ to_pretty_json(result.result)
8888
8989
```json
9090
[
91-
{
92-
"openTime":"2018-04-01T00:00:00",
93-
"openPrice":0.25551,
94-
"highPrice":0.3866,
95-
"lowPrice":0.23983,
96-
"closePrice":0.34145,
97-
"volume":1.17451580874e9,
98-
"closeTime":"2018-04-30T23:59:59.999000064",
99-
"quoteAssetVolume":3.597636214561159e8,
100-
"tradesNumber":759135,
101-
"takerBuyBaseAssetVolume":5.556192707e8,
102-
"takerBuyQuoteAssetVolume":1.706766832130686e8
103-
},
104-
...
91+
{
92+
"openTime":"2018-04-01T00:00:00",
93+
"openPrice":0.25551,
94+
"highPrice":0.3866,
95+
"lowPrice":0.23983,
96+
"closePrice":0.34145,
97+
"volume":1.17451580874e9,
98+
"closeTime":"2018-04-30T23:59:59.999000064",
99+
"quoteAssetVolume":3.597636214561159e8,
100+
"tradesNumber":759135,
101+
"takerBuyBaseAssetVolume":5.556192707e8,
102+
"takerBuyQuoteAssetVolume":1.706766832130686e8
103+
},
104+
...
105105
]
106106
```
107107
"""

src/Binance/Spot/API/DepositLog.jl

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
module DepositLog
2+
3+
export DepositLogQuery,
4+
DepositLogData,
5+
deposit_log
6+
7+
using Serde
8+
using Dates, NanoDates, TimeZones
9+
10+
using CryptoAPIs.Binance
11+
using CryptoAPIs: Maybe, APIsRequest
12+
13+
@enum DepositStatus begin
14+
PENDING = 0
15+
SUCCESS = 1
16+
CREDITED_BUT_CANNOT_WITHDRAW = 6
17+
WRONG_DEPOSIT = 7
18+
WAITING_USER_CONFIRM = 8
19+
end
20+
21+
Base.@kwdef mutable struct DepositLogQuery <: BinancePrivateQuery
22+
coin::Maybe{String} = nothing
23+
endTime::Maybe{DateTime} = nothing
24+
limit::Maybe{Int64} = 1000
25+
offset::Maybe{Int64} = nothing
26+
startTime::Maybe{DateTime} = nothing
27+
status::Maybe{DepositStatus} = nothing
28+
txId::Maybe{String} = nothing
29+
30+
recvWindow::Maybe{Int64} = nothing
31+
timestamp::Maybe{DateTime} = nothing
32+
signature::Maybe{String} = nothing
33+
end
34+
35+
function Serde.SerQuery.ser_type(::Type{<:DepositLogQuery}, x::DepositStatus)::Int64
36+
return Int64(x)
37+
end
38+
39+
struct DepositLogData <: BinanceData
40+
address::String
41+
addressTag::String
42+
amount::Float64
43+
coin::String
44+
confirmTimes::String
45+
id::Int64
46+
insertTime::NanoDate
47+
network::String
48+
status::DepositStatus
49+
transferType::Int64
50+
txId::Maybe{String}
51+
unlockConfirm::Int64
52+
walletType::Int64
53+
end
54+
55+
"""
56+
deposit_log(client::BinanceClient, query::DepositLogQuery)
57+
deposit_log(client::BinanceClient; kw...)
58+
59+
Fetch deposit history.
60+
61+
[`GET sapi/v1/capital/withdraw/history`](https://binance-docs.github.io/apidocs/spot/en/#deposit-history-supporting-network-user_data)
62+
63+
## Parameters:
64+
65+
| Parameter | Type | Required | Description |
66+
|:-----------|:--------------|:---------|:--------------|
67+
| coin | String | false | |
68+
| endTime | DateTime | false | |
69+
| limit | Int64 | false | Default: 1000 |
70+
| offset | Int64 | false | |
71+
| startTime | DateTime | false | |
72+
| status | DepositStatus | false | |
73+
| txId | String | false | |
74+
| recvWindow | Int64 | false | |
75+
| timestamp | DateTime | false | |
76+
| signature | String | false | |
77+
78+
## Code samples:
79+
80+
```julia
81+
using Serde
82+
using CryptoAPIs.Binance
83+
84+
binance_client = BinanceClient(;
85+
base_url = "https://api.binance.com",
86+
public_key = ENV["BINANCE_PUBLIC_KEY"],
87+
secret_key = ENV["BINANCE_SECRET_KEY"],
88+
)
89+
90+
result = Binance.Spot.deposit_log(binance_client)
91+
92+
to_pretty_json(result.result)
93+
```
94+
95+
## Result:
96+
97+
```json
98+
[
99+
{
100+
"id":769800519366885376,
101+
"amount":0.001,
102+
"coin":"BNB",
103+
"network":"BNB",
104+
"status":0,
105+
"address":"bnb136ns6lfw4zs5hg4n85vdthaad7hq5m4gtkgf23",
106+
"addressTag":"101764890",
107+
"txId":"98A3EA560C6B3336D348B6C83F0F95ECE4F1F5919E94BD006E5BF3BF264FACFC",
108+
"insertTime":"2022-08-26T05:52:26",
109+
"transferType":0,
110+
"confirmTimes":"1/1",
111+
"unlockConfirm":0,
112+
"walletType":0
113+
},
114+
...
115+
]
116+
```
117+
"""
118+
function deposit_log(client::BinanceClient, query::DepositLogQuery)
119+
return APIsRequest{Vector{DepositLogData}}("GET", "sapi/v1/capital/deposit/hisrec", query)(client)
120+
end
121+
122+
function deposit_log(client::BinanceClient; kw...)
123+
return deposit_log(client, DepositLogQuery(; kw...))
124+
end
125+
126+
end

0 commit comments

Comments
 (0)