1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-08 16:36:15 +00:00

Added nonce provider default implementation

This commit is contained in:
Jkorf 2021-09-20 15:23:12 +02:00
parent f9957cba16
commit 2ea48d6de9
4 changed files with 91 additions and 10 deletions

View File

@ -0,0 +1,38 @@
using CryptoExchange.Net.Interfaces;
using System;
namespace CryptoExchange.Net.Authentication
{
/// <summary>
/// Default nonce provider
/// </summary>
public class DefaultNonceProvider : INonceProvider
{
private static readonly object nonceLock = new object();
private static long? lastNonce;
/// <summary>
/// Create a new default nonce provider
/// </summary>
/// <param name="startNonce">Start with an incremental value from this start nonce. If not provided `DataTime.UtcNow.Ticks` will be used</param>
public DefaultNonceProvider(long? startNonce = null)
{
lastNonce = startNonce;
}
/// <inheritdoc />
public long GetNonce()
{
lock (nonceLock)
{
long nonce;
if (lastNonce == null)
nonce = DateTime.UtcNow.Ticks;
else
nonce = lastNonce.Value + 1;
lastNonce = nonce;
return nonce;
}
}
}
}

View File

@ -142,6 +142,20 @@
<param name="buff"></param> <param name="buff"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="T:CryptoExchange.Net.Authentication.DefaultNonceProvider">
<summary>
Default nonce provider
</summary>
</member>
<member name="M:CryptoExchange.Net.Authentication.DefaultNonceProvider.#ctor(System.Nullable{System.Int64})">
<summary>
Create a new default nonce provider
</summary>
<param name="startNonce">Start with an incremental value from this start nonce. If not provided `DataTime.UtcNow.Ticks` will be used</param>
</member>
<member name="M:CryptoExchange.Net.Authentication.DefaultNonceProvider.GetNonce">
<inheritdoc />
</member>
<member name="T:CryptoExchange.Net.Authentication.PrivateKey"> <member name="T:CryptoExchange.Net.Authentication.PrivateKey">
<summary> <summary>
Private key info Private key info
@ -1098,6 +1112,17 @@
<param name="exception"></param> <param name="exception"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="T:CryptoExchange.Net.Interfaces.INonceProvider">
<summary>
A provider for a nonce value used when signing requests
</summary>
</member>
<member name="M:CryptoExchange.Net.Interfaces.INonceProvider.GetNonce">
<summary>
Get nonce value. Nonce value should be unique and incremental for each call
</summary>
<returns>Nonce value</returns>
</member>
<member name="T:CryptoExchange.Net.Interfaces.IRateLimiter"> <member name="T:CryptoExchange.Net.Interfaces.IRateLimiter">
<summary> <summary>
Rate limiter interface Rate limiter interface
@ -1449,6 +1474,12 @@
<param name="type">The type</param> <param name="type">The type</param>
<returns>Average fill price</returns> <returns>Average fill price</returns>
</member> </member>
<member name="M:CryptoExchange.Net.Interfaces.ISymbolOrderBook.ToString(System.Int32)">
<summary>
String representation of the top x entries
</summary>
<returns></returns>
</member>
<member name="T:CryptoExchange.Net.Interfaces.ISymbolOrderBookEntry"> <member name="T:CryptoExchange.Net.Interfaces.ISymbolOrderBookEntry">
<summary> <summary>
Interface for order book entries Interface for order book entries
@ -3576,11 +3607,6 @@
The topic of the update, what symbol/asset etc.. The topic of the update, what symbol/asset etc..
</summary> </summary>
</member> </member>
<member name="P:CryptoExchange.Net.Sockets.DataEvent`1.Event">
<summary>
The event that triggered the update
</summary>
</member>
<member name="P:CryptoExchange.Net.Sockets.DataEvent`1.OriginalData"> <member name="P:CryptoExchange.Net.Sockets.DataEvent`1.OriginalData">
<summary> <summary>
The original data that was received, only available when OutputOriginalData is set to true in the client options The original data that was received, only available when OutputOriginalData is set to true in the client options
@ -3599,14 +3625,13 @@
<param name="data">The new data</param> <param name="data">The new data</param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:CryptoExchange.Net.Sockets.DataEvent`1.As``1(``0,System.String,System.String)"> <member name="M:CryptoExchange.Net.Sockets.DataEvent`1.As``1(``0,System.String)">
<summary> <summary>
Create a new DataEvent with data in the from of type K based on the current DataEvent. OriginalData and Timestamp will be copied over Create a new DataEvent with data in the from of type K based on the current DataEvent. OriginalData and Timestamp will be copied over
</summary> </summary>
<typeparam name="K">The type of the new data</typeparam> <typeparam name="K">The type of the new data</typeparam>
<param name="data">The new data</param> <param name="data">The new data</param>
<param name="topic">The new topic</param> <param name="topic">The new topic</param>
<param name="event">The new event</param>
<returns></returns> <returns></returns>
</member> </member>
<member name="T:CryptoExchange.Net.Sockets.MessageEvent"> <member name="T:CryptoExchange.Net.Sockets.MessageEvent">
@ -3951,9 +3976,7 @@
<member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})"> <member name="M:CryptoExchange.Net.Sockets.WebsocketFactory.CreateWebsocket(CryptoExchange.Net.Logging.Log,System.String,System.Collections.Generic.IDictionary{System.String,System.String},System.Collections.Generic.IDictionary{System.String,System.String})">
<inheritdoc /> <inheritdoc />
</member> </member>
</members> <member name="T:System.Diagnostics.CodeAnalysis.AllowNullAttribute">
</doc>
System.Diagnostics.CodeAnalysis.AllowNullAttribute">
<summary> <summary>
Specifies that <see langword="null"/> is allowed as an input even if the Specifies that <see langword="null"/> is allowed as an input even if the
corresponding type disallows it. corresponding type disallows it.

View File

@ -0,0 +1,14 @@
namespace CryptoExchange.Net.Interfaces
{
/// <summary>
/// A provider for a nonce value used when signing requests
/// </summary>
public interface INonceProvider
{
/// <summary>
/// Get nonce value. Nonce value should be unique and incremental for each call
/// </summary>
/// <returns>Nonce value</returns>
long GetNonce();
}
}

View File

@ -100,5 +100,11 @@ namespace CryptoExchange.Net.Interfaces
/// <param name="type">The type</param> /// <param name="type">The type</param>
/// <returns>Average fill price</returns> /// <returns>Average fill price</returns>
CallResult<decimal> CalculateAverageFillPrice(decimal quantity, OrderBookEntryType type); CallResult<decimal> CalculateAverageFillPrice(decimal quantity, OrderBookEntryType type);
/// <summary>
/// String representation of the top x entries
/// </summary>
/// <returns></returns>
string ToString(int rows);
} }
} }