|
Attention! Read the forum rules carefully before posting a topic.
Try to find an answer in Wiki before asking a question. Submit programming questions in this forum only. Off topics are strictly forbidden.
Any topics which do not satisfy these rules will be deleted.
Global account: Trying to get closed order (price,time,profit/loss) |
lil
|
Post subject: Global account: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Mon 17 Jun, 2013, 11:58
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
the onMessage handler gives information when an order is passed on an account (from any other platform) but for some reason it seems hard to read the price at close time, and the linked profit/loss. Any idea on doing this, I know that if the order were processed through the strategy it would be possible, but when passively listening is it?
|
|
|
|
 |
API Support
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 1
|
Posted: Mon 17 Jun, 2013, 12:10
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
lil wrote: I know that if the order were processed through the strategy it would be possible, but when passively listening is it? A running strategy "listens" to all order changes regardless if they were created by the "listening" strategy, another strategy or manually. Consider a strategy which logs all order changes and on every order close prints order close price, time and PL: package jforex.logging;
import com.dukascopy.api.*; import com.dukascopy.api.util.DateUtils;
public class PrintMessages implements IStrategy { private IConsole console; @Override public void onStart(IContext context) throws JFException { this.console = context.getConsole(); }
@Override public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
@Override public void onMessage(IMessage message) throws JFException { IOrder o = message.getOrder(); if(o == null){ return; } console.getOut().println(message + " " + message.getReasons()); if(message.getType() == IMessage.Type.ORDER_CLOSE_OK){ console.getInfo().format("%s close price=%.5f close time=%s PL(pips)=%.1f", o.getLabel(), o.getClosePrice(), DateUtils.format(o.getCloseTime()), o.getProfitLossInPips()) .println(); } } @Override public void onAccount(IAccount account) throws JFException {} @Override public void onStop() throws JFException {}
}
Attachments: |
PrintMessages.java [1.21 KiB]
Downloaded 380 times
|
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on
this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control
on their content. Anyone accessing this webpage and downloading or otherwise making use of any document,
data or information found on this webpage shall do it on his/her own risks without any recourse against
Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from
the use and/or reliance on any document, data or information found on this webpage.
|
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Mon 17 Jun, 2013, 17:01
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Hi, Thanks for your snippet, I had something similar: public void onMessage(IMessage m) throws JFException { IOrder o=m.getOrder(); if ( o != null){ LOGGER.info("___ {}" ,m.getType() +" => "+ o.getState() +" __ "+o.getId()+" __ "+o.getAmount()+" __ "+o.getProfitLossInAccountCurrency()+" __ "+o.getClosePrice()+" __ "+o.getCloseTime()); } } When I run it and from another tool (jclient.jnlp visual interface) I close an order I see: 2013-06-18 17:21:46.201 INFO My_Play - ___ ORDER_CHANGED_OK => FILLED __ 629695EUR/CHF __ 0.0 __ 0.0 __ 0.0 __ 0 no other message, not of ORDER_CLOSE_OK my solution, is for the moment to look if the order is completely closed with o.getAmount() == 0, and then if yes to run a parallel task to download recent order history, that's clearly bad, but I didn't found a solution for getting the real close price ps: I should maybe mention that I'm using a pamm account edit: I can use IOrder getHistoricalOrderById(String id) Returns historical (closed) order by position id for the given user account.
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Tue 18 Jun, 2013, 17:00
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
still with the same issue, public void onMessage(IMessage m) throws JFException { IOrder o=m.getOrder(); LOGGER.info("___ {}" ,m.getReasons()); LOGGER.info("___ {}" ,m.getContent()); LOGGER.info("___ {}" ,m.toString()); if ( o != null){ LOGGER.info("___ {}" ,m.getType() +" => "+ o.getState() +" __ "+o.getId()+" __ "+o.getLabel()+" __ "+o.getAmount()+" __ "+o.getProfitLossInAccountCurrency()+" __ "+o.getClosePrice()+" __ "+o.getCloseTime()+" ____ "+m.getReasons()+" "+m.getContent()); if (m.getType() == Type.ORDER_SUBMIT_OK ){ // } else if (m.getType() == Type.ORDER_CHANGED_OK ){ // } } } will give: Order FILLED at 1.23158 CHF (#202548013 SELL 0.001 mil. EUR/CHF @ MKT) - Position #629695EUR/CHF 2013-06-18 17:51:17.620 INFO My_Play - ___ [] 2013-06-18 17:51:17.620 INFO My_Play - ___ null 2013-06-18 17:51:17.620 INFO My_Play - ___ Message Type: ORDER_CHANGED_OK; Text: null; Related Order: [629695EUR/CHF]-FILLED / EUR/CHF / 0.0 / 0.0 / 0.0 2013-06-18 17:51:17.620 INFO My_Play - ___ ORDER_CHANGED_OK => FILLED __ 629695EUR/CHF __ 629695EUR/CHF __ 0.0 __ 0.0 __ 0.0 __ 0 ____ [] null __notfilled__CREATED __ 202548013 __ 202548013 __ 0.0 __ 0.0 __ 0.0 __ 0
where the LOGGER lines are mine, like the last one also, coming from for (IOrder o : engine.getOrders()){ if(o.getState()!= IOrder.State.FILLED){ System.out.println("__notfilled__" + o.getState() +" __ "+o.getId()+" __ "+o.getLabel()+" __ "+o.getAmount()+" __ "+o.getProfitLossInAccountCurrency()+" __ "+o.getClosePrice()+" __ "+o.getCloseTime()); IOrder o2 = context.getHistory().getHistoricalOrderById(o.getId()); if (o2 !=null){ System.out.println("__histo__" + o2.getState() +" __ "+o2.getId()+" __ "+o2.getAmount()+" __ "+o2.getProfitLossInAccountCurrency()+" __ "+o2.getClosePrice()+" __ "+o2.getCloseTime()); } }
so like you see I can really not get any closed orders (as mentionned here also viewtopic.php?f=65&t=49432) getHistoricalOrderById is not returning the closed order ps: the first line in the log above seems coming from your library right? thanks for the support
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 2
|
Posted: Tue 18 Jun, 2013, 17:10
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
1) Are you running this on Backtest in anyway? 2) You mention PAMM, are you closing at the master account side or the client account side? 3) Did you execute Support's PrintMessages application to verify the integrity of your installation and configurations? 4) What do you see if you do [pseudo code] - if(o != null and o.state == FILLED) o.close() to cause a close straight after the fill - any subsequent CLOSE Callback?
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Tue 18 Jun, 2013, 17:30
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Thanks! problem solved, PAMM require to make amount =0 to close orders 1: they are done in a demo PAMM account 2: done on master side, (it's not accesible for clients) 3: I would be grateful to know more how 4: com.dukascopy.api.JFException: Cannot close orders on global accounts. Please open opposite order instead @ singlejartest.My_Play.onMessage(My_Play.java:386) and else yes it's really specific to PAMM accounts on a nomal demo account, the one I'm using on this forum, the log gives: so it's working well for them Strategy "My_Play" Strategy ID: 0A5C9E4DAD5AFDFCF808A6544DADD151 is started at 2013-06-18 16:24:15.622 GMT on the local computer with no parameters Started 2013-06-18 18:24:15.623 INFO Main - Strategy started: 48 Order ACCEPTED: #202551227 BUY 0.001 mil. EUR/USD @ MKT MAX SLIPPAGE 0.001 - Position #52003761 Order FILLED at 1.34035 USD (#202551227 BUY 0.001 mil. EUR/USD @ MKT MAX SLIPPAGE 0.001) - Position #52003761 2013-06-18 18:24:32.846 INFO My_Play - ___ ORDER_SUBMIT_OK => OPENED __ 52003761 __ jf108v5ca __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] 2013-06-18 18:24:32.846 INFO My_Play - ___ Message Type: ORDER_SUBMIT_OK; Text: ; Related Order: [jf108v5ca]-OPENED / EUR/USD / 0.0 / 0.001 / 0.001 2013-06-18 18:24:32.849 INFO My_Play - ___ NOTIFICATION => OPENED __ 52003761 __ jf108v5ca __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] ORDER_FILLED-Order FILLED at 1.34035 USD (#202551227 BUY 0.001 mil. EUR/USD @ MKT MAX SLIPPAGE 0.001) - Position #52003761 2013-06-18 18:24:32.849 INFO My_Play - ___ Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.34035 USD (#202551227 BUY 0.001 mil. EUR/USD @ MKT MAX SLIPPAGE 0.001) - Position #52003761; Related Order: [jf108v5ca]-OPENED / EUR/USD / 0.0 / 0.001 / 0.001 2013-06-18 18:24:32.851 INFO My_Play - ___ ORDER_FILL_OK => FILLED __ 52003761 __ jf108v5ca __ 0.001 __ -0.03 __ 0.0 __ 0 ____ [ORDER_FULLY_FILLED] 2013-06-18 18:24:32.851 INFO My_Play - ___ Message Type: ORDER_FILL_OK; Text: ; Related Order: [jf108v5ca]-FILLED / EUR/USD / 1.34035 / 0.001 / 0.001 Order FILLED at 1.34042 USD (#202551246 SELL 0.001 mil. EUR/USD @ MKT) - Position #52003761 2013-06-18 18:24:41.434 INFO My_Play - ___ NOTIFICATION => FILLED __ 52003761 __ jf108v5ca __ 0.001 __ 0.05 __ 0.0 __ 0 ____ [] ORDER_FILLED-Order FILLED at 1.34042 USD (#202551246 SELL 0.001 mil. EUR/USD @ MKT) - Position #52003761 2013-06-18 18:24:41.435 INFO My_Play - ___ Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.34042 USD (#202551246 SELL 0.001 mil. EUR/USD @ MKT) - Position #52003761; Related Order: [jf108v5ca]-FILLED / EUR/USD / 1.34035 / 0.001 / 0.001 2013-06-18 18:24:41.718 INFO My_Play - ___ ORDER_CLOSE_OK => CLOSED __ 52003761 __ jf108v5ca __ 0.001 __ 0.05 __ 1.34042 __ 1371572681476 ____ [] null 2013-06-18 18:24:41.718 INFO My_Play - ___ Message Type: ORDER_CLOSE_OK; Text: null; Related Order: [jf108v5ca]-CLOSED / EUR/USD / 1.34035 / 0.001 / 0.001
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 2
|
Posted: Tue 18 Jun, 2013, 19:08
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
That exception message is not PAMM related but 'global' vs 'normal' account related.
In this case your account is a 'global' non-hedged account.
For the benefit of others finding this thread, how are you now closing positions in this case (or will you resort in having the account changed to a 'normal' one)?
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Tue 18 Jun, 2013, 19:39
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
like said above by simply making an order with the opposite amount: Order ACCEPTED: #202555550 BUY 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001 Order FILLED at 1.232 CHF (#202555550 BUY 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF 2013-06-18 19:36:31.633 INFO My_Play - ___ ORDER_SUBMIT_OK => OPENED __ 202555550 __ jfaysulg0 __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] 2013-06-18 19:36:31.633 INFO My_Play - ___ Message Type: ORDER_SUBMIT_OK; Text: ; Related Order: [jfaysulg0]-OPENED / EUR/CHF / 0.0 / 0.001 / 0.001 2013-06-18 19:36:31.633 INFO My_Play - ___ NOTIFICATION => OPENED __ 202555550 __ jfaysulg0 __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] ORDER_FILLED-Order FILLED at 1.232 CHF (#202555550 BUY 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF 2013-06-18 19:36:31.633 INFO My_Play - ___ Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.232 CHF (#202555550 BUY 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF; Related Order: [jfaysulg0]-OPENED / EUR/CHF / 0.0 / 0.001 / 0.001 2013-06-18 19:36:31.708 INFO My_Play - ___ ORDER_FILL_OK => FILLED __ 202555550 __ jfaysulg0 __ 0.001 __ -0.13 __ 0.0 __ 0 ____ [ORDER_FULLY_FILLED] 2013-06-18 19:36:31.708 INFO My_Play - ___ Message Type: ORDER_FILL_OK; Text: ; Related Order: [jfaysulg0]-FILLED / EUR/CHF / 1.232 / 0.001 / 0.001 2013-06-18 19:36:31.709 INFO My_Play - ___ ORDER_CHANGED_OK => FILLED __ 629695EUR/CHF __ 629695EUR/CHF __ 0.001 __ -0.13 __ 0.0 __ 0 ____ [] null 2013-06-18 19:36:31.709 INFO My_Play - ___ Message Type: ORDER_CHANGED_OK; Text: null; Related Order: [629695EUR/CHF]-FILLED / EUR/CHF / 1.232 / 0.001 / 0.001 Order ACCEPTED: #202555559 SELL 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001 Order FILLED at 1.23186 CHF (#202555559 SELL 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF 2013-06-18 19:36:38.924 INFO My_Play - ___ ORDER_SUBMIT_OK => OPENED __ 202555559 __ jf1447le1 __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] 2013-06-18 19:36:38.925 INFO My_Play - ___ Message Type: ORDER_SUBMIT_OK; Text: ; Related Order: [jf1447le1]-OPENED / EUR/CHF / 0.0 / 0.001 / 0.001 2013-06-18 19:36:38.925 INFO My_Play - ___ NOTIFICATION => OPENED __ 202555559 __ jf1447le1 __ 0.001 __ 0.0 __ 0.0 __ 0 ____ [] ORDER_FILLED-Order FILLED at 1.23186 CHF (#202555559 SELL 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF 2013-06-18 19:36:38.925 INFO My_Play - ___ Message Type: NOTIFICATION; Text: ORDER_FILLED-Order FILLED at 1.23186 CHF (#202555559 SELL 0.001 mil. EUR/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695EUR/CHF; Related Order: [jf1447le1]-OPENED / EUR/CHF / 0.0 / 0.001 / 0.001 2013-06-18 19:36:38.926 INFO My_Play - ___ ORDER_FILL_OK => FILLED __ 202555559 __ jf1447le1 __ 0.001 __ -0.14 __ 0.0 __ 0 ____ [ORDER_FULLY_FILLED] 2013-06-18 19:36:38.926 INFO My_Play - ___ Message Type: ORDER_FILL_OK; Text: ; Related Order: [jf1447le1]-FILLED / EUR/CHF / 1.23186 / 0.001 / 0.001 2013-06-18 19:36:38.927 INFO My_Play - ___ ORDER_CHANGED_OK => FILLED __ 629695EUR/CHF __ 629695EUR/CHF __ 0.0 __ 0.0 __ 0.0 __ 0 ____ [] null 2013-06-18 19:36:38.927 INFO My_Play - ___ Message Type: ORDER_CHANGED_OK; Text: null; Related Order: [629695EUR/CHF]-FILLED / EUR/CHF / 0.0 / 0.0 / 0.0 also, it's different from non-global accounts, you can see tickets have names with accountNumber+instrumentI don't know the reason of this choice (a bit hacky :/), it's harder to link it to the ORDER_FILL_OK message (to get the close price) that use another id for the orders 629695EUR/CHF vs 202555559 respectively in the log I'm not even sure it's the right method actualy, giving the right exact close price for this order. I wish support can have a look at it, and tell if PAMMs are still in development or this is expected behaviour?
|
|
|
|
 |
API Support
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Wed 19 Jun, 2013, 14:28
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Your initial inquiry was on closed orders, thus processing close messages made perfect sense there. However, if you wish to check the P/L for opened positions then consider doing it in the onBar method, see wiki example: https://www.dukascopy.com/wiki/#Order_Management/Position_aggregated_profit/lossDepending on your strategy logic you can still also check the P/L in the onMessage, but then you have to determine on what events for which orders you want to check the P/L.
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Wed 19 Jun, 2013, 18:29
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
No, I already read opened orders state elsewhere, here I want to get the P/L of the closed order, for pamm accounts: The source problem is also that client.jnlp allows to close order for pamm, although it's not allowed by the SDK, opposite orders must be made. I don't know what the code of the .jnlp does, it's not really clear, there's an order with state CREATED in the engine.getOrders() afterwhile... anyway back to the issue: consider only this code public void onMessage(IMessage m) throws JFException { IOrder o=m.getOrder(); if (o!=null){ console.getOut().println(m.getType()+": id:"+ o.getId()+" __openp: "+o.getClosePrice()+" __ closep:"+o.getClosePrice()+" __ a:"+o.getAmount()+" pl:"+o.getProfitLossInAccountCurrency()+" ot:"+o.getFillTime()+" ct:"+o.getCloseTime()+ " mt:"+m.getCreationTime() ); } } for the pamm account an open + close gives: Order FILLED at 0.91903 CHF (#202663023 BUY 0.001 mil. USD/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695USD/CHF ORDER_SUBMIT_OK: id:202663023 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661005750 NOTIFICATION: id:202663023 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661005782 ORDER_FILL_OK: id:202663023 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:NaN ot:1371661005779 ct:0 mt:1371661005779 ORDER_CHANGED_OK: id:629695USD/CHF __openp: 0.0 __ closep:0.0 __ a:0.001 pl:NaN ot:1371661005779 ct:0 mt:1371661005779
Order FILLED at 0.91888 CHF (#202663025 SELL 0.001 mil. USD/CHF @ MKT) - Position #629695USD/CHF ORDER_CHANGED_OK: id:629695USD/CHF __openp: 0.0 __ closep:0.0 __ a:0.0 pl:0.0 ot:1371661007878 ct:0 mt:1371661007878
the same with an open + opposite open Order ACCEPTED: #202663167 BUY 0.001 mil. USD/CHF @ MKT MAX SLIPPAGE 0.001 Order FILLED at 0.919 CHF (#202663167 BUY 0.001 mil. USD/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695USD/CHF ORDER_SUBMIT_OK: id:202663167 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661132405 NOTIFICATION: id:202663167 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661132463 ORDER_FILL_OK: id:202663167 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:NaN ot:1371661132459 ct:0 mt:1371661132459 ORDER_CHANGED_OK: id:629695USD/CHF __openp: 0.0 __ closep:0.0 __ a:0.001 pl:NaN ot:1371661132459 ct:0 mt:1371661132459
Order ACCEPTED: #202663171 SELL 0.001 mil. USD/CHF @ MKT MAX SLIPPAGE 0.001 Order FILLED at 0.91886 CHF (#202663171 SELL 0.001 mil. USD/CHF @ MKT MAX SLIPPAGE 0.001) - Position #629695USD/CHF ORDER_SUBMIT_OK: id:202663171 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661137598 NOTIFICATION: id:202663171 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661137653 ORDER_FILL_OK: id:202663171 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:-0.11 ot:1371661137650 ct:0 mt:1371661137650 ORDER_CHANGED_OK: id:629695USD/CHF __openp: 0.0 __ closep:0.0 __ a:0.0 pl:0.0 ot:1371661137650 ct:0 mt:1371661137650
In both cases can you tell me where I can read the order close price?, there are other output message that I don't handle, they come from your library, and they would be helpful since they contain the price, what is the way to do? And in comparison, a normal non global) non pamm account, you see: Order ACCEPTED: #202663961 BUY 0.001 mil. USD/JPY @ MKT MAX SLIPPAGE 0.1 - Position #52027798 Order FILLED at 95.142 JPY (#202663961 BUY 0.001 mil. USD/JPY @ MKT MAX SLIPPAGE 0.1) - Position #52027798 ORDER_SUBMIT_OK: id:52027798 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661754030 NOTIFICATION: id:52027798 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:0.0 ot:0 ct:0 mt:1371661754064 ORDER_FILL_OK: id:52027798 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:NaN ot:1371661754061 ct:0 mt:1371661754061
Order FILLED at 95.136 JPY (#202663964 SELL 0.001 mil. USD/JPY @ MKT) - Position #52027798 NOTIFICATION: id:52027798 __openp: 0.0 __ closep:0.0 __ a:0.001 pl:-0.05 ot:1371661754061 ct:0 mt:1371661756615 ORDER_CLOSE_OK: id:52027798 __openp: 95.136 __ closep:95.136 __ a:0.001 pl:-0.05 ot:1371661754061 ct:1371661756611 mt:1371661756611 which is exactly what I need Thanks also is FIX api better suited for this case (track reliably all order events)?
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Wed 19 Jun, 2013, 20:15
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
edited order states detailed below to reflect correct transitions in state as highlighted by Support Earlier when I asked you to provide details of your closing for the benefit of others I was actually requesting not your console output but the code/explanation of the solution in order to see specifically what you did to address the 'global' account case and to take the discussion into the nuances of dealing with that case and obtaining the Close Price you were initially looking for. The console output nonetheless is appreciated as they offer readers of the thread additional insight. Ok, so with what you have now posted, let's take a look at what is going on. 'normal' account case:- SUBMIT[Long]....Order o1 [CREATED]
- ACCEPTED....... o1 [OPENED]
- FILLED...............o1 [FILLED]
- noPositions()..... 1
- CLOSE(o1)............o1 [CLOSED]
- noPositions()..... 0
o1 retains details of this entire trade. 'global' account case:- SUBMIT[Long]....Order o1 [CREATED]
- ACCEPTED....... o1 [OPENED]
- FILLED...............o1 [FILLED]
- noPositions()..... 1
- CLOSE(o1) - Invalid operation (o1 [FILLED])
- noPositions()..... 1
- SUBMIT[Short]...Order o2 [CREATED]
- ACCEPTED....... o2 [OPENED]
- FILLED...............o2 [FILLED]
- noPositions()..... 0
- CLOSE(o1) - Invalid operation (o1 [CLOSED??])(o2 [CLOSED??])
- CLOSE(o2) - Invalid operation (o1 [CLOSED??])(o2 [CLOSED??])
o1 retains details of the buy o2 retains details of the sell The filling of o2 caused the "covering" (read as closing) of o1 and so no more positions Positions and Orders are not the same thing (note the matching Position '#629695USD/CHF' on both the buy and sell side of your orders) CLOSED?? - I presume that despite the lack of an onMessage(CLOSE) that the state of both orders is in fact closed, but your logic doesn't allow us to see this (Logically both could remain FILLED - It's helpful if the second is CLOSED and holding profit - two CLOSED is confusing later on unless the first has a profit of 0 - SUPPORT can confirm) All strategy writers must consider 'global' vs 'normal' account use if they intend to distribute their code to 3rd parties without clear 'restrictions' information.(I was keen for myself and others to see your conditional handing of both cases to arrive at your solution) and the answer to your question, where is the close price on a global account? The FILL PRICE obtained on the order created to effect the "close".
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Wed 19 Jun, 2013, 23:54
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Thx, very good help First it was maybe confuse, but I was closing/opening orders independantly of the running strategy with the Web jnlp platform, so it's handling the forbidden close with emitting itself the opposite order, but it's weird that there are 2 less messages (no ORDER_SUBMIT, no NOTIFICATION) So if I understand you well, I must store all orders ticket that probably will work to get historical data (my problem #2 viewtopic.php?f=65&t=49432&p=72155&_dc=663#p72155  ) And also I get to have a look at List<IFillOrder> getFillHistory() function to get fill infos edit: seeing again your answer: Quote: if (o!=null){ ITick t = context.getHistory().getLastTick(o.getInstrument()); console.getOut().println(m.getType()+": id:"+ o.getId()+" __: "+(o.isLong()?t.getBid():t.getAsk())+" __ :"+t.getTime()+" mt:"+m.getCreationTime() ); } makes more sense in onMessage, with checking it for message type FILL
|
|
|
|
 |
API Support
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 07:29
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
CriticalSection wrote: normal' account case: SUBMIT[Long]....Order o1 [CREATED] FILL...................o1 [FILLED] noPositions()..... 1 CLOSE(o1)............o1 [CLOSED] noPositions()..... 0 You missed IOrder.State.OPENED, see: https://www.dukascopy.com/wiki/#Order_state
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 10:17
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
I don't see OPENED order states in the log either And when closing them via the web platform, I just get: ORDER_CHANGED_OK: id:629695EUR/CAD __: 1.36666 __ :1371719407023 mt:1371719408663 however I see in the log, or in the report web page Quote: Order ACCEPTED: #202874476 SELL 0.001 mil. EUR/CAD @ MKT Order FILLED at 1.36666 CAD (#202874476 SELL 0.001 mil. EUR/CAD @ MKT) - Position #629695EUR/CAD but they are not accessible through code, generated by your lib Does it mean,if I want to intercept myself these closing prices, I shall never close positions (with a pamm account)? but always open opposite ones
|
|
|
|
 |
API Support
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 10:34
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
lil wrote: I don't see OPENED order states in the log either Those are JForex-API IOrder.State's, you won't see them unless you log them. IOrder.State.OPENED is the API equivalent to the platforms ACCEPTED. To find out more have a look at the order workflow given in our previous post's link. lil wrote: however I see in the log, or in the report web page Order ACCEPTED: #202874476 SELL 0.001 mil. EUR/CAD @ MKT Order FILLED at 1.36666 CAD (#202874476 SELL 0.001 mil. EUR/CAD @ MKT) - Position #629695EUR/CAD but they are not accessible through code, generated by your lib This is not the case. They are accessible, if you print all order-related messages (i.e. without filtering out specific message types). lil wrote: Does it mean,if I want to intercept myselg these cosing prices, I shall never close positions (with a pamm account)? What do you mean by "closing prices"? Do you mean IOrder.getClosePrice() of the position when it's IOrder.getState() = IOrder.State.CLOSED? If it's PAMM or non-PAMM should not influence the order workflow, rather if it's global or standard account. Global accounts don't have such thing as closed orders and subsequently also position history.
|
|
|
|
 |
CriticalSection
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 10:43
|
|
User rating: 70
Joined: Sat 22 Sep, 2012, 17:43 Posts: 118 Location: Brazil, Fortaleza, Ceará
|
In the 'global' case, because you explicitly generate an opposite order with which to "close" existing commitments, you can retain a reference to that Order object ('o2' above or perhaps something like Order oclose; and compare the order object coming through during an onMessage() FILL to display your "close" price. You can have an Array or Set of these depending on how many currencies you use and whether you for example create one 2 lot buy and "close" it with four 1/2 lot opposite orders or simply "close" out with one opposite 2 lot order. I must step back with respect to how it is you are able to obtain and interpret historical BUY/SELL order pairs (either from Fill Order History or Close Order History) to extract position information after these have already occurred as I'm not executing any code here and do not have a global account to work with where I can interrogate everything. But in theory, if you open a Buy, subsequent Buys add to the existing exposure, and subsequent Sales subtract from it. The algorithm for obtaining "closed" orders depends on if the platform changes the 'o2' state to 'CLOSED' (there's no reason why it should as there's no such thing as Close - though it would help a bit); or if they remain FILLED, on your making use of the 'amount' information to determine when a position has been fully covered. Without registering a 'global' account and running tests, I can't help any more I'm afraid - but with some extra code in say onBar or onStop you can solve the mystery 
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 11:19
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Yes Critical, I think you're right, all pamm orders are always in FILLED state (sometimes I see CREATED ?..) thus the order history functions won't work with them, I tried them since days, without result So I must be careful to log every actions
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 11:26
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
Quote: This is not the case. They are accessible, if you print all order-related messages (i.e. without filtering out specific message types). public void onMessage(IMessage m) throws JFException { console.getOut().println(" "+m.toString()); IOrder o=m.getOrder(); if (o!=null){ ITick t = context.getHistory().getLastTick(o.getInstrument()); console.getOut().println(" "+m.getType()+": id:"+ o.getId()+": lab:"+ o.getLabel()+": pl:"+ o.getProfitLossInAccountCurrency()+": l:"+ o.getFillHistory()+" __: "+(o.isLong()?t.getBid():t.getAsk())+" __ :"+t.getTime()+" mt:"+m.getCreationTime() ); } } close on a global account 2013-06-20 12:32:28.028 WARN TaskOrderUpdate - Order message received that doesn't have assigned external id. Parent order id [202887675] Order FILLED at 1.36655 CAD (#202887675 BUY 0.001 mil. EUR/CAD @ MKT) - Position #629695EUR/CAD Order FILLED at 1.36655 CAD (#202887675 BUY 0.001 mil. EUR/CAD @ MKT) - Position #629695EUR/CAD Message Type: ORDER_CHANGED_OK; Text: null; Related Order: [629695EUR/CAD]-FILLED / EUR/CAD / 0.0 / 0.0 / 0.0 ORDER_CHANGED_OK: id:629695EUR/CAD: lab:629695EUR/CAD: pl:0.0: l:[] __: 1.36632 __ :1371724349714 mt:1371724349775 MessageType : INSTRUMENT_STATUS Instument : USD/ZAR Tradable : true
|
|
|
|
 |
API Support
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 11:27
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
Quote: Yes Critical, I think you're right, all pamm orders are always in FILLED state (sometimes I see CREATED ?..) thus the order history functions won't work with them, I tried them since days, without result So I must be careful to log every actions API Support wrote: If it's PAMM or non-PAMM should not influence the order workflow, rather if it's global or standard account. Global accounts don't have such thing as closed orders and subsequently also position history.
|
|
|
|
 |
lil
|
Post subject: Re: Trying to get closed order (price,time,profit/loss) |
Post rating: 0
|
Posted: Thu 20 Jun, 2013, 11:38
|
|
User rating: 0
Joined: Sat 08 Jun, 2013, 12:05 Posts: 71 Location: FranceFrance
|
API Support wrote: If it's PAMM or non-PAMM should not influence the order workflow, rather if it's global or standard account. Global accounts don't have such thing as closed orders and subsequently also position history. just edited, my previous msg, yes I keep talking about a global account, anyway it's not possible to authenticate to client accounts, or maybe I did it wrong Also see my previous message log: Message Type: ORDER_CHANGED_OK; Text: null; Related Order: [629695EUR/CAD]-FILLED / EUR/CAD / 0.0 / 0.0 / 0.0 ORDER_CHANGED_OK: id:629695EUR/CAD: lab:629695EUR/CAD: pl:0.0: l:[] __: 1.36632 __ :1371724349714 mt:1371724349775 and here is the price shown in trade log web page:  So is there a way to capture this log via JforexSDK? 2013-06-20 12:32:28.028 WARN TaskOrderUpdate - Order message received that doesn't have assigned external id. Parent order id [202887675] maybe this line has its importance?
|
|
|
|
 |
|
Pages: [
1, 2
»
]
|
|
|
|
|