Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IOrder.getAmount() & IOrder.getFillHistory() returns something weird
 Post subject: IOrder.getAmount() & IOrder.getFillHistory() returns something weird Post rating: 0   New post Posted: Thu 20 Apr, 2017, 23:19 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
Hi,

I'm trying to visualize my orders from LIVE account (platform version is 3.1.8 with API v 2.13.35), when fetching orders via plugin - IOrder.getAmount() and IOrder.getFillHistory() return something really strange and unusual.

My code is pretty simple
public void onStart(IContext context) throws JFException {
    try {
        for( IOrder o : context.getEngine().getOrders() ) {
            List<IFillOrder> fh = o.getFillHistory();
            ... o.getAmount() * 1_000_000 ...
            ... o.getRequestedAmount() * 1_000_000 ...
            ... o.getOriginalAmount() * 1_000_000 ...
        }


Examples of weird orders ...

Most probably correct amount is 50000 (because i never in my life made orders of 150K), but IOrder.getOriginalAmount() returns 150K.
Next - sum of all 'fills' is definitely absurd - it is 917900.
#6: jf8ithcic/84504019

    Action:       <BUY> EUR/USD
    Created:      2017-03-28 18:11:56.872
    Amount:       50 000
    Amount Req.:  50 000
    Amount Orig.: 150 000
    Open Price:   1.081229
    Filled:       2017-03-28 18:11:56.873
                    #0: 2017-03-28 18:11:54.347 -  30 000 * 1.08
                    #1: 2017-03-28 18:11:54.967 -   1 000 * 1.08
                    #2: 2017-03-28 18:11:56.873 -   1 100 * 1.08
                    #3: 2017-03-28 18:11:58.872 -  17 900 * 1.08
                    #4: 2017-03-28 21:04:07.000 -  50 000 * 1.080049
                    #5: 2017-03-29 21:04:10.000 -  50 000 * 1.080197
                    #6: 2017-03-30 21:04:39.000 -  50 000 * 1.080246
                    #7: 2017-03-31 21:03:36.000 -  50 000 * 1.080295
                    #8: 2017-04-03 21:02:56.000 -  50 000 * 1.080342
                    #9: 2017-04-04 21:02:46.000 -  50 000 * 1.080389
                    #10: 2017-04-05 21:02:44.000 -  50 000 * 1.080529
                    #11: 2017-04-06 21:02:59.000 -  50 000 * 1.080576
                    #12: 2017-04-07 21:03:07.000 -  50 000 * 1.080622
                    #13: 2017-04-10 21:03:19.000 -  50 000 * 1.080668
                    #14: 2017-04-11 21:03:30.000 -  50 000 * 1.0809
                    #15: 2017-04-12 21:03:38.000 -  50 000 * 1.080947
                    #16: 2017-04-13 21:03:33.000 -  50 000 * 1.080947
                    #17: 2017-04-14 21:02:27.000 -  50 000 * 1.080947
                    #18: 2017-04-17 21:03:24.000 -  50 000 * 1.080994
                    #19: 2017-04-18 21:04:18.000 -  50 000 * 1.081041
                    #20: 2017-04-19 21:03:09.000 -  50 000 * 1.081182
                    #21: 2017-04-20 21:03:52.000 -  17 900 * 1.081229


The most funny thing is that same plugin running on another computer generates another response for THE SAME ORDER - notes: 'amount' is different, last 'fill' is different and 'open price' differs too !!!! Frankly, now I don't believe my orders are evaluated correctly.
#6: jf8ithcic/84504019

    Action:       <BUY> EUR/USD
    Created:      2017-03-28 18:11:56.872
    Amount:       32 099
    Amount Req.:  32 099
    Amount Orig.: 150 000
    Open Price:   1.08
    Filled:       2017-03-28 18:11:56.873
                    #0: 2017-03-28 18:11:54.347 -  30 000 * 1.08
                    #1: 2017-03-28 18:11:54.967 -   1 000 * 1.08
                    #2: 2017-03-28 18:11:56.873 -   1 100 * 1.08
                    #3: 2017-03-28 18:11:58.872 -  17 900 * 1.08
                    #4: 2017-03-28 21:04:07.000 -  50 000 * 1.080049
                    #5: 2017-03-29 21:04:10.000 -  50 000 * 1.080197
                    #6: 2017-03-30 21:04:39.000 -  50 000 * 1.080246
                    #7: 2017-03-31 21:03:36.000 -  50 000 * 1.080295
                    #8: 2017-04-03 21:02:56.000 -  50 000 * 1.080342
                    #9: 2017-04-04 21:02:46.000 -  50 000 * 1.080389
                    #10: 2017-04-05 21:02:44.000 -  50 000 * 1.080529
                    #11: 2017-04-06 21:02:59.000 -  50 000 * 1.080576
                    #12: 2017-04-07 21:03:07.000 -  50 000 * 1.080622
                    #13: 2017-04-10 21:03:19.000 -  50 000 * 1.080668
                    #14: 2017-04-11 21:03:30.000 -  50 000 * 1.0809
                    #15: 2017-04-12 21:03:38.000 -  50 000 * 1.080947
                    #16: 2017-04-13 21:03:33.000 -  50 000 * 1.080947
                    #17: 2017-04-14 21:02:27.000 -  50 000 * 1.080947
                    #18: 2017-04-17 21:03:24.000 -  50 000 * 1.080994
                    #19: 2017-04-18 21:04:18.000 -  50 000 * 1.081041
                    #20: 2017-04-19 21:03:09.000 -  50 000 * 1.081182
                    #21: 2017-04-20 21:03:52.000 -  50 000 * 1.081229


Another example
#7: jfust8rk3/84515689

    Action:       <BUY> EUR/USD
    Created:      2017-03-29 06:04:30.791
    Amount:       2 000
    Amount Req.:  2 000
    Amount Orig.: 50 000
    Open Price:   1.08053
    Filled:       2017-03-29 06:04:30.792
                    #0: 2017-03-29 06:04:30.792 -   2 000 * 1.08053
                    #1: 2017-03-29 06:04:36.572 -  23 000 * 1.08051
                    #2: 2017-03-29 21:04:10.000 -  25 000 * 1.08066
                    #3: 2017-03-30 21:04:39.000 -  25 000 * 1.080709
                    #4: 2017-03-31 21:03:36.000 -  25 000 * 1.080758
                    #5: 2017-04-03 21:02:56.000 -  25 000 * 1.080805
                    #6: 2017-04-04 21:02:46.000 -  25 000 * 1.080852
                    #7: 2017-04-05 21:02:44.000 -  25 000 * 1.080992
                    #8: 2017-04-06 21:02:59.000 -  25 000 * 1.081039
                    #9: 2017-04-07 21:03:07.000 -  25 000 * 1.081085
                    #10: 2017-04-10 21:03:19.000 -  25 000 * 1.081131
                    #11: 2017-04-11 21:03:30.000 -  25 000 * 1.081363
                    #12: 2017-04-12 21:03:38.000 -  25 000 * 1.08141
                    #13: 2017-04-13 21:03:33.000 -  25 000 * 1.08141
                    #14: 2017-04-14 21:02:27.000 -  25 000 * 1.08141
                    #15: 2017-04-17 21:03:24.000 -  25 000 * 1.081457
                    #16: 2017-04-18 21:04:18.000 -  25 000 * 1.081504
                    #17: 2017-04-19 21:03:09.000 -  25 000 * 1.081645
                    #18: 2017-04-20 21:03:52.000 -  25 000 * 1.081692


 
 Post subject: Re: IOrder.getAmount() & IOrder.getFillHistory() returns something weird Post rating: 0   New post Posted: Fri 28 Apr, 2017, 11:16 
User avatar

User rating: 0
Joined: Wed 05 Mar, 2014, 17:24
Posts: 30
Location: Russian Federation, Tomsk
I have written about this issue here: https://www.dukascopy.com/swiss/english ... 16&t=54627

Sometimes getOriginalAmount() = N * getAmount(), where N = 2, 3, 4... (integer)


 
 Post subject: Re: IOrder.getAmount() & IOrder.getFillHistory() returns something weird Post rating: 0   New post Posted: Sun 30 Apr, 2017, 22:21 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
Grevlanik, yes, I’ve seen your message later and it seems that this is exactly the same problem and it was not fixed at least for a year … that is sad :(

Dear JForex dev team, during the time while my bug report was moderated I had some time to think about this problem and here are some concerns

1. I do not use and strategy to create orders – everything is performed from JForex UI. The only my code I use is logging already created orders
2. I expect that problem occurs with BUY/SELL order originated from PLACE_BID/PLACE_OFFER orders. I mostly use PLACE_XXX orders and in many cases they are placed at the ‘edge’ price – this typically causes filling of such orders with multiple portions

So I guess you will be easily able to reproduce the problem by putting BID/OFFER with rather high amount at the current middle price between ASK and BID.

But as far as I noticed further wrong reporting from getAmount() is only minor part of the problem. I tried to workaround the wrong values in getAmount() by manually calculating that value from 'fills' – this should be the difference between ‘SUM(all fills)’ and ‘SUM(all closes)’ and it appears that ‘fills’ and ‘closes’ are also not reported correctly – this leaves no chance to calculate amount correctly because input data is not correct.

The problems I see here are ...

3. Listed ‘Fills’ contain both ‘original’ fills and ‘swap’ fills – that is why long-opened positions have such inadequate SUM of fills (I originally included SWAP into overall amount). Workaround for that problem – ignore ‘fills’ occurring at 21:00-21:10 UTC - these are typically SWAPs – unless indeed created at this time. Unfortunately, JForex API does not provide clear flag of the type of ‘fill’. Please add method into IFillOrder to distinguish ‘swap’ and ‘regular’ fills.

4. Sometimes ‘normal’ fills are reported twice - this is the bug that cannot be workarounded in client code. Here is the example (note – same order logged on another computer does not have ‘fill #2’ – i.e. this is some kind of data/timing-dependent error, note2: WEB interface reports only 99K operation happening at ‘09:30:31.911’):

Filled: #0: 2017-04-28 09:30:31.471 - 1 000 * 1.0937
#1: 2017-04-28 09:30:31.911 - 99 000 * 1.0937
#2: 2017-04-28 09:30:31.912 - 99 000 * 1.0937

5. Sometimes last ‘swap’ does not correspond to actual amount – i.e. previous swap is ‘100K’ and last swap is (for example) ‘27800’. There were no ‘close’ operations for that position – therefore that last swap should also be of ‘100K’ as the previous one. Note again: same position logged on another computer at the same time reports ‘100K’ as last swap.

6. The most misleading thing to me – is incorrectly reported ‘getOriginalAmount()’. As mentioned in JavaDoc – it ‘Returns original constant amount of the order. The value is set on order submit and cannot be changed later.’ I assume with SELLs originated from PLACE_OFFER there is something wrong happening while OFFER is transformed into SELL somewhere in JForex inner code.

Note: minor thing – both IFillOrder and ICloseOrder are inherited from IPartialOrder and all their methods are copy/pasted into ‘children’ – this is a bit wrong in terms of API declaration, child interface should define only new methods.


 
 Post subject: Re: IOrder.getAmount() & IOrder.getFillHistory() returns something weird Post rating: 0   New post Posted: Sun 30 Apr, 2017, 23:27 

User rating: 18
Joined: Thu 20 Apr, 2017, 22:42
Posts: 165
Location: Russian Federation,
And consequently Profit/Loss in $$$ is evaluated incorrectly - below are absolutely 'unaligned' numbers, note the 'getProfitLossInUSD()' of '$3.68' - it happens so because used amount is '1K' whereas correct amount is '100K', additionally - none of 'getAmount()' / 'getRequestedAmount()' / 'getOriginalAmount()' return correct value for that position

85695840 FILLED

    Action:       <SELL> EUR/USD
    Created:      2017-04-28 09:30:31.470
    Amount:       1 000
    Amount Req.:  1 000
    Amount Orig.: 300 000
    Open Price:   1.0937
    Fill time:    2017-04-28 09:30:31.470
    Filled:       #0: 2017-04-28 09:30:31.471 -   1 000 * 1.0937
                  #1: 2017-04-28 09:30:31.912 -  99 000 * 1.0937
                  #2: 2017-04-28 21:02:44.000 - 100 000 * 1.0937
    Commission:   4.37 $
    Profit$:      3.68 $
    Profit.:      36.8 pips


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com