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

Parameter name: The Guarded argument was null. #34

Closed
paolobriones opened this issue Jan 31, 2018 · 8 comments
Closed

Parameter name: The Guarded argument was null. #34

paolobriones opened this issue Jan 31, 2018 · 8 comments

Comments

@paolobriones
Copy link

Issue Overview

Trying to execute a Market Order (via client.CreateTestOrder()) with a valid Key/Secret, the code throws an exception saying: "Parameter name: The Guarded argument was null."

Package Version: BinanceDotNet v4.0.1

Repro Steps

BinanceClient client = new BinanceClient(new ClientConfiguration {
ApiKey = "VALIDAPIKEY",
SecretKey = "VALIDSECRETKEY"
});

await client.CreateTestOrder(new CreateOrderRequest {
Symbol = "TRXBTC",
Quantity = 100,

Side = OrderSide.Buy,
Type = OrderType.Market

});

@curious-debug
Copy link

I'm receiving the exact same error on client.CreateOrder. This occurs no matter if it is a market buy or market sell. Also using BinanceDotNet v4.0.1. My ApiKey and Secret are valid.

var createOrderResponse = await client.CreateOrder(new BinanceExchange.API.Models.Request.CreateOrderRequest(){
  Symbol = <<anycoinsymbol - I've tried multiple>>,
  Side = <<BinanceExchange.API.Enums.OrderSide.Buy>> or <<BinanceExchange.API.Enums.OrderSide.Sell>>,
  Type = <<BinanceExchange.API.Enums.OrderType.Market>>, 
  Quantity = <correctly calculated qty that meets rules in Exchange Info payload>>,
  NewClientOrderId = <<my custom string>>
});

I've tried to catch all BinanceExchange.API.Models.Response.Errors, but all I get is this:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
      An unhandled exception has occurred while executing the request
System.ArgumentNullException: Value cannot be null.
Parameter name: The Guarded argument was null.
   at BinanceExchange.API.Client.BinanceClient.<CreateOrder>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at TraderWeb.Controllers.NewApiOrderController.<Post>d__1.MoveNext() in {redacted file path}\NewApiOrderController.cs:line 154 {this is the line where client.CreateOrder exists}
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

@paolobriones
Copy link
Author

Heres what i reckon is happening, based on the binance api docs (https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md), depending on the type of Order you are executing some parameters are required and some are not.

But the code here in BinanceDotNet requires that all parameters be passed into the CreateTestOrder() method.

I.e.
When you execute a Market Buy Order, as per the binance api, the only requirement is the QTY, but in the BinanceDotNet code, Time-In-Force is still a required parameter.

And since you passed in the Time-In-Force value, BinanceDotNet passes that parameter to the binance api which will cause a "Malformed Request" error

@curious-debug
Copy link

@paolobriones @glitch100
So any idea as to the solution? I cannot make any Market orders without getting an error.

On my CreateOrderRequest object in the client.CreateOrder method:

  • If I set TimeInForce = BinanceExchange.API.Enums.TimeInForce.GTC, I receive this:
Malformed requests are sent to the server. Please review the request object/string
  • If I do not include TimeInForce, or if I set TimeInForce = null, I receive this:
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0]
      An unhandled exception has occurred while executing the request
System.ArgumentNullException: Value cannot be null.
Parameter name: The Guarded argument was null.
   at BinanceExchange.API.Client.BinanceClient.<CreateOrder>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---

@paolobriones
Copy link
Author

@ryanjhardinorders thats exactly what i said, its sending additional request parameters that causes the binance api to throw a malformed error

@glitch100 im working on a fix for it now, will send as soon as i can

@paolobriones
Copy link
Author

@glitch100 this bug is related to #10

@curious-debug
Copy link

@paolobriones
OK Cool. I am new to git/github and also relatively new to C#, so if you could be kind enough to guide me a bit on how to implement your changes once posted, I would very much appreciate it. (I'll be a code contributor soon enough!) Thanks!

@glitch100
Copy link
Owner

I believe this fix is included in the #32 release . Please retest there.

If you are wondering it's because I have a deliberate Guard in methods to prevent mandatory parameters being missed. It therefore saves a trip to the API. It appears Binance recently changed which parameters were mandatory. Please try the latest release and see if it fixes your issue

@glitch100 glitch100 moved this from In progress to Done in Enhancement Wave 1 Feb 2, 2018
@paolobriones
Copy link
Author

@glitch100 @ryanjhardinorders
Confirmed, this bug is fixed with release #32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

3 participants