Replies

josef.van.niekerk
06 Sep 2023, 20:56 ( Updated at: 07 Sep 2023, 05:44 )

RE: RE: RE: C# solution with multiple bots / indicators, a.k.a. monorepo...

devman said: 

josef.van.niekerk said: 

I find this rather counterproductive. It's not uncommon for .NET solutions to contain multiple projects.

Try this solution:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <AlgoPublish>false</AlgoPublish>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="cTrader.Automate" Version="1.0.8" />
    </ItemGroup>

    <Target Name="CopyAlgo"
            Condition="'$(AlgoOut)' != ''"
            DependsOnTargets="Build;$(_CoreAlgoBuildTargets)">
        <ItemGroup>
            <_AlgoFile Include="$(_AlgoFilePath)" />
        </ItemGroup>

        <Copy SourceFiles="@(_AlgoFile)"
              DestinationFolder="$(AlgoOut)"
              OverwriteReadOnlyFiles="True"
              Retries="10"
              RetryDelayMilliseconds="100" />

        <Message Importance="High"
                 Text="$(MSBuildProjectName) -> $(AlgoOut)\$(_AlgoFileName)" />
    </Target>
    
</Project>

Run this command: 

dotnet build -p:AlgoOut=your\path -t:CopyAlgo

 

Of course, you can use the full power of MSBuild and create separate .targets file. Like this:

<!-- FILE: src/copyalgo.target -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="CopyAlgo"
            Condition="'$(AlgoOut)' != ''"
            DependsOnTargets="Build;$(_CoreAlgoBuildTargets)">
        <ItemGroup>
            <_AlgoFile Include="$(_AlgoFilePath)" />
        </ItemGroup>

        <Copy SourceFiles="@(_AlgoFile)"
              DestinationFolder="$(AlgoOut)"
              OverwriteReadOnlyFiles="True"
              Retries="10"
              RetryDelayMilliseconds="100" />

        <Message Importance="High"
                 Text="$(MSBuildProjectName) -> $(AlgoOut)\$(_AlgoFileName)" />
    </Target>
</Project>

Import this file in your projects, or use Directory.Build.props to generalize this customization.

<Project>
  ...
  <Import Project="..\..\src\copyalgo.targets" />
  ...
</Project>

Thanks for taking the time to reply devman. I'll definitely take a look into this. As I mentioned, I have a workaround that works okay for me now, but looking at your code, there's definitely some bits and pieces here that I can learn from and use in my own setup.


@josef.van.niekerk

josef.van.niekerk
31 Aug 2023, 07:28 ( Updated at: 31 Aug 2023, 14:29 )

RE: C# solution with multiple bots / indicators, a.k.a. monorepo...

I find this rather counterproductive. It's not uncommon for .NET solutions to contain multiple projects.

The cTrader documentation at https://help.ctrader.com/ctrader-automate/compiling/#parameters also states clearly that AlgoName is defaulted to $(MSBuildProjectName), it does not say solution name, this documentation is rather misleading. The fact that it's even in the docs implies that it should be overrideable.

I would suggest, AlgoName should work as expected, allowing overriding of the output name. I think I'm not the first one that thinks this way, see the following post: https://ctrader.com/forum/calgo-support/39981#post-99655 

Nonetheless, I've found a workaround by setting AlgoPublish to false, and manually setting up a target to copy the algo with the name I want.

Spotware said: 

Dear Josef,

The described behavior is by design. Indicators and cBots get their name from the solution name. 

Best Regards,

cTrader Team

 


@josef.van.niekerk

josef.van.niekerk
30 Aug 2023, 19:26 ( Updated at: 31 Aug 2023, 05:06 )

I have found a workaround, not ideal. By adding the following target to .csproj:

<Target Name="PostBuild" AfterTargets="_BundleAlgo">
  <PropertyGroup>
    <AlgoCopyDestination>%USERPROFILE%\OneDrive\Documents\cAlgo\Sources\Indicators\$(ProjectName).algo</AlgoCopyDestination>
  </PropertyGroup>
  <Exec Command="copy &quot;$(TargetDir)$(SolutionName).algo&quot; &quot;$(AlgoCopyDestination)&quot;"/>
</Target>

and setting <AlgoPublish>false</AlgoPublish>, I'm at least now getting the .algo files where I want them, and with the correct project names.

I should be as easy as updating <AlgoName> instead, but as I mentioned previously, that doesn't work.


@josef.van.niekerk

josef.van.niekerk
30 Aug 2023, 09:04 ( Updated at: 31 Aug 2023, 05:06 )

Furthermore, I tried disabling publishing by setting <AlgoPublish>false</AlgoPublish> in the .csproj file, and adding a post build command On build success using the following command:

xcopy /Y "$(TargetDir)cTraderMonorepo.algo" “%USERPROFILE%\OneDrive\Documents\cAlgo\Sources\Indicators\$(ProjectName).algo”

which doesn't work, it seems the above is trying to run, before the .algo file is output to the filesystem.


@josef.van.niekerk

josef.van.niekerk
30 Aug 2023, 08:39 ( Updated at: 21 Dec 2023, 09:23 )

I'm still stuck with this problem, I need some assistance. My .algo files are still generated with the incorrect name, using the solution name, rather than the project name. I have created a small GitHub repo here, to demonstrate the issue. Check it out using git, and open with JetBrains Rider or Visual Studio.

The GitHub repo contains a small solution, cTraderMonorepo with two indicator projects, SomeIndicator and OtherIndicator. However, when building, as per the screenshot, we can see that in both instances, the output for both projects produce a cTraderMonorepo.algo file, however, I would have expected SomeIndicator.algo and OtherIndicator.algo. The result is, that when building the project, you only end up with one cTraderMonorepo.algo file, I guess the one that gets output last wins.

Another thing I tried was to edit the .csproj files, by adding <AlgoName>OtherIndicator</AlgoName> to the PropertyGroup block. This has no effect at all on the output. According to the  documentation at https://help.ctrader.com/ctrader-automate/compiling/#parameters I'm guessing you should be able to specify the output name for the .algo file using AlgoName.

Maybe @Spotware can help?


@josef.van.niekerk

josef.van.niekerk
29 Aug 2023, 07:05

RE: RE: cTrader and JetBrains Rider

ctid2032775 said: 

josef.van.niekerk said: 

Thanks Christian, I'm using the “Attach to Process” from Rider, then I just select the “algohost” process. It's a bit fiddly, would have hoped the JIT debug dialog would allow selecting Rider as an option, like it does with Visual Studio.

Hi Josef,

you can add the following code snippet at the beginning of the method OnStart() …

var result = System.Diagnostics.Debugger.Launch();if (result is false){    Print("Debugger launch failed");}

… and configure Rider as the default JIT debugger (File | Settings | Build, Execution, Deployment | Debugger).

When you then start the cBot the JIT debug dialog is shown …

Hope this helps!

BR, Christian

Thanks Christian, I'm using the “Attach to Process” from Rider, then I just select the “algohost” process. It's a bit fiddly, would have hoped the JIT debug dialog would allow selecting Rider as an option, like it does with Visual Studio.


@josef.van.niekerk

josef.van.niekerk
29 Aug 2023, 07:02 ( Updated at: 29 Aug 2023, 07:03 )

Thanks Christian. The above is most helpful. I am now getting a popup dialog from Rider instead, making debugging yet another step easier.


@josef.van.niekerk

josef.van.niekerk
28 Aug 2023, 22:39 ( Updated at: 30 Aug 2023, 07:03 )

RE: Recent cTrader.Automate 1.0.6 NuGet update breaks multi project solutions.

Hi @taras.alenin. Are you still able to have solutions with multiple projects as of cTrader.Automate version 1.0.8. I'm seeing my projects using my solution as the output name for the projects .algo filename.

Apologies to hijack your thread. I did also create a separate forum post.


@josef.van.niekerk

josef.van.niekerk
28 Aug 2023, 22:36 ( Updated at: 29 Aug 2023, 04:56 )

I know it's weird replying to myself, but I'm adding bits and pieces I'm finding out as I'm going. 

So this documentation page mentions the use of parameters like AlgoName which I tried to change in my project's .csproj file. I can see the effect of AlgoPublish, however, changing AlgoName also has no effect.

Then I came across this forum thread, I tried placing my projects in separate folders within my solution. But when building, my files are still being output as MyFooBarSolution.algo.

I am using the cTrader.Automate package version 1.0.8

Please help?!


@josef.van.niekerk

josef.van.niekerk
28 Aug 2023, 21:41

I tried updating my Indicator attributes to use the Name attribute like this:

[Indicator(Name = "FooIndicator", AccessRights = AccessRights.FullAccess)]

however, this doesn't work, and Name is marked as obsolete.


@josef.van.niekerk

josef.van.niekerk
28 Aug 2023, 20:41

Thanks Christian, I'm using the “Attach to Process” from Rider, then I just select the “algohost” process. It's a bit fiddly, would have hoped the JIT debug dialog would allow selecting Rider as an option, like it does with Visual Studio.


@josef.van.niekerk

josef.van.niekerk
22 Aug 2023, 11:35

Hi Christian, I'm a bit late to the party. However, I see the new cTrader 4.8 update allows you to open your project in Rider and VS Code as well.

Quick question though, are you actually able to debug your code with Rider as well?


@josef.van.niekerk

josef.van.niekerk
27 Mar 2023, 20:54

It seems what the documentation states about the value being calculated at bot startup still holds true, despite the version. I'm using 4.6.4. I did another check today using the BabyPips Pip Value Calculator

Doing the calculations for EURUSD at an asking price of 1.14155, the pip value I get is 8.760019 EUR.

Symbol.PipSize / Symbol.Ask * Symbol.LotSize = 8.7600192720423991

Still, cTrader (4.6.4) reports a Pip Value of 9.37980. I doubt that it is calculating this value on each tick/bar. Definitely seems to still be using the same value as when the Bot was started. I find it strange that it would do that in the first place, it's not a super expensive calculation to update.

BabyPips Pip Value Calculator


@josef.van.niekerk

josef.van.niekerk
10 Mar 2023, 13:42

RE: RE:

ctid4797769 said:

Spotware said:

Dear trader,

Do you still experience this problem using 4.6.2?

Best regards,

cTrader Team

It doesn't work for me to run all my bots with full access rights anymore. It was nice that we could quickly fix with this full access solution, but honestly, it's not serious that this error has been here since version 4.1 and we are now in 4.6.4 and the error is still here.

Whats the plan, is there anythin I can do on my PC to fix this. 

Thanks Dennis

 

I second that, I think this needs to be fixed.We're at version 4.6.4 already. Seems like a small issue to fix.


@josef.van.niekerk

josef.van.niekerk
08 Feb 2023, 12:12

I'm having the same issue in cTrader 4.6.3, even when compiling the samples that come with cTrader out of the box in .NET 6.

However, if I set the AccessRights as recommended above, everything works just fine, but it's not ideal. Hoping it will be fixed in the next version.


@josef.van.niekerk