Skip to content

Commit

Permalink
Feature/send update (#86)
Browse files Browse the repository at this point in the history
Added client side ratelimiter implementation
Updated REST and WebSocket unit tests
Updated REST requests to new CryptoExchange.Net implementation
Updated various response models
Fixed restClient.FuturesApi.Trading.CancelOrderByClientOrderIdAsync response model
Fixed restClient.FuturesApi.Trading.CancelStopOrderByClientOrderIdAsync response model
Fixed restClient.SpotApi.Account.GetCreditAccountAsync response model
Fixed restClient.SpotApi.Account.GetWithdrawalHistoryAsync status parameter
Removed V1 API
  • Loading branch information
JKorf authored Feb 19, 2025
1 parent c6e817f commit 9229a4a
Show file tree
Hide file tree
Showing 248 changed files with 3,830 additions and 7,485 deletions.
84 changes: 1 addition & 83 deletions CoinEx.Net.UnitTests/CoinExClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
using Newtonsoft.Json;
using NUnit.Framework;
using CoinEx.Net.Objects;
using NUnit.Framework;
using System.Collections.Generic;
using CryptoExchange.Net.Authentication;
using Moq;
using System.Linq;
using CryptoExchange.Net;
using System.Net;
using System;
using System.Threading.Tasks;
using CoinEx.Net.Enums;
using System.Reflection;
using System.Diagnostics;
using CoinEx.Net.Objects.Internal;
using CryptoExchange.Net.Objects;
using CryptoExchange.Net.Sockets;
using CoinEx.Net.Clients;
using CoinEx.Net.ExtensionMethods;
using CryptoExchange.Net.Objects.Sockets;
using NUnit.Framework.Legacy;
using CoinEx.Net.Clients.SpotApiV1;
using CryptoExchange.Net.Clients;
using System.Net.Http;
using CryptoExchange.Net.Converters.JsonNet;
Expand All @@ -32,71 +15,6 @@ namespace CoinEx.Net.UnitTests
[TestFixture]
public class CoinExClientTests
{

[TestCase()]
public async Task ReceivingError_Should_ReturnErrorAndNotSuccess()
{
// arrange
var client = TestHelpers.CreateClient();
var resultObj = new CoinExApiResult()
{
Code = 400001,
Message = "Error occured"
};

TestHelpers.SetResponse((CoinExRestClient)client, JsonConvert.SerializeObject(resultObj));

// act
var result = await client.SpotApi.ExchangeData.GetAssetsAsync();

// assert
ClassicAssert.IsFalse(result.Success);
ClassicAssert.IsNotNull(result.Error);
Assert.That(result.Error!.Code == 400001);
Assert.That(result.Error.Message == "Error occured");
}

[TestCase()]
public async Task ReceivingHttpErrorWithNoJson_Should_ReturnErrorAndNotSuccess()
{
// arrange
var client = TestHelpers.CreateClient();
TestHelpers.SetResponse((CoinExRestClient)client, "", System.Net.HttpStatusCode.BadRequest);

// act
var result = await client.SpotApi.ExchangeData.GetAssetsAsync();

// assert
ClassicAssert.IsFalse(result.Success);
ClassicAssert.IsNotNull(result.Error);
}

[Test]
public void ProvidingApiCredentials_Should_SaveApiCredentials()
{
// arrange
// act
var authProvider = new CoinExAuthenticationProvider(new ApiCredentials("TestKey", "TestSecret"), null);

// assert
Assert.That(authProvider.ApiKey == "TestKey");
}

[Test]
[TestCase("TestStringToSign", "C351B1833970C30017EF9AE280A09570")]
[TestCase("access_id=4DA36FFC61334695A66F8D29020EB589&amount=1.0&market=BTCBCH&price=680&tonce=1513746038205&type=buy&secret_key=B51068CF10B34E7789C374AB932696A05E0A629BE7BFC62F", "610AB90A1D31D45901D173E4F59C9384")]
public void SigningString_Should_GiveCorrectSignResult(string input, string output)
{
// arrange
var authProvider = new CoinExAuthenticationProvider(new ApiCredentials("4DA36FFC61334695A66F8D29020EB589", "B51068CF10B34E7789C374AB932696A05E0A629BE7BFC62F"), null);

// act
var sign = authProvider.Sign(input);

// assert
Assert.That(sign == output);
}

[Test]
public void CheckSignatureExample1()
{
Expand Down
17 changes: 17 additions & 0 deletions CoinEx.Net.UnitTests/Endpoints/FuturesApi/Account/GetBalances.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GET
/v2/assets/futures/balance
true
{
"code": 0,
"data": [
{
"ccy": "CET",
"available": "45945.5263788804",
"frozen": "50634.82448865128",
"margin": "36407.5334622699",
"unrealized_pnl": "18957.427858971438",
"transferrable": "14265.938812991284"
}
],
"message": "OK"
}
11 changes: 11 additions & 0 deletions CoinEx.Net.UnitTests/Endpoints/FuturesApi/Account/SetLeverage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
POST
/v2/futures/adjust-position-leverage
true
{
"code": 0,
"data": {
"margin_mode": "cross",
"leverage": 10
},
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET
/v2/futures/basis-history
false
{
"code": 0,
"data": [
{
"market": "LATUSDT",
"created_at": 1642145400000,
"basis_rate": "-0.00027732"
},
{
"market": "LATUSDT",
"created_at": 1642146000000,
"basis_rate": "-0.00013372"
}
],
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
GET
/v2/futures/funding-rate-history
false
{
"code": 0,
"data": [
{
"market": "LATUSDT",
"funding_time": 1642145331234,
"theoretical_funding_rate": "-0.00007488",
"actual_funding_rate": "-0.00027732"
},
{
"market": "ELONUSDT",
"funding_time": 1642145331234,
"theoretical_funding_rate": "-0.00003688",
"actual_funding_rate": "-0.00013372"
}
],
"pagination": {
"has_next": false
},
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GET
/v2/futures/funding-rate
false
{
"code": 0,
"data": [
{
"market": "LATUSDT",
"mark_price": "0.008157",
"latest_funding_rate": "-0.00007488",
"next_funding_rate": "-0.00027732",
"max_funding_rate": "0.00375",
"min_funding_rate": "-0.00375",
"latest_funding_time": 1642145331234,
"next_funding_time": 1642231731234
},
{
"market": "ELONUSDT",
"mark_price": "0.000000152823",
"latest_funding_rate": "-0.00003688",
"next_funding_rate": "-0.00013372",
"max_funding_rate": "0.00375",
"min_funding_rate": "-0.00375",
"latest_funding_time": 1642145331234,
"next_funding_time": 1642231731234
}
],
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
GET
/v2/futures/index
false
{
"code": 0,
"data": [
{
"market": "BTCUSDT",
"created_at": 1703561120000,
"price": "30718.42",
"sources": [
{
"created_at": 1703561102173,
"exchange" : "binance",
"index_weight": "0.25"
},
{
"created_at": 1703561124859,
"exchange": "coinex",
"index_weight": "0.25"
},
{
"created_at": 1703561123704,
"exchange": " meexc",
"index_weight": "0.25"
},
{
"created_at": 1703561125040,
"exchange": "bybit ",
"index_weight": "0.25"
}
]
}
],
"message": "OK "
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET
/v2/futures/kline
false
{
"code": 0,
"data": [
{
"market": "LATUSDT",
"created_at": 17017617600000,
"open": "0.008286",
"close": "0.008157",
"high": "0.008390",
"low": "0.008106",
"volume": "807714.49139758",
"value": "6689.21644207"
}
],
"message" : "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GET
/v2/futures/liquidation-history
false
{
"code": 0,
"data": [
{
"market": " LATUSDT",
"side": "long",
"liq_price": "0.009061",
"liq_amount": "184378262",
"bkr_price": "0.009038",
"created_at": 1691482451000
},
{
"market": " LATUSDT",
"side": "long",
"liq_price": "0.009030",
"liq_amount": "375947238",
"bkr_price": "0.009016",
"created_at": 1691482829000
}
],
"pagination": {
"has_next": false
},
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
GET
/v2/futures/depth
false
{
"code": 0,
"data": {
"market": "BTCUSDT",
"is_full": true,
"depth": {
"asks": [
[
"30740.00",
"0.31763545"
],
[
"30769.00",
"1.45155000"
]
],
"bids": [
[
"30736.00",
"0.04857373"
],
[
"30733.00",
"0.84696320"
],
[
"30725.00",
"0.12563353"
],
[
"30422.00",
"0"
]
],
"last": "30746.28",
"updated_at": 1689152421692,
"checksum": 2578768879
}
},
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
GET
/v2/futures/position-level
false
{
"code": 0,
"data": [
{
"market": "BTCUSDT",
"level": [
{"amount": "20", "leverage": "100", "maintenance_margin_rate": "0.005", "min_initial_margin_rate": "0.01"},
{"amount": "50", "leverage": "50", "maintenance_margin_rate": "0.01", "min_initial_margin_rate": "0.02"},
{"amount": "100", "leverage": "30", "maintenance_margin_rate": "0.015", "min_initial_margin_rate": "0.0333"},
{"amount": "200", "leverage": "20", "maintenance_margin_rate": "0.02", "min_initial_margin_rate": "0.05"},
{"amount": "500", "leverage": "15", "maintenance_margin_rate": "0.025", "min_initial_margin_rate": "0.06"},
{"amount": "1000", "leverage": "10", "maintenance_margin_rate": "0.03", "min_initial_margin_rate": "0.1"}
]
}
],
"message": "OK"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
GET
/v2/futures/premium-index-history
false
{
"code": 0,
"data": [
{
"market": "LATUSDT",
"created_at": 1642145400000,
"premium_index": "-0.00027732"
},
{
"market": "LATUSDT",
"created_at": 1642146000000,
"premium_index": "-0.00013372"
}
],
"message": "OK"
}
Loading

0 comments on commit 9229a4a

Please sign in to comment.