Skip to content

Commit

Permalink
changed nonce calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
semashkinvg committed Jul 18, 2018
1 parent 0c0ad38 commit 4e0c4b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
40 changes: 20 additions & 20 deletions Bitmex.NET/Authorization/NonceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace Bitmex.NET.Authorization
{
public interface INonceProvider
{
long GetNonce();
}
public class NonceProvider : INonceProvider
{
private static long _lastNonce = 0;
public long GetNonce()
{
var yearBegin = new DateTime(1990, 1, 1);
var newNonce = DateTime.UtcNow.Ticks - yearBegin.Ticks;
if (_lastNonce < newNonce)
{
Interlocked.Exchange(ref _lastNonce, newNonce);
return _lastNonce;
}
public interface INonceProvider
{
long GetNonce();
}
public class NonceProvider : INonceProvider
{
private static long _lastNonce = 0;
public long GetNonce()
{
var yearBegin = new DateTime(1970, 1, 1);
var newNonce = Convert.ToInt64(Math.Floor((DateTime.UtcNow - yearBegin).TotalSeconds));
if (_lastNonce < newNonce)
{
Interlocked.Exchange(ref _lastNonce, newNonce);
return _lastNonce;
}

Interlocked.Increment(ref _lastNonce);
return _lastNonce;
}
}
Interlocked.Increment(ref _lastNonce);
return _lastNonce;
}
}
}
2 changes: 1 addition & 1 deletion releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes

## 2.0.26.0
## 2.0.30.0
Fixed authentication issues. Currently, nonce became in seconds rather than in milliseconds, according to the official reference

## 2.0.2.*
Expand Down

0 comments on commit 4e0c4b3

Please sign in to comment.