Releases: sonvister/Binance
0.2.0-beta1
Available on NuGet.
Initial Beta Release
Changes:
- Add new
IBinanceApi.GetWithdrawFeeAsync()
. - Add
BinanceUnknownStatusException
message (for #77). - BREAKING: Rename
GetTradesAsync()
extension toGetAccountTradesAsync()
. - BREAKING: Remove
ClientOrder.Time
(refer toOrder.Time
instead).- Remove
IsNotPlaced()
extension method (an order will exist or query API for status). - Make
ClientOrder.Side
nullable (must be explicitly set before placing order).
- Remove
- BREAKING: Add
IRateLimiterProvider
andIApiRateLimiterProvider
.- Replace ApiRateLimiter(null) and BinanceApiUserProvider(null) with default constructors.
- FIX: Add
recvWindow
parameter toGetDepositAddressAsync()
andGetAccountStatusAsync()
. - FIX:
IBinanceApi.CancelAllOrdersAsync()
. - Update static assets and symbols.
0.2.0-alpha41
Available on NuGet.
Changes:
- FIX: Publisher
Unsubscribe()
not triggering automatic stream control (#76 - thanks @rakewell). - FIX: Cache
SubscribedStreams
returned clientSubscribedStreams
instead of cache-related subscriptions. - FIX:
BinanceHttpClient
message event subject was notAbsoluteUri
. - Make
GetStreamName(...)
public static
on clients (AggregateTradeClient
, etc.) - Minor updates and improvements.
- Update static assets and symbols (ONT).
0.2.0-alpha40
Available on NuGet.
This release includes significant refactoring including removal of the web socket client and cache managers (functionality relocated) and removal of several namespaces (to simplify usage). The automatic streaming start/stop feature has been moved from the managers to a lower-level and is now a built-in part of the I...WebSocketClient
implementations (the IUserDataWebSocketManager
and composite managers remain). For those not wanting the automatic stream control, look to the IBinanceWebSocketStream
and I...Client
'advanced' implementations. Examples and sample applications have been updated.
The fundamental change in this release is the separation of IJsonStream
into a simpler IJsonStream
and the new IJsonPublisher
(both are JSON producers). The publisher handles subscriptions for the combined stream functionality where the web socket stream URI is automatically modified and changes to the URI trigger the automatic web socket abort and re-connect.
The architecture diagram has been updated.
Changes:
- FIX:
SymbolStatisticCache
link to client and unsubscribe for #75. (thanks @tompetko). - BREAKING: Remove all
...ClientManager
and...CacheManager
classes moving functionality to existing...WebSocketClient
and new...WebSocketCache
.- Move
IWatchdogTimer
toIJsonStreamController
(monitors JSON producer/stream rather than client data). - Move
IJsonStreamController
to newIAutoJsonStreamPublisher
.
- Move
- BREAKING: Remove several namespaces including Api, Market, Account, Account.Orders, etc.
- BREAKING: Change
IJsonProvider
toIJsonProducer
,IJsonObserver
toIJsonSubscriber
,ObservedStreams
property toSubscribedStreams
, andProvidesStreams
property toPublishedStreams
. - BREAKING: Remove cancellation token from client events (expect to be handled quickly and synchronously).
- BREAKING: Move all controllers to
Utility
namespace. - Add delay when calculating average timestamp offset.
- Add
IWatchdogTimer.IsEnabled
control. - Update static assets and symbols.
0.2.0-alpha39
Available on NuGet.
Changes:
- Add web socket cache managers (e.g.
IAggregateTradeWebSocketCacheManager
) and update sample apps. - BREAKING: Replace
IBinanceHttpClient.Options
(for #24).- Replace
IBinanceHttpClient.Options.RecvWindowDefault
withIBinanceHttpClient.DefaultRecvWindow
. - Replace
IBinanceHttpClient.Options.TimestampOffsetRefreshPeriodMinutes
withIBinanceHttpClient.TimestampProvider.TimestampOffsetRefreshPeriod
.
- Replace
- Add extensions for simpler
ClientOrder
validation. - Remove superficial sample applications.
- Update static assets and symbols.
0.2.0-alpha38
Available on NuGet.
Changes:
- Add
IWebSocketClient
extension to wait until web socket is open (for #71).- Add
IWebSocketClient.IsOpen
flag.
- Add
- Add to and improve logging (change log levels to reduce the amount of reported 'errors').
- Return
IJsonStream
on subscribe/unsubscribe to allow chaining. - Update application file logger to display inner exceptions.
- Update static assets and symbols.
0.2.0-alpha37
Available on NuGet.
Changes:
- Modify
TaskController
andRetryTaskController
:- Add optional logger and logging to task controller operations.
- Add
Pausing
andResuming
events toIRetryTaskController
(for issue #50). - BREAKING: Remove redundant task controller error action from constructor (use
Error
event instead).
- BREAKING/FIX: Change
OrderExecutionEventArgs.OrderRejectedReason
type from enum to string. - FIX: Streaming of all symbol statistics (BinanceWebSocketStream parsing of JSON array).
- Minor updates and improvements.
- Update sample applications.
0.2.0-alpha36
Available on NuGet.
Changes:
- Improve JSON client subscribe/unsubscribe usability.
- Add extensions to subscribe/unsubscribe multiple symbols.
- Return JSON client from subscribe/unsubscribe to allow chaining calls.
- Change timestamp parameters to
DateTime
(uselong.ToDateTime()
for easy conversion).- BREAKING: Change
IBinanceApi
andIBinanceHttpClient
GetDepositsAsync()
andGetWithdrawalsAsync()
timestamp parameters toDateTime
. - BREAKING: Change
IBinanceApi.GetCandlesticksAsync()
timestamps toDateTime
. - BREAKING: Remove
IBinanceApi.GetAggregateTradesIn()
.
- BREAKING: Change
- Add unit tests for JSON clients.
- Update sample applications.
0.2.0-alpha35
Available on NuGet.
This release includes a redesign of the automatic web socket manager IBinanceWebSocketManager
, which allowed applications to use client interfaces (subscribe/unsubscribe) without needing to handle the required stream cancellation and restart. That functionality has been moved to a lower level but the usability remains in the new IBinanceWebSocketClientManager
. Also, there are new discrete automatic web socket managers for each of the Binance endpoints (e.g. ITradeWebSocketClientManager
, etc.).
Changes (significant refactoring of web sockets and caches with new managers):
- Add
IJsonClientManager
and implementations (provide automatic stream controller management). - Add
IJsonStream
,IJsonStreamObserver
,IJsonClient
, andIJsonStreamClient
.BinanceWebSocketStream
subscribe/unsubscribe can be done while streaming.IUserDataClient
allows callbacks to be defined for specific event types.
- Add
IJsonProvider
andJsonMessageEventArgs
(provides low-level access to JSON data).- Implement in
BinanceHttpClient
andDefaultWebSocketClient
.
- Implement in
- Add
IJsonClientCache
(caches no longer have reference to stream).- BREAKING: Remove
StreamAsync()
andSubscribeAndStream()
. - BREAKING: Remove
LinkTo()
andUnlink()
(setIJsonClientCache.Client
instead).
- BREAKING: Remove
- BREAKING:
IBinanceWebSocketManager
is nowIBinanceWebSocketClientManager
. - BREAKING: Move
Binance.WebSocket.Events
toBinance.Client.Events
namespace. - BREAKING: Low-level
IWebSocketClient
propertyWebSocket.Client
is nowStream.WebSocket
. - BREAKING:
ISymbolStatisticsClient
subscribe/unsubscribe method parameters rearranged. - BREAKING: Web socket events no longer duplicated in higher level interfaces.
- BREAKING: Remove user data options (and probably other things not mentioned).
- Add example usage of managers and update all sample applications.
- Add
HttpClientTimeoutDefaultSeconds
configuration option (for #64). - Update static assets and symbols.
Documentation
The purpose of this document is to describe the core separation of JSON producers and consumers and how they form the layered architecture of this library as well as to explain the is-a and has-a relationships of the interfaces and implementations of this library.
This is not intended to be a 'how-to' guide. Currently, the sample applications still offer the best demonstrations and example use of this library. For those looking for the simplest application-level development, consider using the new web socket client managers or the composite IBinanceWebSocketClientManager
.
Architecture Diagram (partial)
IJsonProvider
This fundamental interface defines a JSON message provider. This can be anything that produces JSON messages (in Binance format or otherwise) such as a Web Socket, HTTP client, or database API (for back-testing/simulation).
public interface IJsonProvider
{
event EventHandler<JsonMessageEventArgs> Message;
}
NOTE: Application-level development will typically not use this 'low-level' event for anything other than logging or troubleshooting. Also, since some JSON data can contain sensitive information, this is no longer logged automatically as of this release (but, can still be logged at the application-level using this event).
JsonMessageEventArgs
The JSON message event arguments include the message data as a JSON object or array and the message Subject
, which defines the context of the message. For instance, the IBinanceHttpClient
and IWebSocketClient
implementations use their respective URI.AbsolutePath
as the message subject, while IJsonStream
implementations use the stream name.
public sealed class JsonMessageEventArgs
{
public string Subject { get; }
public string Json { get; }
}
NOTE: When using combined streams, the IWebSocketClient
message is the raw
JSON before being separated into stream name and data.
IBinanceHttpClient
This is the IJsonProvider
interface to the Binance REST API using a single HttpClient
that returns 'raw' JSON. The specific methods are implemented as extensions in BinanceHttpClientExtensions
. New capabilities can be added as extensions of IBinanceHttpClient
in a similar fashion (at the application level) utilizing the shared, singleton, BinanceHttpClient
.
Deserialization
The top-level IBinanceAPI
interface deserializes the JSON data from IBinanceHttpClient
into convenient domain value-objects. All of the deserializers used in BinanceApi
are available in the Binance.Serialization
namespace for application-level deserialization of 'raw' Binance JSON data (for instance, if stored for back-testing/simulation).
IJsonStream
This defines an abstract, streaming, JSON provider. New message notification is sent to subscribed observers or Message
event handlers, where the message subject is the stream name. When subscribing to a stream, the observer is optional (if using an event handler instead). The ProvidedStreams
property lists the unique stream names that are currently subscribed.
Streaming is controlled by calling the StreamAsync
method and by providing a required CancellationToken
to abort the streaming operation. The stream is 'closed' when the Task
has completed (and IsStreaming
is false
). There is no Error
event because exceptions can and should be caught with try/catch (when using async
) or with the AggregateException
via the returned Task
.
NOTE: Users of this library are expected to be familiar with TAP.
NOTE: The IJsonStream
implementations handle subscribe/unsubscribe of streams whether streaming is active or not. However (depending on the implementation), if changes are made while streaming, the flow of data may be interrupted (this is the case with BinanceWebSocketStream
since the web socket client must be aborted and another connection established with a new URI).
public interface IJsonStream : IJsonProvider
{
bool IsStreaming { get; }
IEnumerable<string> ProvidedStreams { get; }
void Subscribe(IJsonStreamObserver observer, params string[] streamNames);
void Unsubscribe(IJsonStreamObserver observer, params string[] streamNames);
Task StreamAsync(CancellationToken token);
IBufferedJsonProvicer
This IJsonProvider
decorator buffers data from another JSON provider.
public interface IBufferedJsonProvider<TProvider> : IJsonProvider
where TProvider : IJsonProvider
{
TProvider JsonProvider { get; }
}
IWebSocketStream
This interface defines a specific implementation of IJsonStream
that uses a 'low-level' IWebSocketClient
to provide JSON data, which can be accessed via the WebSocket
property. The extending IBinanceWebSocketStream
interface provides an additional IsCombined
property.
NOTE: An IWebSocketStream
is not an IWebSocketClient
. The IWebSocketStream
is a specific form of IJsonStream
that uses an IWebSocketClient
. The IWebSocketClient.StreamAsync()
method combines connect with receive operations and returns a Task
, in-part, controlled by the IJsonStream
. The Open
event is raised after a connection is established. The Close
event is raised just before the Task
completes. Stream controllers need only manage the StreamAsync()
returned Task
and not concern themselves with the implementation details of the IJsonStream
(i.e. the Open
and Close
events).
public interface IWebSocketClient : IJsonProvider
{
event EventHandler<EventArgs> Open;
event EventHandler<EventArgs> Close;
bool IsStreaming { get; }
Task StreamAsync(Uri uri, CancellationToken token);
}
public interface IWebSocketStream : IJsonStream
{
IWebSocketClient WebSocket { get; }
}
public interface IBinanceWebSocketStream : IWebSocketStream
{
bool IsCombined { get; }
}
IJsonStreamObserver
This interface provides a means of identifying classes as observers of a IJsonStream
as passed to the subscribe/unsubscribe methods as well as providing the ability to handle message events asynchronously. Any class can make use the IJsonProvider.Message
event, but that event handler will receive all 'raw' JSON messages (depending on context of the event).
public interface IJsonStreamObserver
{
Task HandleMessageAsync(string stream, string json, CancellationToken token = default);
}
IJsonClient
These JSON stream observers have the capability of deserializing JSON into higher-level objects and providing notification via subscribed callbacks and/or non-specific events. Each Binance implementation is responsible for interpreting JSON from one or more of the official web socket endpoints.
public interface IJsonClient : IJsonStreamObserver
{
IEnumerable<string> ObservedStreams { get; }
void Unsubscribe();
}
NOTE: As JSON observers, the clients, can be used to process JSON from any compatible IJsonProvider
implementation.
IAggregateTradeClient
Processes JSON data from Aggregate Trade streams. When subscribing or unsubscribing, the callback is optional (extension methods are available).
public interface IAggregateTrad...
0.2.0-alpha34
Available on NuGet.
Changes (same as 0.2.0-alpha32):
- FIX: Revert code back to 0.2.0-alpha32 for issue #60 (thanks @pavlexander).
0.2.0-alpha33
UNLISTED on NuGet.
For Testing Only
Changes (same as 0.2.0-alpha31 and alpha32):
- FIX: Testing changes for issue #60 (@pavlexander).