переход на секционированные стаканы
test / deploy_trader_prod (push) Successful in 8m4s
Details
test / deploy_trader_prod (push) Successful in 8m4s
Details
parent
9a5fedb41c
commit
f49d4a9134
|
@ -3,43 +3,43 @@
|
|||
public static class BotModeSwitcher
|
||||
{
|
||||
private readonly static object _locker = new();
|
||||
private static bool _canSell = true;
|
||||
private static bool _canPurchase = true;
|
||||
private static bool _canClose = true;
|
||||
private static bool _canOpen = false;
|
||||
|
||||
public static bool CanSell()
|
||||
public static bool CanClose()
|
||||
{
|
||||
lock (_locker)
|
||||
return _canSell;
|
||||
return _canClose;
|
||||
}
|
||||
|
||||
public static bool CanPurchase()
|
||||
public static bool CanOpen()
|
||||
{
|
||||
lock (_locker)
|
||||
return _canPurchase;
|
||||
return _canOpen;
|
||||
}
|
||||
|
||||
public static void StopSelling()
|
||||
public static void StopClosing()
|
||||
{
|
||||
lock (_locker)
|
||||
_canSell = false;
|
||||
_canClose = false;
|
||||
}
|
||||
|
||||
public static void StopPurchase()
|
||||
public static void StopOpening()
|
||||
{
|
||||
lock (_locker)
|
||||
_canPurchase = false;
|
||||
_canOpen = false;
|
||||
}
|
||||
|
||||
public static void StartSelling()
|
||||
public static void StartClosing()
|
||||
{
|
||||
lock (_locker)
|
||||
_canSell = true;
|
||||
_canClose = true;
|
||||
}
|
||||
|
||||
public static void StartPurchase()
|
||||
public static void StartOpening()
|
||||
{
|
||||
lock (_locker)
|
||||
_canPurchase = true;
|
||||
_canOpen = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,15 @@
|
|||
public const string DisableTrading = "Стоп торги";
|
||||
public const string EnableTrading = "Старт торги";
|
||||
|
||||
public const string DisableSelling = "Выключить продажи";
|
||||
public const string EnableSelling = "Включить продажи";
|
||||
public const string DisableClosing = "Выключить продажи";
|
||||
public const string DisableClosing2 = "Выключить закрытия";
|
||||
public const string EnableClosing = "Включить продажи";
|
||||
public const string EnableClosing2 = "Включить закрытия";
|
||||
|
||||
public const string DisablePurchases = "Выключить покупки";
|
||||
public const string EnablePurchases = "Включить покупки";
|
||||
public const string DisableOpening = "Выключить покупки";
|
||||
public const string DisableOpening2 = "Выключить открытия";
|
||||
public const string EnableOpening = "Включить покупки";
|
||||
public const string EnableOpening2 = "Включить открытия";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,8 @@ namespace KLHZ.Trader.Core.DataLayer
|
|||
{
|
||||
entity.HasKey(e1 => new { e1.Time, e1.Id });
|
||||
entity.Ignore(e1 => e1.IsHistoricalData);
|
||||
entity.Property(p => p.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
entity.Property(e => e.Time)
|
||||
.HasConversion(
|
||||
v => v.ToUniversalTime(),
|
||||
|
@ -77,6 +79,8 @@ namespace KLHZ.Trader.Core.DataLayer
|
|||
modelBuilder.Entity<OrderbookElement>(entity =>
|
||||
{
|
||||
entity.HasKey(e1 => new { e1.Time, e1.Id });
|
||||
entity.Property(p => p.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
entity.Property(e => e.Time)
|
||||
.HasConversion(
|
||||
v => v.ToUniversalTime(),
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
|
||||
var lastUpdateDict = new Dictionary<string, PriceChange>();
|
||||
var pricesBuffer = new List<Trade>();
|
||||
var orderbookItemsBuffer = new List<OrderbookItem>();
|
||||
var orderbookItemsBuffer = new List<OrderbookElement>();
|
||||
var lastWrite = DateTime.UtcNow;
|
||||
await foreach (var response in stream.ResponseStream.ReadAllAsync())
|
||||
{
|
||||
|
@ -162,7 +162,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
if (response.Orderbook != null)
|
||||
{
|
||||
|
||||
var asks = response.Orderbook.Asks.Take(4).Select(a => new OrderbookItem()
|
||||
var asks = response.Orderbook.Asks.Take(4).Select(a => new OrderbookElement()
|
||||
{
|
||||
Count = a.Quantity,
|
||||
Price = a.Price,
|
||||
|
@ -172,7 +172,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
Time = response.Orderbook.Time.ToDateTime().ToUniversalTime(),
|
||||
}).ToArray();
|
||||
|
||||
var bids = response.Orderbook.Bids.Take(4).Select(a => new OrderbookItem()
|
||||
var bids = response.Orderbook.Bids.Take(4).Select(a => new OrderbookElement()
|
||||
{
|
||||
Count = a.Quantity,
|
||||
Price = a.Price,
|
||||
|
@ -208,7 +208,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
lastWrite = DateTime.UtcNow;
|
||||
if (orderbookItemsBuffer.Count > 0)
|
||||
{
|
||||
await context.OrderbookItems.AddRangeAsync(orderbookItemsBuffer);
|
||||
await context.OrderbookElements.AddRangeAsync(orderbookItemsBuffer);
|
||||
orderbookItemsBuffer.Clear();
|
||||
}
|
||||
if (pricesBuffer.Count > 0)
|
||||
|
|
|
@ -719,7 +719,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
{
|
||||
var stops = st.GetStops(PositionType.Long);
|
||||
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase())
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanOpen())
|
||||
{
|
||||
var accounts = _portfolioWrapper.Accounts
|
||||
.Where(a => !a.Value.Assets.ContainsKey(message.Figi))
|
||||
|
@ -740,7 +740,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
)
|
||||
{
|
||||
var stops = st.GetStops(PositionType.Short);
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase())
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanOpen())
|
||||
{
|
||||
var accounts = _portfolioWrapper.Accounts
|
||||
.Where(a => !a.Value.Assets.ContainsKey(message.Figi))
|
||||
|
@ -758,7 +758,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
}
|
||||
if (result[TradingEvent.CloseLong] >= Constants.UppingCoefficient)
|
||||
{
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanSell())
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanClose())
|
||||
{
|
||||
var assetsForClose = _portfolioWrapper.Accounts
|
||||
.SelectMany(a => a.Value.Assets.Values)
|
||||
|
@ -772,7 +772,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
|||
|
||||
if (result[TradingEvent.CloseShort] >= Constants.UppingCoefficient)
|
||||
{
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanPurchase())
|
||||
if (!message.IsHistoricalData && BotModeSwitcher.CanClose())
|
||||
{
|
||||
var assetsForClose = _portfolioWrapper.Accounts
|
||||
.SelectMany(a => a.Value.Assets.Values)
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace KLHZ.Trader.Core.Exchange.Utils
|
|||
internal static bool IsOperationAllowed(IManagedAccount account, decimal boutPrice, decimal count,
|
||||
decimal accountCashPartFutures, decimal accountCashPart)
|
||||
{
|
||||
if (!BotModeSwitcher.CanPurchase()) return false;
|
||||
if (!BotModeSwitcher.CanOpen()) return false;
|
||||
|
||||
var balance = account.Balance;
|
||||
var total = account.Total;
|
||||
|
|
|
@ -45,35 +45,39 @@ namespace KLHZ.Trader.Core.TG.Services
|
|||
case "/start":
|
||||
{
|
||||
var replyKeyboardMarkup = new ReplyKeyboardMarkup(new[] {
|
||||
new KeyboardButton[] { Constants.BotCommandsButtons.EnableSelling, Constants.BotCommandsButtons.DisableSelling},
|
||||
new KeyboardButton[] { Constants.BotCommandsButtons.EnablePurchases, Constants.BotCommandsButtons.DisablePurchases}});
|
||||
new KeyboardButton[] { Constants.BotCommandsButtons.EnableClosing2, Constants.BotCommandsButtons.DisableClosing2},
|
||||
new KeyboardButton[] { Constants.BotCommandsButtons.EnableOpening2, Constants.BotCommandsButtons.EnableOpening2}});
|
||||
|
||||
|
||||
await botClient.SendMessage(update.Message.Chat, "Принято!", replyMarkup: replyKeyboardMarkup);
|
||||
break;
|
||||
}
|
||||
case Constants.BotCommandsButtons.EnableSelling:
|
||||
case Constants.BotCommandsButtons.EnableClosing:
|
||||
case Constants.BotCommandsButtons.EnableClosing2:
|
||||
{
|
||||
BotModeSwitcher.StartSelling();
|
||||
await botClient.SendMessage(update.Message.Chat, "Продажи начаты!");
|
||||
BotModeSwitcher.StartClosing();
|
||||
await botClient.SendMessage(update.Message.Chat, "Закрытия разрешены!");
|
||||
break;
|
||||
}
|
||||
case Constants.BotCommandsButtons.DisableSelling:
|
||||
case Constants.BotCommandsButtons.DisableClosing:
|
||||
case Constants.BotCommandsButtons.DisableClosing2:
|
||||
{
|
||||
BotModeSwitcher.StopSelling();
|
||||
await botClient.SendMessage(update.Message.Chat, "Продажи остановлены!");
|
||||
BotModeSwitcher.StopClosing();
|
||||
await botClient.SendMessage(update.Message.Chat, "Закрытия запрещены!");
|
||||
break;
|
||||
}
|
||||
case Constants.BotCommandsButtons.EnablePurchases:
|
||||
case Constants.BotCommandsButtons.EnableOpening:
|
||||
case Constants.BotCommandsButtons.EnableOpening2:
|
||||
{
|
||||
BotModeSwitcher.StartPurchase();
|
||||
await botClient.SendMessage(update.Message.Chat, "Покупки начаты!");
|
||||
BotModeSwitcher.StartOpening();
|
||||
await botClient.SendMessage(update.Message.Chat, "Открытия начаты!");
|
||||
break;
|
||||
}
|
||||
case Constants.BotCommandsButtons.DisablePurchases:
|
||||
case Constants.BotCommandsButtons.DisableOpening:
|
||||
case Constants.BotCommandsButtons.DisableOpening2:
|
||||
{
|
||||
BotModeSwitcher.StopPurchase();
|
||||
await botClient.SendMessage(update.Message.Chat, "Покупки остановлены!");
|
||||
BotModeSwitcher.StopOpening();
|
||||
await botClient.SendMessage(update.Message.Chat, "Открытия остановлены!");
|
||||
break;
|
||||
}
|
||||
case "скинуть IMOEXF":
|
||||
|
|
Loading…
Reference in New Issue