Dukascopy
 
 
Wiki JStore Search Login

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.

Error in getAmount() with CFD
 Post subject: Error in getAmount() with CFD Post rating: 0   New post Posted: Fri 26 Jul, 2019, 23:11 

User rating: 0
Joined: Fri 26 Jul, 2019, 23:06
Posts: 2
Location: Canada,
Hi,
Normally when i call the function getAmount() with Forex it's ok, but, when i'm trying with CFD, i got this :

18:57:48 Trade : Thu Jul 25 14:16:21 UTC 2019 Open Price : 318.483 Close Price : 322.508 Amount : 2.0E-5 Pips : 402.5 Profit/Loss : 80.5 $ Commission : 20.0 $

the right number is 20
not 2.0E-5


Can you help me with that ?

With the code :

public void onStart(IContext context) throws JFException {
console = context.getConsole();

//String theDateString = "01-01-2018";
SimpleDateFormat timeFormatDate = new SimpleDateFormat("dd-MM-yyyy");
try {
beginDate = (Date)timeFormatDate.parse(theDateString);
} catch (ParseException e) {
console.getOut().println(e);
}
long beginDateLong = beginDate.getTime();
long time = System.currentTimeMillis();

List<IOrder> orders = context.getHistory().getOrdersHistory(theInstrument, beginDateLong, time);
if (orders != null) {

for (int i = 0; i <= orders.size() -1; i++) {

theDate = new Date(orders.get(i).getCreationTime());

console.getOut().println(" Trade : " + theDate + " Open Price : " +
orders.get(i).getOpenPrice() + " Close Price : " + orders.get(i).getClosePrice() + " " +
"Amount : " + orders.get(i).getAmount() + " " +
" Pips : " + orders.get(i).getProfitLossInPips() +
" Profit/Loss : " + orders.get(i).getProfitLossInAccountCurrency() + " $" + " Commission : " +
orders.get(i).getCommission() + " $");

}
}
}


 
 Post subject: Re: Error in getAmount() with CFD Post rating: 0   New post Posted: Mon 29 Jul, 2019, 17:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

Quote:
In JForex API amounts of orders are represented in millions, meaning that by submitting a long order with amount 1 and instrument EUR/USD, on full, successful fill 1 million units (i.e. 1'000'000 EUR) will get bought.

https://www.dukascopy.com/wiki/en/development/strategy-api/orders-and-positions/order-amounts

2.0E-5 = 0.000020


 
 Post subject: Re: Error in getAmount() with CFD Post rating: 0   New post Posted: Mon 29 Jul, 2019, 19:19 

User rating: 0
Joined: Fri 26 Jul, 2019, 23:06
Posts: 2
Location: Canada,
Ho ok !

Great !

Thank you !


 

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