ok24601 / etoro-api

etoro trading REST API
ISC License
101 stars 47 forks source link

A JSONObject text must begin with '{' at 1 [character 2 line 1] #24

Open JustinGuese opened 3 years ago

JustinGuese commented 3 years ago

Hey, when trying out the demo buy I'm getting the error A JSONObject text must begin with '{' at 1 [character 2 line 1] Command is exactly like in the readme curl -X POST \ http://localhost:8088/etoro-api/positions/open \ -H 'Content-Type: application/json' \ -H 'mode: Demo' \ -d '{ "name": "btc", "type": "BUY", "amount": 100, "leverage": 1, "takeProfitRate": 13000, "stopLossRate": 1000 }'

Any ideas? Running ubuntu 20.04 openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

JustinGuese commented 3 years ago

Full output of api server


org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
    at org.json.JSONTokener.syntaxError(JSONTokener.java:505) ~[json-20180813.jar!/:na]
    at org.json.JSONObject.<init>(JSONObject.java:215) ~[json-20180813.jar!/:na]
    at org.json.JSONObject.<init>(JSONObject.java:399) ~[json-20180813.jar!/:na]
    at ok.work.etoroapi.client.EtoroHttpClient.openPosition(EtoroHttpClient.kt:201) ~[classes!/:na]
    at ok.work.etoroapi.controller.PositionsController.openPosition(PositionsController.kt:34) ~[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]
JustinGuese commented 3 years ago

What a mess, found it, you can't just type in the values, but need to add a lot of \t and \n to the string. "{\n\t\"name\": \"btc\",\n\t\"type\": \"BUY\",\n\t\"amount\": 1000,\n\t\"leverage\": 1\n}"

JustinGuese commented 3 years ago

And no it is actually related to takeProdit and stopLoss values... What exactly are those? I think the error is thrown if the stopLoss is outside the range of 1-100. Is it the percentage of stop loss? Like 60 --> Stop loss at 60% of the buy price? Does the same go for takeProfit?

Make sure that "takeProfit" and "stopLoss" have valid values.

ok24601 commented 3 years ago

Hi,

Check your takeProfit rate. It seemsto be less than btc price, which is more than 30000$ now.

Am 29.01.2021 um 09:29 schrieb Justin Güse notifications@github.com:



Hey, when trying out the demo buy I'm getting the error A JSONObject text must begin with '{' at 1 [character 2 line 1] Command is exactly like in the readme curl -X POST \ http://localhost:8088/etoro-api/positions/open \ -H 'Content-Type: application/json' \ -H 'mode: Demo' \ -d '{ "name": "btc", "type": "BUY", "amount": 100, "leverage": 1, "takeProfitRate": 13000, "stopLossRate": 1000 }'

Any ideas? Running ubuntu 20.04 openjdk 11.0.9.1 2020-11-04 OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04) OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

— 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/24, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVXSOO4FNIBY7BE6GXLS4JWVLANCNFSM4WYO4QSQ.

ok24601 commented 3 years ago

It’s not percentage, it’s assets price

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Justin Güsemailto:notifications@github.com Sent: Friday, January 29, 2021 9:48 AM To: ok24601/etoro-apimailto:etoro-api@noreply.github.com Cc: Subscribedmailto:subscribed@noreply.github.com Subject: Re: [ok24601/etoro-api] A JSONObject text must begin with '{' at 1 [character 2 line 1] (#24)

And no it is actually related to takeProdit and stopLoss values... What exactly are those? I think the error is thrown if the stopLoss is outside the range of 1-100. Is it the percentage of stop loss? Like 60 --> Stop loss at 60% of the buy price? Does the same go for takeProfit?

Make sure that "takeProfit" and "stopLoss" have valid values.

— 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/24#issuecomment-769667432, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADHNNVULGD7HMZRIFTOSE5DS4JY7BANCNFSM4WYO4QSQ.

gedwin1997 commented 1 year ago

Error! InventarioDAO - findxNombre: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] can you help me

gedwin1997 commented 1 year ago

Error! InventarioDAO - findxNombre: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] 13-Apr-2023 16:04:48.299 GRAVE [http-nio-80-exec-2] com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError javax.faces.application.ViewExpiredException: viewId:/login.xhtml - No se pudo restablecer la vista /login.xhtml. at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:210) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.primefaces.icarus.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:32) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

Error! InventarioDAO - findxNombre: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] Error! InventarioDAO - findxNombre: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1] Error! InventarioDAO - findxNombre: org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]