-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated examples Updated CryptoExchange.Net to v8.1.0 Moved FormatSymbol to BybitExchange class Added support Side setting on SharedTrade model Added BybitTrackerFactory Added overload to Create method on BybitOrderBookFactory support SharedSymbol parameter
- Loading branch information
Showing
21 changed files
with
455 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using Bybit.Net.Clients; | ||
using Bybit.Net.Interfaces; | ||
using Bybit.Net.Interfaces.Clients; | ||
using CryptoExchange.Net; | ||
using CryptoExchange.Net.SharedApis; | ||
using CryptoExchange.Net.Trackers.Klines; | ||
using CryptoExchange.Net.Trackers.Trades; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
|
||
namespace Bybit.Net | ||
{ | ||
/// <inheritdoc /> | ||
public class BybitTrackerFactory : IBybitTrackerFactory | ||
{ | ||
private readonly IServiceProvider? _serviceProvider; | ||
|
||
/// <summary> | ||
/// ctor | ||
/// </summary> | ||
public BybitTrackerFactory() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// ctor | ||
/// </summary> | ||
/// <param name="serviceProvider">Service provider for resolving logging and clients</param> | ||
public BybitTrackerFactory(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IKlineTracker CreateKlineTracker(SharedSymbol symbol, SharedKlineInterval interval, int? limit = null, TimeSpan? period = null) | ||
{ | ||
var restClient = _serviceProvider?.GetRequiredService<IBybitRestClient>() ?? new BybitRestClient(); | ||
var socketClient = _serviceProvider?.GetRequiredService<IBybitSocketClient>() ?? new BybitSocketClient(); | ||
|
||
IKlineRestClient sharedRestClient; | ||
IKlineSocketClient sharedSocketClient; | ||
if (symbol.TradingMode == TradingMode.Spot) | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5SpotApi.SharedClient; | ||
} | ||
else if (symbol.TradingMode.IsLinear()) | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5LinearApi.SharedClient; | ||
} | ||
else | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5InverseApi.SharedClient; | ||
} | ||
|
||
return new KlineTracker( | ||
_serviceProvider?.GetRequiredService<ILoggerFactory>().CreateLogger(restClient.Exchange), | ||
sharedRestClient, | ||
sharedSocketClient, | ||
symbol, | ||
interval, | ||
limit, | ||
period | ||
); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null, TimeSpan? period = null) | ||
{ | ||
var restClient = _serviceProvider?.GetRequiredService<IBybitRestClient>() ?? new BybitRestClient(); | ||
var socketClient = _serviceProvider?.GetRequiredService<IBybitSocketClient>() ?? new BybitSocketClient(); | ||
|
||
IRecentTradeRestClient? sharedRestClient = null; | ||
ITradeSocketClient sharedSocketClient; | ||
if (symbol.TradingMode == TradingMode.Spot) | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5SpotApi.SharedClient; | ||
} | ||
else if (symbol.TradingMode.IsLinear()) | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5LinearApi.SharedClient; | ||
} | ||
else | ||
{ | ||
sharedRestClient = restClient.V5Api.SharedClient; | ||
sharedSocketClient = socketClient.V5InverseApi.SharedClient; | ||
} | ||
|
||
return new TradeTracker( | ||
_serviceProvider?.GetRequiredService<ILoggerFactory>().CreateLogger(socketClient.Exchange), | ||
sharedRestClient, | ||
null, | ||
sharedSocketClient, | ||
symbol, | ||
limit, | ||
period | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using CryptoExchange.Net.SharedApis; | ||
using CryptoExchange.Net.Trackers.Klines; | ||
using CryptoExchange.Net.Trackers.Trades; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Bybit.Net.Interfaces | ||
{ | ||
/// <summary> | ||
/// Tracker factory | ||
/// </summary> | ||
public interface IBybitTrackerFactory | ||
{ | ||
/// <summary> | ||
/// Create a new kline tracker | ||
/// </summary> | ||
/// <param name="symbol">The symbol</param> | ||
/// <param name="interval">Kline interval</param> | ||
/// <param name="limit">The max amount of klines to retain</param> | ||
/// <param name="period">The max period the data should be retained</param> | ||
/// <returns></returns> | ||
IKlineTracker CreateKlineTracker(SharedSymbol symbol, SharedKlineInterval interval, int? limit = null, TimeSpan? period = null); | ||
|
||
/// <summary> | ||
/// Create a new trade tracker for a symbol | ||
/// </summary> | ||
/// <param name="symbol">The symbol</param> | ||
/// <param name="limit">The max amount of klines to retain</param> | ||
/// <param name="period">The max period the data should be retained</param> | ||
/// <returns></returns> | ||
ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null, TimeSpan? period = null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.