Compare commits
No commits in common. "e5eee2504290f8880dfba5bb1ac20a2daaa571d7" and "dbacad168afb7884a1f2bdc1f098c3fbde7491ca" have entirely different histories.
e5eee25042
...
dbacad168a
|
@ -5,10 +5,10 @@ namespace KLHZ.Trader.Core.Exchange.Extentions
|
||||||
{
|
{
|
||||||
internal static class InvestApiClientExtentions
|
internal static class InvestApiClientExtentions
|
||||||
{
|
{
|
||||||
public static async Task<Dictionary<string, string>> GetAccounts(this InvestApiClient client, params string[] managedAccountNamePatterns)
|
public static async Task<Dictionary<string,string>> GetAccounts(this InvestApiClient client, params string[] managedAccountNamePatterns)
|
||||||
{
|
{
|
||||||
var accounts = await client.Users.GetAccountsAsync();
|
var accounts = await client.Users.GetAccountsAsync();
|
||||||
var accs = new Dictionary<string, string>();
|
var accs = new Dictionary<string,string>();
|
||||||
foreach (var pattern in managedAccountNamePatterns)
|
foreach (var pattern in managedAccountNamePatterns)
|
||||||
{
|
{
|
||||||
var aids = accounts.Accounts
|
var aids = accounts.Accounts
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace KLHZ.Trader.Core.Exchange.Interfaces
|
||||||
public decimal Total { get; }
|
public decimal Total { get; }
|
||||||
bool Initialized { get; }
|
bool Initialized { get; }
|
||||||
string AccountId { get; }
|
string AccountId { get; }
|
||||||
string? AccountName { get; }
|
string? AccountName{ get; }
|
||||||
Task Init(string accountId, string? accountName = null);
|
Task Init(string accountId, string? accountName = null);
|
||||||
Task LoadPortfolio();
|
Task LoadPortfolio();
|
||||||
ImmutableDictionary<string, Asset> Assets { get; }
|
ImmutableDictionary<string, Asset> Assets { get; }
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
var accounts = await _investApiClient.GetAccounts(_managedAccountNamePatterns);
|
var accounts = await _investApiClient.GetAccounts(_managedAccountNamePatterns);
|
||||||
foreach (var acc in accounts)
|
foreach (var acc in accounts)
|
||||||
{
|
{
|
||||||
await _portfolioWrapper.AddAccount(acc.Key, acc.Value);
|
await _portfolioWrapper.AddAccount(acc.Key,acc.Value);
|
||||||
}
|
}
|
||||||
_ = CycleSubscribtion(accounts.Keys.ToArray());
|
_ = CycleSubscribtion(accounts.Keys.ToArray());
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
using Tinkoff.InvestApi;
|
using Tinkoff.InvestApi;
|
||||||
using Asset = KLHZ.Trader.Core.Exchange.Models.AssetsAccounting.Asset;
|
using Asset = KLHZ.Trader.Core.Exchange.Models.AssetsAccounting.Asset;
|
||||||
|
@ -294,8 +293,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
await OpenPositions(accounts, message, PositionType.Long, stops.stopLoss, stops.takeProfit, 1);
|
await OpenPositions(accounts, message, PositionType.Long, stops.stopLoss, stops.takeProfit, 1);
|
||||||
}
|
}
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-100), message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(100), message);
|
||||||
}
|
}
|
||||||
if (newMod == TradingMode.Dropping && newMod != oldMod)
|
if (newMod == TradingMode.Dropping && newMod != oldMod)
|
||||||
{
|
{
|
||||||
|
@ -310,8 +309,8 @@ namespace KLHZ.Trader.Core.Exchange.Services
|
||||||
await OpenPositions(accounts, message, PositionType.Short, stops.stopLoss, stops.takeProfit, 1);
|
await OpenPositions(accounts, message, PositionType.Short, stops.stopLoss, stops.takeProfit, 1);
|
||||||
}
|
}
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(10, 100)), message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-100), message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(100), message);
|
||||||
}
|
}
|
||||||
TradingModes[message.Figi] = newMod;
|
TradingModes[message.Figi] = newMod;
|
||||||
if (oldMod != newMod)
|
if (oldMod != newMod)
|
||||||
|
@ -467,7 +466,7 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
|
||||||
assetsForClose.Add(asset);
|
assetsForClose.Add(asset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tasks = assetsForClose.Select(asset => _portfolioWrapper.Accounts[asset.AccountId].ClosePosition(message.Figi));
|
var tasks = assetsForClose.Select(asset => _portfolioWrapper.Accounts[asset.AccountId].ClosePosition(message.Figi));
|
||||||
await Task.WhenAll(tasks);
|
await Task.WhenAll(tasks);
|
||||||
}
|
}
|
||||||
|
@ -548,8 +547,8 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
|
||||||
}
|
}
|
||||||
|
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value + stops.takeProfit, message.Time.AddMilliseconds(-100), message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenLong, message.Value - stops.stopLoss, message.Time.AddMilliseconds(100), message);
|
||||||
}
|
}
|
||||||
if (result[TradingEvent.DowntrendStart] > Constants.PowerUppingCoefficient
|
if (result[TradingEvent.DowntrendStart] > Constants.PowerUppingCoefficient
|
||||||
&& !ShortOpeningStops.ContainsKey(message.Figi)
|
&& !ShortOpeningStops.ContainsKey(message.Figi)
|
||||||
|
@ -568,8 +567,8 @@ INewPrice message, int windowMaxSize, decimal uptrendStartingDetectionMeanfullSt
|
||||||
}
|
}
|
||||||
|
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value - stops.takeProfit, message.Time.AddMilliseconds(-100), message);
|
||||||
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(RandomNumberGenerator.GetInt32(300, 1000)), message);
|
await LogDeclision(DeclisionTradeAction.OpenShort, message.Value + stops.stopLoss, message.Time.AddMilliseconds(100), message);
|
||||||
}
|
}
|
||||||
if (result[TradingEvent.UptrendEnd] > Constants.UppingCoefficient)
|
if (result[TradingEvent.UptrendEnd] > Constants.UppingCoefficient)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,11 +39,11 @@ namespace KLHZ.Trader.Core.TG.Services
|
||||||
{
|
{
|
||||||
await _botClient.SendMessage(admin, message.Text);
|
await _botClient.SendMessage(admin, message.Text);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при отправке сообщения в бота.");
|
_logger.LogError(ex, "Ошибка при отправке сообщения в бота.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue