Login Page - Create Account

Support Board


Date/Time: Sun, 19 May 2024 17:40:58 +0000



Post From: How to exchange position info with Ctrader (C#)

[2024-04-15 21:30:59]
tomas262 - Posts: 135
For now solved this simply by this code

s_SCPositionData PositionData;
  int posResult = sc.GetTradePosition(PositionData);

  if (lastPositionData == -1 || lastPositionData != PositionData.PositionQuantity) {
    // Write values to a file
    // Open a file for writing
    std::ofstream outFile("position_data.txt");

    if (!outFile.is_open()) {
      std::cerr << "Failed to open file for writing." << std::endl;
      return;
    }

    // Write position quantity to file
    outFile << PositionData.PositionQuantity << std::endl;

    // Close the file
    outFile.close();

    lastPositionData = PositionData.PositionQuantity;
  }

lastPositionData is a int persist var so the value is written into the file only when a change happens

on the Ctrader side I simply use StreamReader executed OnTick() to check the value and open a corresponding position
Date Time Of Last Edit: 2024-04-15 21:31:41