ChristopherHaws / gdax-dotnet

DotNet Core GDAX Exchange API
MIT License
7 stars 7 forks source link

HttpMethod.Post - Not passing parameters #1

Closed InTheta closed 6 years ago

InTheta commented 6 years ago

I know you have not implemented any Post requests, but when I am sending a post request for an order or withdrawal, it does not seem to pass any params.

I have added the params, and also tried with no Post params at all, and the error is always ;

{"message":"Missing product_id"} {"message":"currency is required"}

`public async Task<Order> SubmitMarketOrderCrypto(Side side, String productID, Double size, Double funds, OrderType orderType = OrderType.Market)
        {
            var request = new GdaxRequestBuilder("/orders", HttpMethod.Post)

                .AddParameterIfNotNull("side", ((Side)side).ToString())
                .AddParameterIfNotNull("product_id", productID)
                .AddParameterIfNotNull("type", ((OrderType)orderType).ToString())
                .AddParameterIfNotNull("size", ((Double)size).ToString())
                .AddParameterIfNotNull("funds", ((double)size).ToString())

                .Build();

            return (await this.GetResponse<Order>(request).ConfigureAwait(false)).Value;

        }`
ChristopherHaws commented 6 years ago

Hello @ColossusFX,

I believe the issue here is that the AddParameterIfNotNull method is for adding query string parameters to the request, but the parameters that GDAX is expecting is a json object in the body. Something like this should work:

internal class SubmitMarketOrderRequest
{
    [JsonProperty("type")]
    public String Type { get; } = "market";

    [JsonProperty("product_id")]
    public String ProductId { get; set; }

    [JsonProperty("side")]
    public Side Side { get; set; }

    [JsonProperty("size")]
    public Decimal Size { get; set; }
}

public async Task<Order> SubmitMarketOrderBySize(Side side, String productId, Double size)
{
    var model = new SubmitMarketOrderRequest
    {
        Side = side,
        ProductId = productId,
        Size = size
    };

    var request = new GdaxRequestBuilder("/orders", HttpMethod.Post)
        //.AddBody(model)
        .Build();

    //TODO: There should be an AddBody method on the request builder that does this.
    request.RequestBody = JsonConvert.Serialize(model);

    return (await this.GetResponse<Order>(request).ConfigureAwait(false)).Value;
}
InTheta commented 6 years ago

Thanks for replying. It's hard to edit other people's code. Yes I was going over all functions earlier realized I had to serialize the Post message. I will push the branch after I have tested it all. Thanks again