Moderator: Moderator
def close_trade(fc, buy_sell):
open_trades_table = fc.get_table(ForexConnect.TRADES)
open_trades_table = Common.convert_table_to_dataframe(open_trades_table)
try:
open_trades_table['trade_id'] = open_trades_table.index
open_trades_table.reset_index(inplace=True, drop=True)
open_trades_table = open_trades_table.tail(1)
trade_id = open_trades_table.trade_id[0]
offer = open_trades_table.offer_id[0]
account_id = open_trades_table.account_id[0]
amount = open_trades_table.amount[0]
print("closing last trade")
request = fc.create_order_request(order_type=fxcorepy.Constants.Orders.TRUE_MARKET_CLOSE, OFFER_ID=offer,
ACCOUNT_ID=account_id, BUY_SELL=buy_sell, AMOUNT=str(amount), TRADE_ID=trade_id)
except IndexError as e:
request = None
print("No Previous Trade Found..",str(e))
if request is None:
raise Exception("Cannot create close trade request")
elif request is not None:
try:
resp = fc.send_request(request)
# sometimes i get a warning to use send_request_async
order_id = resp.order_id
print(
"Following trade with trade_id {} has been closed successfully and order_id is {}".format(trade_id, order_id))
except Exception as e:
print(e)
Return to ForexConnect-Python API
Users browsing this forum: Bing [Bot] and 7 guests