Skip to content

Commit

Permalink
Cleanup, tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Nov 6, 2024
1 parent 59c54b9 commit 0977335
Show file tree
Hide file tree
Showing 40 changed files with 948 additions and 307 deletions.
8 changes: 7 additions & 1 deletion Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
A minimal API showing how to integrate WhiteBit.Net in a web API project

### WhiteBit.Examples.Console
A simple console client demonstrating basic usage
A simple console client demonstrating basic usage

### WhiteBit.Examples.OrderBook
Example of using the client side order book implementation

### WhiteBit.Examples.Tracker
Example of using the trade tracker
7 changes: 4 additions & 3 deletions Examples/WhiteBit.Examples.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
// Map the endpoint and inject the rest client
app.MapGet("/{Symbol}", async ([FromServices] IWhiteBitRestClient client, string symbol) =>
{
var result = await client.SpotApi.ExchangeData.GetTickerAsync(symbol);
return result.Data.LastPrice;
var tickers = await client.V4Api.ExchangeData.GetTickersAsync();
var ticker = tickers.Data.Single(x => x.Symbol == symbol);
return ticker.LastPrice;
})
.WithOpenApi();


app.MapGet("/Balances", async ([FromServices] IWhiteBitRestClient client) =>
{
var result = await client.SpotApi.Account.GetBalancesAsync();
var result = await client.V4Api.Account.GetSpotBalancesAsync();
return (object)(result.Success ? result.Data : result.Error!);
})
.WithOpenApi();
Expand Down
4 changes: 4 additions & 0 deletions Examples/WhiteBit.Examples.Api/WhiteBit.Examples.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\WhiteBit.Net\WhiteBit.Net.csproj" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions Examples/WhiteBit.Examples.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

// REST
var restClient = new WhiteBitRestClient();
var ticker = await restClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
Console.WriteLine($"Rest client ticker price for ETHUSDT: {ticker.Data.List.First().LastPrice}");
var tickers = await restClient.V4Api.ExchangeData.GetTickersAsync();
var ticker = tickers.Data.Single(x => x.Symbol == "ETH_USDT");
Console.WriteLine($"Rest client ticker price for ETH_USDT: {ticker.LastPrice}");

Console.WriteLine();
Console.WriteLine("Press enter to start websocket subscription");
Console.ReadLine();

// Websocket
var socketClient = new WhiteBitSocketClient();
var subscription = await socketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", update =>
var subscription = await socketClient.V4Api.SubscribeToTickerUpdatesAsync("ETH_USDT", update =>
{
Console.WriteLine($"Websocket client ticker price for ETHUSDT: {update.Data.LastPrice}");
Console.WriteLine($"Websocket client ticker price for ETH_USDT: {update.Data.Ticker.LastPrice}");
});

Console.ReadLine();
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\WhiteBit.Net\WhiteBit.Net.csproj" />
</ItemGroup>

</Project>
37 changes: 28 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![.NET](https://img.shields.io/github/actions/workflow/status/JKorf/WhiteBit.Net/dotnet.yml?style=for-the-badge)](https://github.com/JKorf/WhiteBit.Net/actions/workflows/dotnet.yml) ![License](https://img.shields.io/github/license/JKorf/WhiteBit.Net?style=for-the-badge)

WhiteBit.Net is a client library for accessing the [WhiteBit REST and Websocket API](WhiteBit).
WhiteBit.Net is a client library for accessing the [WhiteBit REST and Websocket API](https://docs.whitebit.com/).

## Features
* Response data is mapped to descriptive models
Expand Down Expand Up @@ -47,16 +47,17 @@ The NuGet package files are added along side the source with the latest GitHub r
```csharp
// Get the ETH/USDT ticker via rest request
var restClient = new WhiteBitRestClient();
var tickerResult = await restClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
var lastPrice = tickerResult.Data.LastPrice;
var tickerResult = await restClient.V4Api.ExchangeData.GetTickersAsync();
var symbol = tickerResult.Data.Single(x => x.Symbol == "ETH_USDT");
var lastPrice = symbol.LastPrice;
```
* Websocket streams
```csharp
// Subscribe to ETH/USDT ticker updates via the websocket API
var socketClient = new WhiteBitSocketClient();
var tickerSubscriptionResult = socketClient.SpotApi.SubscribeToTickerUpdatesAsync("ETHUSDT", (update) =>
var tickerSubscriptionResult = socketClient.V4Api.SubscribeToTickerUpdatesAsync("ETH_USDT", (update) =>
{
var lastPrice = update.Data.LastPrice;
var lastPrice = update.Data.Ticker.LastPrice;
});
```

Expand Down Expand Up @@ -95,14 +96,32 @@ A Discord server is available [here](https://discord.gg/MSpeEtSY8t). For discuss

## Supported functionality

### Spot
### V4 API Public
|API|Supported|Location|
|--|--:|--|
|TODO||`restClient.SpotApi.Account`|
### Futures
|Rest API||`restClient.V4Api.ExchangeData`|
|Websocket API||`socketClient.V4Api`|

### V4 API Private Rest Main
|API|Supported|Location|
|--|--:|--|
|Codes API||`restClient.V4Api.Codes`|
|Crypto Lending API|X||
|Fees API||`restClient.V4Api.Account`|
|SubAccount API||`restClient.V4Api.SubAccount`|
|Mining Pool API||`restClient.V4Api.Account`|

### V4 API Private Rest Trade
|API|Supported|Location|
|--|--:|--|
|Spot API||`restClient.V4Api.Account` / `restClient.V4Api.Trading`|
|Collateral API||`restClient.V4Api.Account` / `restClient.V4Api.CollateralTrading`|
|Convert API||`restClient.V4Api.Convert`|

### V4 API Private WebSocket
|API|Supported|Location|
|--|--:|--|
|TODO||`restClient.FuturesApi.ExchangeData`|
|*||`socketClient.V4Api`|

## Support the project
Any support is greatly appreciated.
Expand Down
28 changes: 13 additions & 15 deletions WhiteBit.Net.UnitTests/Endpoints/V4/Trading/GetUserTrades.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
POST
/api/v4/trade-account/executed-history
true
{
"BTC_USDT": [
{
"id": 160305483,
"clientOrderId": "customId11",
"time": 1594667731.724403,
"side": "sell",
"role": 2,
"amount": "0.000076",
"price": "9264.21",
"deal": "0.70407996",
"fee": "0.00070407996"
}
]
}
[
{
"id": 160305483,
"clientOrderId": "customId11",
"time": 1594667731.724403,
"side": "sell",
"role": 2,
"amount": "0.000076",
"price": "9264.21",
"deal": "0.70407996",
"fee": "0.00070407996"
}
]
2 changes: 1 addition & 1 deletion WhiteBit.Net.UnitTests/RestRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task ValidateV4TradingCalls()
opts.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456");
});
var tester = new RestRequestValidator<WhiteBitRestClient>(client, "Endpoints/V4/Trading", "https://whitebit.com", IsAuthenticated, stjCompare: true);
await tester.ValidateAsync(client => client.V4Api.Trading.GetUserTradesAsync(), "GetUserTrades");
await tester.ValidateAsync(client => client.V4Api.Trading.GetUserTradesAsync("ETH_USDT"), "GetUserTrades");
await tester.ValidateAsync(client => client.V4Api.Trading.GetOrderTradesAsync(123), "GetOrderTrades", nestedJsonProperty: "records");
}

Expand Down
10 changes: 8 additions & 2 deletions WhiteBit.Net.UnitTests/SocketSubscriptionTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using CryptoExchange.Net.Testing;
using NUnit.Framework;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using WhiteBit.Net.Clients;
using WhiteBit.Net.Objects.Models;
Expand All @@ -16,8 +18,12 @@ public async Task ValidateSpotExchangeDataSubscriptions()
{
opts.ApiCredentials = new CryptoExchange.Net.Authentication.ApiCredentials("123", "456");
});
var tester = new SocketSubscriptionValidator<WhiteBitSocketClient>(client, "Subscriptions/Spot", "XXX", stjCompare: true);
//await tester.ValidateAsync<WhiteBitModel>((client, handler) => client.SpotApi.SubscribeToXXXUpdatesAsync(handler), "XXX");
var tester = new SocketSubscriptionValidator<WhiteBitSocketClient>(client, "Subscriptions/V4", "wss://api.whitebit.com", stjCompare: true);
await tester.ValidateAsync<WhiteBitTradeUpdate>((client, handler) => client.V4Api.SubscribeToTradeUpdatesAsync("ETH_USDT", handler), "Trades", nestedJsonProperty: "params");
await tester.ValidateAsync<WhiteBitLastPriceUpdate>((client, handler) => client.V4Api.SubscribeToLastPriceUpdatesAsync("ETH_USDT", handler), "LastPrice", nestedJsonProperty: "params");
await tester.ValidateAsync<WhiteBitTickerUpdate>((client, handler) => client.V4Api.SubscribeToTickerUpdatesAsync("ETH_USDT", handler), "Ticker", nestedJsonProperty: "params");
await tester.ValidateAsync<IEnumerable<WhiteBitKlineUpdate>>((client, handler) => client.V4Api.SubscribeToKlineUpdatesAsync("ETH_USDT", Enums.KlineInterval.OneDay, handler), "Klines", nestedJsonProperty: "params");
await tester.ValidateAsync<WhiteBitBookUpdate>((client, handler) => client.V4Api.SubscribeToOrderBookUpdatesAsync("ETH_USDT", 5, handler), "OrderBook", nestedJsonProperty: "params");
}
}
}
4 changes: 0 additions & 4 deletions WhiteBit.Net.UnitTests/Subscriptions/Spot/TODO.txt

This file was deleted.

19 changes: 19 additions & 0 deletions WhiteBit.Net.UnitTests/Subscriptions/V4/Klines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
> { "id": "|1|", "method": "candles_subscribe", "params": ["ETH_USDT", 86400] }
< { "id": |1|, "result": { "status": "success" }, "error": null }
=
{
"id": null,
"method": "candles_update",
"params": [
[
1580895000,
"0.020683",
"0.020683",
"0.020683",
"0.020666",
"504.701",
"10.433600491",
"ETH_USDT"
]
]
}
11 changes: 11 additions & 0 deletions WhiteBit.Net.UnitTests/Subscriptions/V4/LastPrice.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
> { "id": "|1|", "method": "lastprice_subscribe", "params": ["ETH_USDT"] }
< { "id": |1|, "result": { "status": "success" }, "error": null }
=
{
"id": null,
"method": "lastprice_update",
"params": [
"ETH_USDT",
"0.020683"
]
}
22 changes: 22 additions & 0 deletions WhiteBit.Net.UnitTests/Subscriptions/V4/OrderBook.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
> { "id": "|1|", "method": "depth_subscribe", "params": ["ETH_USDT", 5, "0"] }
< { "id": |1|, "result": { "status": "success" }, "error": null }
=
{
"id": null,
"method": "depth_update",
"params": [
false,
{
"timestamp": 1689600180.5164471,
"asks": [
["0.020861", "0"],
["0.020900", "2.5"]
],
"bids": [
["0.020844", "5.949"],
["0.020800", "0"]
]
},
"ETH_USDT"
]
}
20 changes: 20 additions & 0 deletions WhiteBit.Net.UnitTests/Subscriptions/V4/Ticker.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
> { "id": "|1|", "method": "market_subscribe", "params": ["ETH_USDT"] }
< { "id": |1|, "result": { "status": "success" }, "error": null }
=
{
"id": null,
"method": "market_update",
"params": [
"ETH_USDT",
{
"period": 86400,
"last": "0.020964",
"open": "0.020349",
"close": "0.020964",
"high": "0.020997",
"low": "0.020281",
"volume": "135574.476",
"deal": "2784.413999488"
}
]
}
19 changes: 19 additions & 0 deletions WhiteBit.Net.UnitTests/Subscriptions/V4/Trades.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
> { "id": "|1|", "method": "trades_subscribe", "params": ["ETH_USDT"] }
< { "id": |1|, "result": { "status": "success" }, "error": null }
=
{
"id": null,
"method": "trades_update",
"params": [
"ETH_USDT",
[
{
"id": 41358530,
"time": 1580905394.70332,
"price": "0.020857",
"amount": "5.511",
"type": "sell"
}
]
]
}
Loading

0 comments on commit 0977335

Please sign in to comment.