How to create a share file that multiple instances can access?
How to create a share file that multiple instances can access?
03 Feb 2023, 07:51
Hi,
I have been at this problem for months now.
I've tried many different solution which work but do not solve my problem.
In order for it to work I think I need to create a share file that my cBot can access so that multiple instances can read/write to it and share the data.
Essentially what I need it to do is place and order and write that order to the "order_status.txt" file located in what I presume is the cBot's working directory and then check the file to see if an order has been placed.
The final version is more complex than this simplified version however this one piece of code 'file sharing' I cannot solve.
The bot just crashes no matter what I try here.
Any help with providing cBot access to a file to read/write and share with other instances would be much appreciated.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System.IO;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.SingaporeStandardTime, AccessRights = AccessRights.FullAccess)]
public class CUSTOMCBOT : Robot
{
//private string _shareFilePath = @"order_status.txt";
//private string _shareFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "order_status.txt");
private string _shareFilePath = @"Z:\Documents\cAlgo\Sources\Robots\TESTING\TESTING\order_status.txt";
//private string _shareFilePath = @"C:\Users\<username>\AppData\Roaming\cAlgo\Sources\Robots\order_status.txt";
//private string _shareFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "cAlgo", "Sources", "Robots", "order_status.txt");
//private string _shareFilePath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "order_status.txt");
protected override void OnTick()
{
if (!File.Exists(_shareFilePath))
{
Print("Not Placed");
File.WriteAllText(_shareFilePath, "Not placed");
}
string orderStatus = File.ReadAllText(_shareFilePath);
if (orderStatus != "Placed")
{
ExecuteMarketRangeOrder(TradeType.Buy, SymbolName, 1000, 5, Symbol.Ask, "2", null, 25);
File.WriteAllText(_shareFilePath, "Placed");
Print("Order Placed");
}
}
protected override void OnStop()
{
File.WriteAllText(_shareFilePath, string.Empty);
}
}
}
ctid2434759
03 Feb 2023, 09:20 ( Updated at: 03 Feb 2023, 09:31 )
RE:
Every single time I write the question on this forum that I've been stuck on for days, weeks or months I figure it out about an hour after I ask the question.
So if anyone ever want's the code. What I have written above works.
I'm very very happy.
I'de like to take the time to say thanks to.....ABSOLUTE NO BODY, the coding champ does whatever the f the coding champ wants.
@ctid2434759