etoro-api icon indicating copy to clipboard operation
etoro-api copied to clipboard

Error with shorting (sell) positions

Open WarlaxZ opened this issue 5 years ago • 22 comments

Whenever I try to create a short position it fails

Unfortunately I don't have the error now as the market is closed, however will try and get it on monday. I just want to confirm that the library supports shorts, as it looks as if it does.

Will confirm that buys went through completely fine, it was just an issue with 'sells' (and I don't mean closing an open position, mean a shot position).

Let me know if there is anything else I can provide you with

WarlaxZ avatar Jan 08 '21 22:01 WarlaxZ

Hi,

For the sell positions is required to specify SL and TP values, have you done that? You can verify it with Bitcoin its market is open even on weekends.

Best regards Oleg


От: WarlaxZ [email protected] Отправлено: 9 января 2021 г. 0:33 Кому: ok24601/etoro-api [email protected] Копия: Subscribed [email protected] Тема: [ok24601/etoro-api] Error with shorting (sell) positions (#20)

Whenever I try to create a short position it fails

Unfortunately I don't have the error now as the market is closed, however will try and get it on monday. I just want to confirm that the library supports shorts, as it looks as if it does.

Will confirm that buys went through completely fine, it was just an issue with 'sells' (and I don't mean closing an open position, mean a shot position).

Let me know if there is anything else I can provide you with

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/ok24601/etoro-api/issues/20, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVTCBJD6KPORGZSDBBDSY6B3LANCNFSM4V3BPZXA.

ok24601 avatar Jan 09 '21 11:01 ok24601

originally I had (but it was part of a larger program so couldnt directly see the results) - however nice shout on the btc - will test locally now. wonder if my issue may have been due to some positions requiring larger SL/TP - but will investigate. thank you for the response!

WarlaxZ avatar Jan 09 '21 19:01 WarlaxZ

ah can't test - now that u cant buy cfd and u have to buy the underlying asset, u cant short (button not available in etoro UI) - so currently see this error (although this is correct that it errors)

{ "timestamp": "2021-01-09T19:28:11.872+0000", "status": 500, "error": "Internal Server Error", "message": "Code: 747, details: null", "path": "/etoro-api/positions/open" }

Will wait until market opens monday and provide more details :)

WarlaxZ avatar Jan 09 '21 19:01 WarlaxZ

Ok just confirmed, tried to short TUI.L

I see this error:

{
  "timestamp": "2021-01-11T10:20:55.744+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "Code: 796, details: null",
  "path": "/etoro-api/positions/open"
}

And the stack trace in the logs is:

{"Id":"e2101552-b280-4ec8-a779-5a83d6bcf0d5","Durable":false,"Type":"Trading.Failure.Position.Open","Content":"{\"CID\":19298152,\"ErrorMessageCode\":796,\"RequestToken\":\"110952bf-df6d-425d-b538-034b34b0b3c0\"}","Aggregated":false}

2021-01-11 10:32:45.423 ERROR 40 --- [nio-8088-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/etoro-api] threw exception [Request processing failed; nested exception is ok.work.etoroapi.transactions.TransactionError: Code: 796, details: null] with root cause


ok.work.etoroapi.transactions.TransactionError: Code: 796, details: null

at ok.work.etoroapi.transactions.TransactionPool.getFromPool(TransactionPool.kt:35) ~[classes!/:na]

at ok.work.etoroapi.client.EtoroHttpClient.openPosition(EtoroHttpClient.kt:126) ~[classes!/:na]

at ok.work.etoroapi.controller.PositionsController.openPosition(PositionsController.kt:27) ~[classes!/:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]

at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.3.RELEASE.jar!/:5.2.3.RELEASE]

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.30.jar!/:9.0.30]

at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

And for full confirmation, watchlist looks like this:

[
  {
    "id": "2163",
    "name": "tui.l",
    "fullName": "TUI AG",
    "buy": 356.12,
    "sell": 354.58,
    "marketOpen": true,
    "askDiscounted": 355.8,
    "bidDiscounted": 354.9
  }
]

And position being sent was:

{
  "name": "tui.l",
  "type": "SELL",
  "amount": 123,
  "leverage": 1,
  "takeProfitRate": 100.12,
  "stopLossRate": 500.03,
  "tsl": true
}

(Confirmed those TP/SL values were valid from the etoro front end)

WarlaxZ avatar Jan 11 '21 10:01 WarlaxZ

hi, thanks fore pointing this out, i'll look how to fix it.

Oleg


От: WarlaxZ [email protected] Отправлено: 11 января 2021 г. 12:28 Кому: ok24601/etoro-api [email protected] Копия: ok24601 [email protected]; Comment [email protected] Тема: Re: [ok24601/etoro-api] Error with shorting (sell) positions (#20)

Also tried with:

"takeProfitRate": 500.00, "stopLossRate": 320.00,

Just to really test the water, but still failed

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ok24601/etoro-api/issues/20#issuecomment-757859840, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVSAAESYMMD3ZXTVKCTSZLHGHANCNFSM4V3BPZXA.

ok24601 avatar Jan 11 '21 11:01 ok24601

Hero, thank you so much for this library!

WarlaxZ avatar Jan 11 '21 12:01 WarlaxZ

I've done a quick look to see what the actual packet should look like when sent to etoro, hopefully this help!:

https://www.etoro.com/sapi/trade-demo/positions?client_request_id=XXXXX

{
    "CID":XXXXX,
    "InstrumentID":2163,
    "IsBuy":false,
    "Leverage":1,
    "StopLossRate":374.62,
    "TakeProfitRate":279.31,
    "IsTslEnabled":true,
    "View_UnitMargin":4.82908408,
    "View_MaxPositionUnits":1440,
    "View_Units":1041.61,
    "View_openByUnits":false,
    "IsDiscounted":false,
    "ViewRateContext": {
        "ClientViewRate":358.48,
        "ClientViewRateID":XXXX,
        "ClientRateForCalc":359.7,
        "ClientRateForCalcID":XXXX
    },
    "Amount":5030,
    "View_Source_Application":"apps-components-autocomplete-autocomplete.view-trade-button",
    "View_Source_Location":"/portfolio",
    "View_CurrentTradingMode":"REGULAR"
}

buy position for reference:

https://www.etoro.com/sapi/trade-demo/positions?client_request_id=XXXX'

{
    "CID":XXXX,
    "InstrumentID":2163,
    "IsBuy":true,
    "Leverage":1,
    "StopLossRate":351.95,
    "TakeProfitRate":1158.88,
    "IsTslEnabled":false,
    "View_UnitMargin":4.8496525,
    "View_MaxPositionUnits":1440,
    "View_Units":20.62,
    "View_openByUnits":false,
    "IsDiscounted":true,
    "ViewRateContext":{
        "ClientViewRate":359.9,
        "ClientViewRateID":XXXX,
        "ClientRateForCalc":360,
        "ClientRateForCalcID":XXXX
    },
    "Amount":100,
    "View_Source_Application":"apps-components-autocomplete-autocomplete.view-trade-button",
    "View_Source_Location":"/portfolio",
    "View_CurrentTradingMode":"REGULAR"
}

difference I can spot:

"IsBuy":false,
"IsDiscounted":false,

Looking at your code nothing jumps out at me, but I don't have an IDE installed to breakpoint it to see the actual error, although IsBuy looks like its set correctly

If theres anything else I can help with, please let me know, I'm desperate to get this working and this is literally the final piece for me, so I'm more than happy to help where I can

WarlaxZ avatar Jan 11 '21 12:01 WarlaxZ

ok, thanks for this overview it's helpfull, it can be it's because price for SELL is discounted, in theory my code should use discounted price in this case but may be smthng went wrong


От: WarlaxZ [email protected] Отправлено: 11 января 2021 г. 14:40 Кому: ok24601/etoro-api [email protected] Копия: ok24601 [email protected]; Comment [email protected] Тема: Re: [ok24601/etoro-api] Error with shorting (sell) positions (#20)

I've done a quick look to see what the actual packet should look like when sent to etoro, hopefully this help!:

https://www.etoro.com/sapi/trade-demo/positions?client_request_id=XXXXX

{ "CID":XXXXX, "InstrumentID":2163, "IsBuy":false, "Leverage":1, "StopLossRate":374.62, "TakeProfitRate":279.31, "IsTslEnabled":true, "View_UnitMargin":4.82908408, "View_MaxPositionUnits":1440, "View_Units":1041.61, "View_openByUnits":false, "IsDiscounted":false, "ViewRateContext": { "ClientViewRate":358.48, "ClientViewRateID":XXXX, "ClientRateForCalc":359.7, "ClientRateForCalcID":XXXX }, "Amount":5030, "View_Source_Application":"apps-components-autocomplete-autocomplete.view-trade-button", "View_Source_Location":"/portfolio", "View_CurrentTradingMode":"REGULAR" }

buy position for reference:

https://www.etoro.com/sapi/trade-demo/positions?client_request_id=XXXX'

{ "CID":XXXX, "InstrumentID":2163, "IsBuy":true, "Leverage":1, "StopLossRate":351.95, "TakeProfitRate":1158.88, "IsTslEnabled":false, "View_UnitMargin":4.8496525, "View_MaxPositionUnits":1440, "View_Units":20.62, "View_openByUnits":false, "IsDiscounted":true, "ViewRateContext":{ "ClientViewRate":359.9, "ClientViewRateID":XXXX, "ClientRateForCalc":360, "ClientRateForCalcID":XXXX }, "Amount":100, "View_Source_Application":"apps-components-autocomplete-autocomplete.view-trade-button", "View_Source_Location":"/portfolio", "View_CurrentTradingMode":"REGULAR" }

difference I can spot:

"IsBuy":false, "IsDiscounted":false,

Looking at your code nothing jumps out at me, but I don't have an IDE installed to breakpoint it to see the actual error, although IsBuy looks like its set correctly

If theres anything else I can help with, please let me know, I'm desperate to get this working and this is literally the final piece for me, so I'm more than happy to help where I can

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ok24601/etoro-api/issues/20#issuecomment-757926533, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVQSIFXOUXVRHCFBTXDSZLWT7ANCNFSM4V3BPZXA.

ok24601 avatar Jan 11 '21 13:01 ok24601

maybe worth adding an override param perhaps.

from what I can see in your code it calls:

assetInfo.getBoolean("AllowDiscountedRates") which is just fixed no matter the direciton. I think its weird that the same asset should or shouldnt have a discount depending on the direction. to be honest I'm really not even sure what the discount is and how u get it. I did also notice i missed off the trailing stop when i manually opened the buy, so no idea if a trailing stop would affect the discount.

might be worth changing it to !type && assetInfo.getBoolean("AllowDiscountedRates")

WarlaxZ avatar Jan 11 '21 13:01 WarlaxZ

sorry i mean type not !type - as discount is only allowed on buys

(type = position.type.equals(PositionType.BUY))

WarlaxZ avatar Jan 11 '21 13:01 WarlaxZ

nope re-ran is isdiscounted set to false and that doesnt seem to have done the magic trick :/

WarlaxZ avatar Jan 11 '21 13:01 WarlaxZ

So I tried replaying an actual post an I dont get an error, however the position didnt open (presumably because the ID for calc might have been a dupe, not entirely sure. Also one thing I noticed as that the caps get lost in you post body, ie your looks like this:

{
    "amount": 50,
    "instrumentID": "2163",
    "isBuy": false,
    "isDiscounted": false,
    "isTslEnabled": false,
    "leverage": 1,
    "stopLossRate": 355.98,
    "takeProfitRate": 178.81,
    "view_MaxPositionUnits": 1440,
    "view_openByUnits": false,
    "view_Units": 0.01,
    "viewRateContext": {
        "clientViewRate": 356.3
    }
}

so vs a real packet we're missing:

   "View_CurrentTradingMode": "REGULAR",
    "View_Source_Application": "apps-components-autocomplete-autocomplete.view-trade-button",
    "View_Source_Location": "/markets/tui.l",
    "View_UnitMargin": 0.87582864,
    "View_Units": 114.18, <--- this is always fixed at 0.01 in your code (probably not a problem)
    "ViewRateContext": {
        "ClientRateForCalc": 65.04,
        "ClientRateForCalcID": XXXXX,
        "ClientViewRateID": XXXX
    }

WarlaxZ avatar Jan 11 '21 14:01 WarlaxZ

u had any joy with this? not being able to set any breakpoints to investigate properly was killing me yesterday, that and I've not used kotlin before :P let me know if theres anything I can help you with to get this up and running though

WarlaxZ avatar Jan 12 '21 11:01 WarlaxZ

hi, I din't get a chance to take a look on that, had a lot of work this week. Will probably do it on weekends.


От: WarlaxZ [email protected] Отправлено: 12 января 2021 г. 13:07 Кому: ok24601/etoro-api [email protected] Копия: ok24601 [email protected]; Comment [email protected] Тема: Re: [ok24601/etoro-api] Error with shorting (sell) positions (#20)

u had any joy with this? not being able to set any breakpoints to investigate properly was killing me yesterday, that and I've not used kotlin before :P let me know if theres anything I can help you with to get this up and running though

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ok24601/etoro-api/issues/20#issuecomment-758583575, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVUZHDYZEE5RJO7TDBDSZQUQ3ANCNFSM4V3BPZXA.

ok24601 avatar Jan 12 '21 12:01 ok24601

ok - once again thank you so much for the library, and do let me know if there is anything you need from me to assist

WarlaxZ avatar Jan 12 '21 14:01 WarlaxZ

any luck?

WarlaxZ avatar Jan 17 '21 11:01 WarlaxZ

nope couldnt test it because market was closed on weekends, will try to fix it on the week

ok24601 avatar Jan 19 '21 21:01 ok24601

ah lol didnt think about that either, stupid markets :P as always let me know if theres anything i can do to assist

WarlaxZ avatar Jan 20 '21 00:01 WarlaxZ

By me is not able to open trades on LOGN.ZU. Go errors on these too: ASC.L, SMSN.L, ABBN.ZU

Seem that don't like to open trades on assets with extension .L, .ZU :)

Is possible to use uppercase or lowercase in all assets because I see cryptos, forex are in uppercase?

username77 avatar Jan 20 '21 06:01 username77

i'm fairly certain i get the same issue with american stocks, so no '.blah' extention (for example "bb") - but the casing thing certainly is annoying, might be worth a .lower()/upper() (or language equivalent) on all variables just to harmonize them, as symbols are case insensitive

WarlaxZ avatar Jan 20 '21 11:01 WarlaxZ

how u getting on?

WarlaxZ avatar Jan 21 '21 14:01 WarlaxZ

bump

WarlaxZ avatar Jan 31 '21 14:01 WarlaxZ