Skip to content

Commit

Permalink
Feature/integration tests (#74)
Browse files Browse the repository at this point in the history
* Added integration tests
* Updated CryptoExchange.Net
  • Loading branch information
JKorf authored Jul 26, 2024
1 parent 7fcb5a6 commit 5f86c16
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Integration Testing

on:
schedule:
- cron: "0 0 * * *"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
- name: Set GitHub package source
run: dotnet nuget add source --username JKorf --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/JKorf/index.json"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal -e INTEGRATION=1
126 changes: 126 additions & 0 deletions CoinEx.Net.UnitTests/CoinExRestIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using CoinEx.Net.Clients;
using CoinEx.Net.Objects;
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.Testing;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CoinEx.Net.UnitTests
{
[NonParallelizable]
internal class CoinExRestIntegrationTests : RestIntergrationTest<CoinExRestClient>
{
public override bool Run { get; set; }

public CoinExRestIntegrationTests()
{
}

public override CoinExRestClient GetClient(ILoggerFactory loggerFactory)
{
var key = Environment.GetEnvironmentVariable("APIKEY");
var sec = Environment.GetEnvironmentVariable("APISECRET");

Authenticated = key != null && sec != null;
return new CoinExRestClient(null, loggerFactory, opts =>
{
opts.OutputOriginalData = true;
opts.ApiCredentials = Authenticated ? new ApiCredentials(key, sec) : null;
});
}

[Test]
public async Task TestErrorResponseParsing()
{
if (!ShouldRun())
return;

var result = await CreateClient().SpotApiV2.ExchangeData.GetTickersAsync(new[] { "TSTTST" }, default);

Assert.That(result.Success, Is.False);
Assert.That(result.Error.Code, Is.EqualTo(3639));
}

[Test]
public async Task TestSpotAccount()
{
await RunAndCheckResult(client => client.SpotApiV2.Account.GetTradingFeesAsync("ETHUSDT", Enums.AccountType.Spot, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetBalancesAsync(default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetMarginBalancesAsync(default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetFinancialBalancesAsync(default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetCreditAccountAsync(default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetAutoMarketMakerAccountLiquidityAsync(default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetBorrowHistoryAsync(default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetBorrowLimitAsync("ETHUSDT", "USDT", default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetDepositHistoryAsync("USDT", default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetWithdrawalHistoryAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetDepositWithdrawalConfigAsync("ETH", default), true);
await RunAndCheckResult(client => client.SpotApiV2.Account.GetTransfersAsync("ETH", Enums.AccountType.Spot, default, default, default, default, default, default, default), true);
}

[Test]
public async Task TestSpotExchangeData()
{
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetServerTimeAsync(default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetSymbolsAsync(default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetAssetsAsync(default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetTickersAsync(default, default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetOrderBookAsync("ETHUSDT", 5, default, default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetTradeHistoryAsync("ETHUSDT", default, default, default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetKlinesAsync("ETHUSDT", Enums.KlineInterval.OneDay, default, default, default), false);
await RunAndCheckResult(client => client.SpotApiV2.ExchangeData.GetIndexPricesAsync(default, default), false);
}

[Test]
public async Task TestSpotTrading()
{
await RunAndCheckResult(client => client.SpotApiV2.Trading.GetOpenOrdersAsync(Enums.AccountType.Spot, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Trading.GetClosedOrdersAsync(Enums.AccountType.Spot, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Trading.GetOpenStopOrdersAsync(Enums.AccountType.Spot, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Trading.GetClosedStopOrdersAsync(Enums.AccountType.Spot, default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.SpotApiV2.Trading.GetUserTradesAsync("ETHUSDT", Enums.AccountType.Spot, default, default, default, default, default, default), true);
}

[Test]
public async Task TestFuturesAccount()
{
await RunAndCheckResult(client => client.FuturesApi.Account.GetTradingFeesAsync("ETHUSDT", default), true);
await RunAndCheckResult(client => client.FuturesApi.Account.GetBalancesAsync(default), true);
}

[Test]
public async Task TestFuturesExchangeData()
{
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetServerTimeAsync(default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetSymbolsAsync(default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetTickersAsync(default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetOrderBookAsync("ETHUSDT", 5, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT", default, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetKlinesAsync("ETHUSDT", Enums.KlineInterval.OneDay, default, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetIndexPricesAsync(default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetFundingRatesAsync(default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetFundingRateHistoryAsync("ETHUSDT", default, default, default, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetPremiumIndexPriceHistoryAsync("ETHUSDT", default, default, default, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetPositionLevelsAsync(default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetLiquidationHistoryAsync("ETHUSDT", default, default, default, default, default), false);
await RunAndCheckResult(client => client.FuturesApi.ExchangeData.GetBasisHistoryAsync("ETHUSDT", default, default, default), false);
}

[Test]
public async Task TestFuturesTrading()
{
await RunAndCheckResult(client => client.FuturesApi.Trading.GetOpenOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetClosedOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetOpenStopOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetClosedStopOrdersAsync(default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetUserTradesAsync("ETHUSDT", default, default, default, default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetPositionsAsync("ETHUSDT", default, default, default), true);
await RunAndCheckResult(client => client.FuturesApi.Trading.GetPositionHistoryAsync("ETHUSDT", default, default, default, default, default), true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
}

/// <inheritdoc />
public override ReadOnlyMemory<byte> PreprocessStreamMessage(WebSocketMessageType type, ReadOnlyMemory<byte> data)
public override ReadOnlyMemory<byte> PreprocessStreamMessage(SocketConnection connection, WebSocketMessageType type, ReadOnlyMemory<byte> data)
=> data.DecompressGzip();

#region public
Expand Down
2 changes: 1 addition & 1 deletion CoinEx.Net/Clients/SpotApiV2/CoinExSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
}

/// <inheritdoc />
public override ReadOnlyMemory<byte> PreprocessStreamMessage(WebSocketMessageType type, ReadOnlyMemory<byte> data)
public override ReadOnlyMemory<byte> PreprocessStreamMessage(SocketConnection connection, WebSocketMessageType type, ReadOnlyMemory<byte> data)
=> data.DecompressGzip();

#region public
Expand Down
2 changes: 1 addition & 1 deletion CoinEx.Net/CoinEx.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.9.0" />
<PackageReference Include="CryptoExchange.Net" Version="7.10.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions CoinEx.Net/CoinEx.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f86c16

Please sign in to comment.