How can I get the latest position information?
How can I get the latest position information?
20 Jul 2023, 11:11
Information is not updated when trying to retrieve information immediately after closing a position.
I have a position at the same time as the cBot start with the code below, and immediately after modifying the position, why does the information on Quantity not match the modified Quantity when I get the information on Quantity?
Please let me know if anyone can figure this out.
Best regards.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
private string _symbol;
private double quantity;
protected override void OnStart()
{
_symbol = Chart.SymbolName;
ExecuteMarketOrder(TradeType.Sell, _symbol, 4000);
var positionsell = Positions.FindAll(null, _symbol, TradeType.Sell);
foreach (Position p in positionsell)
{
foreach (var Position in positionsell)
{
if (Position.Id == p.Id)
{
ModifyPositionAsync(Position, 1000);
}
}
}
var positionsell2 = Positions.FindAll(null, _symbol, TradeType.Sell);
foreach (Position q in positionsell2)
{
quantity += q.Quantity;
}
Chart.DrawStaticText("test", quantity.ToString(), VerticalAlignment.Bottom, HorizontalAlignment.Center, Color.White);
}
protected override void OnTick()
{
}
protected override void OnStop()
{
}
}
}
Replies
yomm0401
24 Jul 2023, 06:47
RE: How can I get the latest position information?
PanagiotisChar said:
Hi there,
Because you are using an Async method. Don't use an Async method if you need positions to be updated before you proceed.
Need help? Join us on Telegram
Appreciate the replies.
You have solved all my problems.
Thank you.
@yomm0401
PanagiotisChar
20 Jul 2023, 15:56
Hi there,
Because you are using an Async method. Don't use an Async method if you need positions to be updated before you proceed.
Aieden Technologies
Need help? Join us on Telegram
@PanagiotisChar