adshao / go-binance

A Go SDK for Binance API
MIT License
1.57k stars 686 forks source link

Error -1106 randomly occurring #105

Closed georgk10 closed 4 years ago

georgk10 commented 4 years ago

I'm not sure whether it's a problem regarding this SDK or if it's a problem with Binance (because I'm creating orders quickly one after the other - around 20ms between two orders). Sometimes (like 50% of the time) the following error occurs when my bot tries to place an order:

code=-1106, msg=Parameter 'quantity' sent when not required.

I cannot see why the error occurs, it just seems to be random. I'm using the client to create market orders as quoted below. :

func order(market, side, amount string){ if side == "buy"{ _, err := client.NewCreateOrderService().Symbol(market). Side(binance.SideTypeBuy).Type(binance.OrderTypeMarket). Quantity(amount). Do(context.Background()) if err != nil{ fmt.Println(err) } } if side == "sell" { _, err := client.NewCreateOrderService().Symbol(market). Side(binance.SideTypeSell).Type(binance.OrderTypeMarket). Quantity(amount). Do(context.Background()) if err != nil{ fmt.Println(err) } } }

adshao commented 4 years ago

hi @georgk10 , could you set client.Debug = true to print the request info? I'm not sure the restriction of Market order, however, it would be better to ask admins in binance API telegram group about the error.

georgk10 commented 4 years ago

Hi @adshao , here is the output generated by my bot with client.debug = true:

Binance-golang 2020/01/16 18:06:00 full url: https://api.binance.com/api/v3/order?timestamp=1579197960975&signature=acd8a5a055da0c39a4dbe18b8708594e8f7475374e7c96cecde2fb15d5dbe510, body: quantity=0.000000&side=BUY&symbol=BTCUSDT&type=MARKET Binance-golang 2020/01/16 18:06:00 request: &http.Request{Method:"POST", URL:(url.URL)(0xc42070ee00), Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{"Content-Type":[]string{"application/x-www-form-urlencoded"}, "X-Mbx-Apikey":[]string{"3CKOVkhL4frCVTCeNwLpExQIRjsFQ9Ab0c4OUX59pKRqmpMTH19PsNhgCR9lzlpk"}}, Body:ioutil.nopCloser{Reader:(bytes.Buffer)(0xc42091dd50)}, GetBody:(func() (io.ReadCloser, error))(0x7f9342518900), ContentLength:53, TransferEncoding:[]string(nil), Close:false, Host:"api.binance.com", Form:url.Values(nil), PostForm:url.Values(nil), MultipartForm:(multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil), Response:(http.Response)(nil), ctx:(context.emptyCtx)(0xc42000c4a0)} Binance-golang 2020/01/16 18:06:01 full url: https://api.binance.com/api/v3/order?timestamp=1579197961000&signature=cda371064faa441b1fd16286cecce45318f0de5400bb8e88a4213ff987b63ba7, body: quantity=0.000000&side=BUY&symbol=ETHBTC&type=MARKET Binance-golang 2020/01/16 18:06:01 request: &http.Request{Method:"POST", URL:(url.URL)(0xc42070f080), Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{"X-Mbx-Apikey":[]string{"3CKOVkhL4frCVTCeNwLpExQIRjsFQ9Ab0c4OUX59pKRqmpMTH19PsNhgCR9lzlpk"}, "Content-Type":[]string{"application/x-www-form-urlencoded"}}, Body:ioutil.nopCloser{Reader:(bytes.Buffer)(0xc4208520e0)}, GetBody:(func() (io.ReadCloser, error))(0x7f9342518900), ContentLength:52, TransferEncoding:[]string(nil), Close:false, Host:"api.binance.com", Form:url.Values(nil), PostForm:url.Values(nil), MultipartForm:(multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil), Response:(http.Response)(nil), ctx:(context.emptyCtx)(0xc42000c4a0)} Binance-golang 2020/01/16 18:06:01 full url: https://api.binance.com/api/v3/order?timestamp=1579197961025&signature=621eb739a7c76e3b4abc21af66acbbd5f2e025de8e77e67aa11fe3b8d7e2a217, body: quantity=0.000000&side=SELL&symbol=ETHUSDT&type=MARKET Binance-golang 2020/01/16 18:06:01 request: &http.Request{Method:"POST", URL:(url.URL)(0xc42070f500), Proto:"HTTP/1.1", ProtoMajor:1, ProtoMinor:1, Header:http.Header{"Content-Type":[]string{"application/x-www-form-urlencoded"}, "X-Mbx-Apikey":[]string{"3CKOVkhL4frCVTCeNwLpExQIRjsFQ9Ab0c4OUX59pKRqmpMTH19PsNhgCR9lzlpk"}}, Body:ioutil.nopCloser{Reader:(bytes.Buffer)(0xc420852620)}, GetBody:(func() (io.ReadCloser, error))(0x7f9342518900), ContentLength:54, TransferEncoding:[]string(nil), Close:false, Host:"api.binance.com", Form:url.Values(nil), PostForm:url.Values(nil), MultipartForm:(multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil), Response:(http.Response)(nil), ctx:(context.emptyCtx)(0xc42000c4a0)} Binance-golang 2020/01/16 18:06:01 response: &http.Response{Status:"400 Bad Request", StatusCode:400, Proto:"HTTP/2.0", ProtoMajor:2, ProtoMinor:0, Header:http.Header{"Date":[]string{"Thu, 16 Jan 2020 18:06:01 GMT"}, "Server":[]string{"nginx"}, "X-Mbx-Uuid":[]string{"2b5088c2-b8fc-4f76-88f2-b906c5d71414"}, "X-Cache":[]string{"Error from cloudfront"}, "Via":[]string{"1.1 5e2b2bef8be6bee05fe23de3ed9e3a6e.cloudfront.net (CloudFront)"}, "X-Amz-Cf-Id":[]string{"Q0sqHtThGAz-v_8eXU8a12w1YaWNt4leF4DWNTSi0DjSoL35Augwhw=="}, "X-Mbx-Used-Weight-1m":[]string{"6"}, "X-Content-Type-Options":[]string{"nosniff"}, "Content-Security-Policy":[]string{"default-src 'self'"}, "Pragma":[]string{"no-cache"}, "X-Amz-Cf-Pop":[]string{"DUB2-C1"}, "X-Mbx-Used-Weight":[]string{"6"}, "Strict-Transport-Security":[]string{"max-age=31536000; includeSubdomains"}, "X-Content-Security-Policy":[]string{"default-src 'self'"}, "X-Webkit-Csp":[]string{"default-src 'self'"}, "Expires":[]string{"0"}, "Content-Type":[]string{"application/json;charset=utf-8"}, "X-Frame-Options":[]string{"SAMEORIGIN"}, "X-Xss-Protection":[]string{"1; mode=block"}, "Cache-Control":[]string{"no-cache, no-store, must-revalidate"}}, Body:http.http2transportResponseBody{cs:(http.http2clientStream)(0xc4203d6140)}, ContentLength:-1, TransferEncoding:[]string(nil), Close:false, Uncompressed:false, Trailer:http.Header(nil), Request:(http.Request)(0xc4200ec400), TLS:(*tls.ConnectionState)(0xc4203cc790)} Binance-golang 2020/01/16 18:06:01 response body: {"code":-1106,"msg":"Parameter 'quantity' sent when not required."} Binance-golang 2020/01/16 18:06:01 response status code: 400

code=-1106, msg=Parameter 'quantity' sent when not required.
georgk10 commented 4 years ago

Problem solved, the log showed that quantity was set to 0 due to an calculation problem. Everything works fine now. Thanks for the hint with setting client.debug = true

adshao commented 4 years ago

Problem solved, the log showed that quantity was set to 0 due to an calculation problem. Everything works fine now. Thanks for the hint with setting client.debug = true

Glad to hear that.