-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TTALGO-2105: First version of TPbot v.1.4 has been added
- Loading branch information
1 parent
fe7a80d
commit c1fc0b8
Showing
9 changed files
with
338 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TPtoAllNewPositions | ||
=== | ||
|
||
## Idea | ||
This bot does smth awesome | ||
|
||
|
||
## Parameters | ||
|
||
|
||
|
||
## Inputs | ||
|
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,60 @@ | ||
using SoftFx.Routines; | ||
using System.Text; | ||
using System; | ||
using System.Threading.Tasks; | ||
using TickTrader.Algo.Api; | ||
|
||
namespace TPtoAllNewPositions | ||
{ | ||
[TradeBot(Category = "SoftFX Public", DisplayName = "TPtoAllNewPositions", Version = "1.0", | ||
Description = "The bot emulates the TakeProfit for positions on Net account. It sets the specified TP for all new Net positions")] | ||
public class TPtoAllNewPositions : SingleLoopBot<TPtoAllNewPositionsConfiguration> | ||
{ | ||
private const string ConfigDefaultFileName = $"{nameof(TPtoAllNewPositions)}.tml"; | ||
|
||
|
||
[Parameter(DisplayName = "Config File", DefaultValue = $"{nameof(TPtoAllNewPositions)}.tml")] | ||
[FileFilter("Toml Config (*.tml)", "*.tml")] | ||
public File ConfigFile { get; set; } | ||
|
||
|
||
protected override Task InitInternal() | ||
{ | ||
LoopTimeout = Config.RunIntervalInSeconds * 1000; | ||
|
||
if (Account.Type != AccountTypes.Net) | ||
{ | ||
PrintError("Bot works only on Net account"); | ||
Abort(); | ||
} | ||
|
||
return base.InitInternal(); | ||
} | ||
|
||
protected override Task Iteration() | ||
{ | ||
CheckConfigSymbols(); | ||
} | ||
|
||
|
||
protected override string GetConfigFullPath() => ConfigFile.FullPath; | ||
|
||
protected override string GetDefaultConfigFileName() => ConfigDefaultFileName; | ||
|
||
|
||
private void CheckConfigSymbols() | ||
{ | ||
var str = new StringBuilder(1 << 10); | ||
|
||
foreach (var key in Config.SymbolsSettings.Keys) | ||
if (Symbols[key].IsNull) | ||
str.AppendLine($"Symbol {key} not found on server."); | ||
|
||
if (Config.HasErrors) | ||
Status.WriteLine($"Config error:{Environment.NewLine}{Config.GetAllErrors}"); | ||
|
||
if (str.Length > 0) | ||
Status.WriteLine($"Config warning:{Environment.NewLine}{str}"); | ||
} | ||
} | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="TickTrader.Algo.Api" Version="1.*" /> | ||
<PackageReference Include="TickTrader.Algo.Tools" Version="1.*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="README.md"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
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,97 @@ | ||
using SoftFx; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace TPtoAllNewPositions | ||
{ | ||
public class TPtoAllNewPositionsConfiguration : BotConfig | ||
{ | ||
[Nett.TomlIgnore] | ||
public HashSet<string> ExcludeSymbolsHash { get; } = new(); | ||
|
||
[Nett.TomlIgnore] | ||
public Dictionary<string, int> SymbolsTP { get; } = new(); | ||
|
||
|
||
public Dictionary<string, string> SymbolsSettings { get; set; } | ||
|
||
public List<string> ExcludeSymbols { get; set; } | ||
|
||
|
||
public int RunIntervalInSeconds { get; set; } | ||
|
||
public int DefaultTPInPips { get; set; } | ||
|
||
public int TpForCurrentPriceInPips { get; set; } | ||
|
||
|
||
public TPtoAllNewPositionsConfiguration() | ||
{ | ||
RunIntervalInSeconds = 600; | ||
DefaultTPInPips = 100; | ||
TpForCurrentPriceInPips = 5; | ||
|
||
SymbolsSettings = new Dictionary<string, string>() | ||
{ | ||
["AUDCAD"] = "200", | ||
["AUDCHF"] = "200", | ||
["USDMXN"] = "3000", | ||
["USDRUB"] = "1000", | ||
}; | ||
|
||
ExcludeSymbols = new List<string>() { "BTCUSD" }; | ||
} | ||
|
||
|
||
public override void Init() | ||
{ | ||
if (RunIntervalInSeconds <= 0) | ||
throw new ValidationException($"{nameof(RunIntervalInSeconds)} must be greater than 0"); | ||
|
||
if (DefaultTPInPips < 0) | ||
throw new ValidationException($"{nameof(DefaultTPInPips)} must be greater or equal than 0"); | ||
|
||
if (TpForCurrentPriceInPips < 0) | ||
throw new ValidationException($"{nameof(TpForCurrentPriceInPips)} must be greater or equal than 0"); | ||
|
||
foreach ((var symbol, var tp) in SymbolsSettings) | ||
if (int.TryParse(tp, out var pips)) | ||
PrintError($"{symbol} invalid tp = {tp} (cannot be parsed to int)"); | ||
else | ||
SymbolsTP.TryAdd(symbol, pips); | ||
|
||
ExcludeSymbolsHash.Clear(); | ||
|
||
foreach (var symbol in ExcludeSymbols) | ||
ExcludeSymbolsHash.Add(symbol); | ||
} | ||
|
||
|
||
public bool TryGetTP(string symbol, out double tp) | ||
{ | ||
tp = SymbolsTP.TryGetValue(symbol, out var pips) ? pips : DefaultTPInPips; | ||
|
||
return ExcludeSymbolsHash.Contains(symbol); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
var builder = new StringBuilder(1 << 10); | ||
|
||
builder.AppendLine("Input config:") | ||
.AppendLine($"{nameof(RunIntervalInSeconds)} = {RunIntervalInSeconds};") | ||
.AppendLine($"{nameof(DefaultTPInPips)} = {DefaultTPInPips};") | ||
.AppendLine($"{nameof(TpForCurrentPriceInPips)} = {TpForCurrentPriceInPips};") | ||
.AppendLine() | ||
.AppendLine($"[{nameof(SymbolsSettings)}]") | ||
.Append($"{string.Join($"{Environment.NewLine}", SymbolsTP.Select(u => $"{u.Key}={u.Value}"))}") | ||
.AppendLine() | ||
.AppendLine($"[{nameof(ExcludeSymbols)}]") | ||
.Append($"{string.Join(",", ExcludeSymbols)}"); | ||
|
||
return builder.ToString(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.