Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with shorting (sell) positions #20

Open
WarlaxZ opened this issue Jan 8, 2021 · 22 comments
Open

Error with shorting (sell) positions #20

WarlaxZ opened this issue Jan 8, 2021 · 22 comments

Comments

@WarlaxZ
Copy link

WarlaxZ commented Jan 8, 2021

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

@ok24601
Copy link
Owner

ok24601 commented Jan 9, 2021 via email

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 9, 2021

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
Copy link
Author

WarlaxZ commented Jan 9, 2021

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
Copy link
Author

WarlaxZ commented Jan 11, 2021

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)

@ok24601
Copy link
Owner

ok24601 commented Jan 11, 2021 via email

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 11, 2021

Hero, thank you so much for this library!

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 11, 2021

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

@ok24601
Copy link
Owner

ok24601 commented Jan 11, 2021 via email

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 11, 2021

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
Copy link
Author

WarlaxZ commented Jan 11, 2021

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

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

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 11, 2021

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

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 11, 2021

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
Copy link
Author

WarlaxZ commented Jan 12, 2021

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

@ok24601
Copy link
Owner

ok24601 commented Jan 12, 2021 via email

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 12, 2021

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
Copy link
Author

WarlaxZ commented Jan 17, 2021

any luck?

@ok24601
Copy link
Owner

ok24601 commented Jan 19, 2021

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

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 20, 2021

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

@username77
Copy link

username77 commented Jan 20, 2021

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?

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 20, 2021

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
Copy link
Author

WarlaxZ commented Jan 21, 2021

how u getting on?

@WarlaxZ
Copy link
Author

WarlaxZ commented Jan 31, 2021

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants