Open r2roi opened 7 months ago
We're glad you've opened your first issue. Please provide all the necessary details and any relevant code or screenshots to help us understand the problem better. Our team will review your issue and provide assistance as soon as possible. Thank you for contributing!
Thank you for the prompt response. The method of buying and selling new positions is functioning properly.This is the only area where problems have arisen.Below is an excerpt from my code that is relevant and I would be happy if you could review it.
import json
from flask import Flask, request
import logging
from ejtraderCT import Ctrader
# Global instance of Ctrader
ctrader_instance = None
# Custom position list
position_list = {}
def get_ctrader_instance(force_relogin=False):
global ctrader_instance
if not ctrader_instance or force_relogin:
credentials = get_ctrader_credentials()
ctrader_instance = Ctrader(server=credentials["host"], account=credentials["sender_comp_id"], password=credentials["password"])
LoopingCall(send_heartbeat).start(30) # send heartbeat every 30 seconds
return ctrader_instance
# ・・・・・・Code to split processing between holding a buy/sell position or closing all positions (close_all) depending on the content of the webhook alert・・・
def update_positions_list():
global ctrader_instance, position_list
try:
# Get current positions
current_positions = ctrader_instance.positions()
logger.debug(f"Acquired position data: {current_positions}")
# Update own position_list
position_list.clear() # clear existing position_list
for pos in current_positions:
position_list[pos['pos_id']] = pos
def process_st_off(retry_count=0): #ST_OFF is a variable in my Alert Word that indicates the request to make close all
try:
update_positions_list() # update position list (call with no arguments)
current_positions = ctrader.positions()
logger.debug(f"Current positions: {current_positions}")
logger.debug("Start process to close all positions.")
ctrader.close_all()
time.sleep(1) # wait 1 second
logger.debug("Close process completed.")
Hello ejtraderCT Team,
I am experiencing an issue with the close_all method in the Ctrader class, which is not functioning as expected in my implementation. The method is supposed to close all open positions, but it fails to do so. Here's the relevant snippet from my main.py:
python code def process_close_all():
... code to update and log current positions ...
update_positions_list()
current_positions = api.positions() ctrader.close_all() time.sleep(1)
... logging message ...
Despite calling ctrader.close_all(), the positions remain open. The close_all method is invoked after retrieving the current positions, but the subsequent positions check reveals that they are not closed. This issue occurs even though there are active positions present.
Could you please help me understand if there's a known issue with this method or if I might be missing something in my implementation? Any guidance or suggestions for troubleshooting this would be greatly appreciated.
Thank you for your assistance.