Can't create a Order

Moderator: Moderator

Can't create a Order

Postby haixiu » Thu Apr 16, 2015 10:24 am

I made a function to create Limite Entry order. It worked fine. but recently it doesn't work.

Code: Select all
        public static bool CreateOrder(string offerid, string buysell, int amount, double ratestop, double rate)
        {
            O2GRequestFactory requestFactory = session.getRequestFactory();
            if (requestFactory == null)
            {
                UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Cannot create requestFactory", "red"));
                return false;
            }
            if (rate > 0 && (buysell == "B" && amount > 0) || (buysell == "S" && amount < 0))
            {
                O2GValueMap valuemap = requestFactory.createValueMap();
                [color=#FF0000]valuemap.setString(O2GRequestParamsEnum.Command,   Constants.Commands.CreateOrder);
                valuemap.setString(O2GRequestParamsEnum.AccountID, Client.ACCOUNT.AccountID);
                valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.LimitEntry);
                valuemap.setString(O2GRequestParamsEnum.OfferID,   offerid);
                valuemap.setString(O2GRequestParamsEnum.BuySell,   buysell);
                valuemap.setDouble(O2GRequestParamsEnum.Rate,         rate);
                ////////////////////////////////////////////////////
                if (ratestop > 0)
                    valuemap.setDouble(O2GRequestParamsEnum.RateStop,  ratestop);
                valuemap.setInt   (O2GRequestParamsEnum.Amount,Math.Abs(amount));
                O2GRequest request = requestFactory.createOrderRequest(valuemap);[/color]
                if (request == null)
                {
                    UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Cannot create request", "red"));
                    return false;
                }
                // Send Request
                ResponseListener responseListener = new ResponseListener();
                session.subscribeResponse(responseListener);
                responseListener.RequestID = request.RequestID;
                [color=#FF0000]session.sendRequest(request);[/color]
                if (!responseListener.WaitSyncResponseEvent())
                {
                    UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Request timeout expired", "red"));
                    return false;
                }
                return true;
            }
            else
            {
                UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Wrong rate or amount", "red"));
                return false;
            }
        }
haixiu
 
Posts: 6
Joined: Fri Dec 09, 2011 9:49 pm

Re: Can't create a Order

Postby Georgiy » Fri Apr 17, 2015 2:17 am

Hello haixiu,

What do you mean by "but recently it doesn't work."
Could you please clarify more exactly what happened?
The request is not created? The request is not executed (what is an error message)? Or something else?

Thank you.
Georgiy
FXCodeBase: Initiate
 
Posts: 150
Joined: Tue Jul 29, 2014 4:49 am

Re: Can't create a Order

Postby haixiu » Tue Apr 28, 2015 4:16 pm

Georgiy wrote:Hello haixiu,

What do you mean by "but recently it doesn't work."
Could you please clarify more exactly what happened?
The request is not created? The request is not executed (what is an error message)? Or something else?

Thank you.


Thanks for reply. The request has been created and executed. There is no error message. But the order table is empty. There is no order created.
haixiu
 
Posts: 6
Joined: Fri Dec 09, 2011 9:49 pm

Re: Can't create a Order

Postby Georgiy » Thu Apr 30, 2015 8:05 am

Hello haixiu,

1. Could you please clarify how do you track the appearing of the new order in a table?
The order can appear in the table immediately disappear (e.g. can be executed immediately
if the price is close to the market). That's the events have to be tracked (please use the IO2GTableListener interface).
For details please see: "Receiving Notifications about Trading Tables Updates".

2. If you already use the events please tell, does the problem keep repeating?

Thank you.
Georgiy
FXCodeBase: Initiate
 
Posts: 150
Joined: Tue Jul 29, 2014 4:49 am

Re: Can't create a Order

Postby haixiu » Thu Apr 30, 2015 3:32 pm

Georgiy wrote:Hello haixiu,

1. Could you please clarify how do you track the appearing of the new order in a table?
The order can appear in the table immediately disappear (e.g. can be executed immediately
if the price is close to the market). That's the events have to be tracked (please use the IO2GTableListener interface).
For details please see: "Receiving Notifications about Trading Tables Updates".

2. If you already use the events please tell, does the problem keep repeating?

Thank you.


I tracked the event, there is no any changes(add, delete, update) happened after I send request.

Code: Select all
        public static bool CreateOrder(string offerid, string buysell, int amount, double ratestop, double rate)
        {
            O2GRequestFactory requestFactory = session.getRequestFactory();
            if (requestFactory == null)
            {
                UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Cannot create requestFactory", "red"));
                return false;
            }
            if (rate > 0 && (buysell == "B" && amount > 0) || (buysell == "S" && amount < 0))
            {
                O2GValueMap valuemap = requestFactory.createValueMap();
                valuemap.setString(O2GRequestParamsEnum.Command,   Constants.Commands.CreateOrder);
                valuemap.setString(O2GRequestParamsEnum.AccountID, Client.ACCOUNT.AccountID);
                valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.LimitEntry);
                valuemap.setString(O2GRequestParamsEnum.OfferID,   offerid);
                valuemap.setString(O2GRequestParamsEnum.BuySell,   buysell);
                valuemap.setDouble(O2GRequestParamsEnum.Rate,         rate);
                ////////////////////////////////////////////////////
                if (ratestop > 0)
                    valuemap.setDouble(O2GRequestParamsEnum.RateStop,  ratestop);
                valuemap.setInt   (O2GRequestParamsEnum.Amount,Math.Abs(amount));
                O2GRequest request = requestFactory.createOrderRequest(valuemap);
                if (request == null)
                {
                    UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Cannot create request", "red"));
                    return false;
                }
                // Send Request
                ResponseListener responseListener = new ResponseListener();
                session.subscribeResponse(responseListener);
                responseListener.RequestID = request.RequestID;
                TableListener tableListener = new TableListener(responseListener);
                ORDERS.subscribeUpdate(O2GTableUpdateType.Insert, tableListener);
                session.sendRequest(request);
                if (!responseListener.WaitSyncResponseEvent() || !tableListener.WaitSyncTableEvent())
                {
                    UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Request timeout expired", "red"));
                    return false;
                }
                ORDERS.unsubscribeUpdate(O2GTableUpdateType.Insert, tableListener);
                return true;
            }
            else
            {
                UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Wrong rate or amount", "red"));
                return false;
            }
        }
haixiu
 
Posts: 6
Joined: Fri Dec 09, 2011 9:49 pm

Re: Can't create a Order

Postby haixiu » Thu Apr 30, 2015 4:26 pm

I don't understand but this time the request can't be created. function createOrderRequest(valuemap) returns NULL.

Code: Select all
                O2GValueMap valuemap = requestFactory.createValueMap();
                valuemap.setString(O2GRequestParamsEnum.Command,   Constants.Commands.CreateOrder);
                valuemap.setString(O2GRequestParamsEnum.AccountID, Client.ACCOUNT.AccountID);
                valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.LimitEntry);
                valuemap.setString(O2GRequestParamsEnum.OfferID,   offerid);
                valuemap.setString(O2GRequestParamsEnum.BuySell,   buysell);
                ////////////////////////////////////////////////////
                if (ratestop > 0)
                    valuemap.setDouble(O2GRequestParamsEnum.RateStop,  ratestop);
                valuemap.setInt   (O2GRequestParamsEnum.Amount,Math.Abs(amount));
                O2GRequest request = requestFactory.createOrderRequest(valuemap);
                if (request == null)
                {
                    UpdateClientStatus(null, new ClientEventArgs("CreateOrder(): Cannot create request", "red"));
                    return false;
                }
haixiu
 
Posts: 6
Joined: Fri Dec 09, 2011 9:49 pm

Re: Can't create a Order

Postby Georgiy » Wed May 06, 2015 4:24 am

Hello haixiu,
function createOrderRequest(valuemap) returns NULL

Please try to use IO2GRequestFactory.getLastError method to find out the cause.
Georgiy
FXCodeBase: Initiate
 
Posts: 150
Joined: Tue Jul 29, 2014 4:49 am

Re: Can't create a Order

Postby tesforex » Wed May 06, 2015 6:43 pm

Hi Guys,

I am experiencing strange problems with AUD/USD. I am concurrently trading 8 pairs with my own C++ trading system. I use Forexconnect API to get tick data and place orders (only market orders since my system manages other order issues).

I trade GBP/CAD, EUR/USD, EUR/GBP, USD/CAD ... and no problems with any of them except with AUD/USD. Orders were placed sometimes and not placed sometimes and there was not even an error message.

I also noticed the interface for historical data for AUDUSD was not working properly too. When downloading data for other pairs, their is no memory leaking problem. When downloading tick data for AUD/USD, the memory usage kept going up for my downloading program. I use exactly the same code. The only difference is the symbol of the currency pair. So I am sure this is nothing to do with the memory management coding in my program. The API might not be responding to requests to close a connection session which for sure will cause memory leakage.

Could someone check AUD/USD? Could it be a higher trading activity on this pair? I am really confused. Please help.

Update: The trading problem happened with EUR/GBP too. For a period of about 30 minutes, it didn't respond to order request and then resumed working status later.
Last edited by tesforex on Thu May 07, 2015 3:40 pm, edited 1 time in total.
tesforex
 
Posts: 2
Joined: Wed May 06, 2015 6:11 pm

Re: Can't create a Order

Postby tesforex » Wed May 06, 2015 6:58 pm

Hi Guys,

I need your help.

I am trading 8 pairs with my own C++ trading system build on Forexconnect API. I have no problem with any pairs except with AUD/USD. I only place market orders. There are about 5 or 6 orders that was not placed successfully with AUD/USD and there was not even an error message. I placed about a hundred orders with other pairs. No single error except AUD/USD. And my tick data downloading program also has problem with AUD/USD. When working with other pairs, there is no memory leaking problem at all. Memory usage kept almost constant. But with AUD/USD, the memory usage kept going up. The coding for trading or data downloading is exactly the same for all pairs. The only difference is the symbol of the pair.

I believe the API interface with AUD/USD is experiencing problems. e.g. it didn't respond to request to close a connection session which caused memory leakage. I don't know whether it's because of an overall higher trading activity or something else. Please kindly check for me.

Thank a lot!

Harold
Last edited by tesforex on Thu May 07, 2015 3:34 pm, edited 1 time in total.
tesforex
 
Posts: 2
Joined: Wed May 06, 2015 6:11 pm

Re: Can't create a Order

Postby Georgiy » Thu May 07, 2015 7:58 am

Hello Harold,

Thank you for reporting your issues. We should investigate that.
I will let you know about the result as soon as we figure out the cause.
Thank you for patience.
Georgiy
FXCodeBase: Initiate
 
Posts: 150
Joined: Tue Jul 29, 2014 4:49 am

Next

Return to ForexConnect API

Who is online

Users browsing this forum: No registered users and 4 guests