Skip to content

Commit

Permalink
CryptoExchange V7.11.0 (#228)
Browse files Browse the repository at this point in the history
Updated CryptoExchange.Net to V7.11.0
Fixed nullable enum response properties
  • Loading branch information
JKorf authored Aug 7, 2024
1 parent 7003514 commit 7dd72ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Kucoin.Net/Kucoin.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.10.0" />
<PackageReference Include="CryptoExchange.Net" Version="7.11.0" />
</ItemGroup>
</Project>
30 changes: 20 additions & 10 deletions Kucoin.Net/KucoinAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public override void AuthenticateRequest(
RestApiClient apiClient,
Uri uri,
HttpMethod method,
IDictionary<string, object> uriParameters,
IDictionary<string, object> bodyParameters,
Dictionary<string, string> headers,
ref IDictionary<string, object>? uriParameters,
ref IDictionary<string, object>? bodyParameters,
ref Dictionary<string, string>? headers,
bool auth,
ArrayParametersSerialization arraySerialization,
HttpMethodParameterPosition parameterPosition,
Expand All @@ -50,10 +50,13 @@ public override void AuthenticateRequest(
brokerKey = apiClient is KucoinRestClientFuturesApi ? "9e08c05f-454d-4580-82af-2f4c7027fd00" : "f8ae62cb-2b3d-420c-8c98-e1c17dd4e30a";
}

uri = uri.SetParameters(uriParameters, arraySerialization);
headers.Add("KC-API-KEY", _credentials.Key!.GetString());
if (uriParameters != null)
uri = uri.SetParameters(uriParameters, arraySerialization);

headers ??= new Dictionary<string, string>();
headers.Add("KC-API-KEY", _credentials.Key);
headers.Add("KC-API-TIMESTAMP", GetMillisecondTimestamp(apiClient).ToString());
var phrase = _credentials.PassPhrase.GetString();
var phrase = _credentials.PassPhrase;
if (!_phraseCache.TryGetValue(phrase, out var phraseSign))
{
phraseSign = SignHMACSHA256(phrase, SignOutputType.Base64);
Expand All @@ -66,17 +69,24 @@ public override void AuthenticateRequest(
string jsonContent = string.Empty;
if (parameterPosition == HttpMethodParameterPosition.InBody)
{
jsonContent = bodyParameters.Count == 1 && bodyParameters.First().Key == "<BODY>"
? JsonConvert.SerializeObject(bodyParameters.First().Value)
: JsonConvert.SerializeObject(bodyParameters);
if (bodyParameters?.Any() == true)
{
jsonContent = bodyParameters.Count == 1 && bodyParameters.First().Key == "<BODY>"
? JsonConvert.SerializeObject(bodyParameters.First().Value)
: JsonConvert.SerializeObject(bodyParameters);
}
else
{
jsonContent = "{}";
}
}

var signData = headers["KC-API-TIMESTAMP"] + method + Uri.UnescapeDataString(uri.PathAndQuery) + jsonContent;
headers.Add("KC-API-SIGN", SignHMACSHA256(signData, SignOutputType.Base64));

// Partner info
headers.Add("KC-API-PARTNER", brokerName!);
var partnerSignData = headers["KC-API-TIMESTAMP"] + brokerName + _credentials.Key!.GetString();
var partnerSignData = headers["KC-API-TIMESTAMP"] + brokerName + _credentials.Key;
using HMACSHA256 hMACSHA = new HMACSHA256(Encoding.UTF8.GetBytes(brokerKey));
byte[] buff = hMACSHA.ComputeHash(Encoding.UTF8.GetBytes(partnerSignData));
headers.Add("KC-API-PARTNER-SIGN", BytesToBase64String(buff));
Expand Down
8 changes: 4 additions & 4 deletions Kucoin.Net/Objects/KucoinApiCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class KucoinApiCredentials : ApiCredentials
/// <summary>
/// The pass phrase
/// </summary>
public SecureString PassPhrase { get; }
public string PassPhrase { get; }

/// <summary>
/// Creates new api credentials. Keep this information safe.
Expand All @@ -25,7 +25,7 @@ public class KucoinApiCredentials : ApiCredentials
/// <param name="apiPassPhrase">The API passPhrase</param>
public KucoinApiCredentials(string apiKey, string apiSecret, string apiPassPhrase): base(apiKey, apiSecret)
{
PassPhrase = apiPassPhrase.ToSecureString();
PassPhrase = apiPassPhrase;
}

/// <summary>
Expand All @@ -42,13 +42,13 @@ public KucoinApiCredentials(Stream inputStream, string? identifierKey = null, st
throw new ArgumentException("Input stream not valid json data");

var pass = accessor.GetValue<string>(MessagePath.Get().Property(identifierPassPhrase ?? "apiPassPhrase")) ?? throw new ArgumentException("apiKey or apiSecret value not found in Json credential file");
PassPhrase = pass.ToSecureString();
PassPhrase = pass;
}

/// <inheritdoc />
public override ApiCredentials Copy()
{
return new KucoinApiCredentials(Key!.GetString(), Secret!.GetString(), PassPhrase!.GetString());
return new KucoinApiCredentials(Key, Secret, PassPhrase);
}
}
}
2 changes: 1 addition & 1 deletion Kucoin.Net/Objects/Models/Spot/KucoinOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public record KucoinOrder: KucoinOrderBase
/// <summary>
/// The stop condition
/// </summary>
public StopCondition Stop { get; set; }
public StopCondition? Stop { get; set; }
/// <summary>
/// Time after which the order is canceled
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Kucoin.Net/Objects/Models/Spot/KucoinUserTrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public record KucoinUserTrade: KucoinTradeBase
/// <summary>
/// The stop condition of the fill
/// </summary>
public StopCondition Stop { get; set; }
public StopCondition? Stop { get; set; }
/// <summary>
/// The id of the counter order
/// </summary>
Expand Down

0 comments on commit 7dd72ce

Please sign in to comment.