Skip to content

Commit a4e0c45

Browse files
authored
Merge pull request #13 from codez0mb1e/release_v0.4
Prepare to pre-release v0.4
2 parents 70a9a84 + 18ae0e6 commit a4e0c45

File tree

5 files changed

+38
-27
lines changed

5 files changed

+38
-27
lines changed

src/BinanceBot.Market/Configurations/MarketStrategyConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public record MarketStrategyConfiguration
3030

3131

3232
/// <summary>
33-
/// Precision of the quote asset
33+
/// Precision of the base asset
3434
/// </summary>
35-
public int QuoteAssetPrecision { get; set; }
35+
public int BaseAssetPrecision { get; set; }
3636

3737
/// <summary>
3838
/// Price precision

src/BinanceBot.Market/MarketDepthManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using Binance.Net.Interfaces.Clients;
44
using Binance.Net.Objects.Models.Spot;
5+
using BinanceBot.Market.Core;
56
using CryptoExchange.Net.Objects;
67

78

src/BinanceBot.Market/MarketMakerBot.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Binance.Net.Enums;
77
using Binance.Net.Interfaces.Clients;
88
using Binance.Net.Objects.Models.Spot;
9+
using BinanceBot.Market.Core;
10+
using BinanceBot.Market.Strategies;
911
using CryptoExchange.Net.Objects;
1012
using NLog;
1113

@@ -87,28 +89,36 @@ public override async Task<BinancePlacedOrder> CreateOrderAsync(CreateOrderReque
8789
{
8890
if (order == null) throw new ArgumentNullException(nameof(order));
8991

90-
#if TEST_ORDER_CREATION_MODE
92+
#if TEST_ORDER_CREATION_MODE
9193
WebCallResult<BinancePlacedOrder> response = await _binanceRestClient.SpotApi.Trading.PlaceTestOrderAsync(
92-
order.Symbol, order.Side, order.OrderType, order.Quantity,
93-
newClientOrderId:order.NewClientOrderId,
94-
receiveWindow:order.RecvWindow)
94+
// general
95+
order.Symbol,
96+
order.Side,
97+
order.OrderType,
98+
// price-quantity
99+
price: order.Price,
100+
quantity: order.Quantity,
101+
// metadata
102+
newClientOrderId: order.NewClientOrderId,
103+
timeInForce: order.TimeInForce,
104+
receiveWindow: order.RecvWindow)
95105
.ConfigureAwait(false);
96-
#else
106+
#else
97107
WebCallResult<BinancePlacedOrder> response = await _binanceRestClient.SpotApi.Trading.PlaceOrderAsync(
98108
// general
99-
order.Symbol,
100-
order.Side,
109+
order.Symbol,
110+
order.Side,
101111
order.OrderType,
102112
// price-quantity
103-
price: order.Price,
113+
price: order.Price,
104114
quantity: order.Quantity,
105115
// metadata
106116
newClientOrderId: order.NewClientOrderId,
107117
timeInForce: order.TimeInForce,
108118
receiveWindow: order.RecvWindow)
109119
.ConfigureAwait(false);
110-
#endif
111-
120+
#endif
121+
112122
if (response.Error != null)
113123
Logger.Error(response.Error.Message);
114124

@@ -160,9 +170,9 @@ private async Task OnMarketBestPairChanged(object sender, MarketBestPairChangedE
160170
OrderType = SpotOrderType.Limit,
161171
// price-quantity
162172
Price = Decimal.Round(q.Price, decimals: MarketStrategy.Config.PricePrecision),
163-
Quantity = Decimal.Round(q.Volume, decimals: MarketStrategy.Config.QuoteAssetPrecision),,
173+
Quantity = Decimal.Round(q.Volume, decimals: MarketStrategy.Config.BaseAssetPrecision),
164174
// metadata
165-
NewClientOrderId = "test",
175+
NewClientOrderId = $"market-bot-{Guid.NewGuid():N}".Substring(0, 36),
166176
TimeInForce = TimeInForce.GoodTillCanceled,
167177
RecvWindow = (int)MarketStrategy.Config.ReceiveWindow.TotalMilliseconds
168178
};

src/BinanceBot.MarketBot.Console/Program.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Binance.Net.Clients;
5+
using Binance.Net.Enums;
46
using Binance.Net.Interfaces.Clients;
57
using Binance.Net.Objects;
68
using BinanceBot.Market;
@@ -21,7 +23,7 @@ internal static class Program
2123
private const string Secret = "***";
2224

2325
// WARN: set necessary token here
24-
private const string Symbol = "DOGEBTC";
26+
private const string Symbol = "SOLUSDT";
2527
private static readonly TimeSpan ReceiveWindow = TimeSpan.FromMilliseconds(1000);
2628
#endregion
2729

@@ -38,12 +40,12 @@ static async Task Main(string[] args)
3840

3941
// 2. test connection
4042
Logger.Info("Testing connection...");
41-
var pingAsyncResult = await binanceRestClient.PingAsync();
43+
var pingAsyncResult = await binanceRestClient.SpotApi.ExchangeData.PingAsync();
4244
Logger.Info($"Ping {pingAsyncResult.Data} ms");
4345

4446

4547
// 2.1. check permissions
46-
var permissionsResponse = await binanceRestClient.General.GetAPIKeyPermissionsAsync();
48+
var permissionsResponse = await binanceRestClient.SpotApi.Account.GetAPIKeyPermissionsAsync();
4749
if (!permissionsResponse.Success)
4850
{
4951
Logger.Error($"{permissionsResponse.Error?.Message}");
@@ -57,12 +59,12 @@ static async Task Main(string[] args)
5759

5860

5961
// 3. set bot strategy config
60-
var exchangeInfoResult = binanceRestClient.Spot.System.GetExchangeInfoAsync(Symbol);
62+
var exchangeInfoResult = binanceRestClient.SpotApi.ExchangeData.GetExchangeInfoAsync(Symbol);
6163

6264
var symbolInfo = exchangeInfoResult.Result.Data.Symbols
6365
.Single(s => s.Name.Equals(Symbol, StringComparison.InvariantCultureIgnoreCase));
6466

65-
if (!(symbolInfo.Status == SymbolStatus.Trading && symbolInfo.OrderTypes.Contains(OrderType.Market)))
67+
if (!(symbolInfo.Status == SymbolStatus.Trading && symbolInfo.OrderTypes.Contains(SpotOrderType.Market)))
6668
{
6769
Logger.Error($"Symbol {symbolInfo.Name} doesn't suitable for this strategy");
6870
return;
@@ -85,10 +87,10 @@ static async Task Main(string[] args)
8587
// WARN: set thresholds for strategy here
8688
var strategyConfig = new MarketStrategyConfiguration
8789
{
88-
TradeWhenSpreadGreaterThan = .02M, // or 0.02%, (price spread*min_volume) should be greater than broker's commissions for trade
90+
TradeWhenSpreadGreaterThan = .05M, // or 0.05%, (price spread*min_volume) should be greater than broker's commissions for trade
8991
MinOrderVolume = symbolInfo.LotSizeFilter.MinQuantity*10,
9092
MaxOrderVolume = symbolInfo.LotSizeFilter.MinQuantity*100,
91-
QuoteAssetPrecision = symbolInfo.QuoteAssetPrecision,
93+
BaseAssetPrecision = symbolInfo.BaseAssetPrecision,
9294
PricePrecision = pricePrecision,
9395
ReceiveWindow = ReceiveWindow
9496
};

src/BinanceBot.MarketViewer.Console/Program.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Linq;
3-
using System.Threading;
43
using System.Threading.Tasks;
54
using Binance.Net.Clients;
65
using Binance.Net.Interfaces.Clients;
@@ -23,13 +22,12 @@ internal static class Program
2322
private const string Secret = "***";
2423

2524
// WARN: Set necessary token here
26-
private const string Symbol = "DOGEBTC";
25+
private const string Symbol = "SOLUSDT";
2726
private const int OrderBookDepth = 10;
2827
private static readonly TimeSpan? OrderBookUpdateLimit = TimeSpan.FromMilliseconds(1000);
2928
#endregion
3029

3130
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
32-
private static readonly ApiCredentials Credentials = new(Key, Secret);
3331

3432

3533
static async Task Main(string[] args)
@@ -42,7 +40,7 @@ static async Task Main(string[] args)
4240

4341
// 2. test connection
4442
Logger.Info("Testing connection...");
45-
var pingResult = await binanceRestClient.PingAsync();
43+
var pingResult = await binanceRestClient.SpotApi.ExchangeData.PingAsync();
4644
Logger.Info($"Ping time: {pingResult.Data} ms");
4745

4846

@@ -62,8 +60,8 @@ static async Task Main(string[] args)
6260
{
6361
LastUpdate = e.UpdateTime,
6462

65-
Asks = e.Asks.Reverse().Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}"),
66-
Bids = e.Bids.Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}")
63+
Asks = e.Asks.OrderByDescending(q => q.Price).Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}"),
64+
Bids = e.Bids.OrderByDescending(q => q.Price).Take(OrderBookDepth).Select(s => $"{s.Price} : {s.Volume}")
6765
},
6866
Formatting.Indented));
6967

0 commit comments

Comments
 (0)