bchavez / Coinbase

:moneybag: A .NET/C# implementation of the Coinbase API.

Home Page:https://developers.coinbase.com/api/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when creating sell order

t0x1c123 opened this issue · comments

I'm trying to place sell order but I'm getting this error

Flurl.Http.FlurlParsingException: Response could not be deserialized to JSON: POST https://api.coinbase.com/v2/accounts/f456a09d-7116-5215-93f9-fba8e492967e/sells ---> Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.DateTimeOffset'. Path 'data.created_at', line 1, position 177. ---> System.ArgumentException: Could not cast or convert from {null} to System.DateTimeOffset.

Version: 5.0.4
Newtonsoft.JSON version: 11.0.2 (also tried 12.0.1)

Hey @t0x1c123 ,

Thanks for the bug report, could you get a network trace of that API call with Fiddler? I'd like to see the response body by coinbase so we can get this fixed.

You can intercept HTTP requests by using this class:

private class ProxyFactory : DefaultHttpClientFactory
{
   private readonly WebProxy proxy;

   public ProxyFactory(WebProxy proxy)
   {
      this.proxy = proxy;
   }

   public override HttpMessageHandler CreateMessageHandler()
   {
      return new HttpClientHandler
         {
            Proxy = this.proxy,
            UseProxy = true
         };
   }
}
// Call this code before creating new CoinbaseClient()

// localhost.:8888 - is the fiddler port fiddler is listening to:
var webProxy = new WebProxy("http://localhost.:8888", BypassOnLocal: false);

FlurlHttp.Configure(settings =>
   {
      settings.HttpClientFactory = new ProxyFactory(webProxy);
   });

Tools > Fiddler Options...
fiddler_2648

Then look at the response body, and post it here.

Thanks,
Brian

  "data": {
    "id": "f6192933-0e2b-50e5-9140-010812e79c53",
    "fee": { "amount": "0.99", "currency": "EUR" },
    "status": "created",
    "user_reference": "ZKLQALJR",
    "transaction": null,
    "created_at": null,
    "updated_at": null,
    "resource": "sell",
    "resource_path": "/v2/accounts/f456a09d-7116-5215-93f9-fba8e492967e/sells/f6192933-0e2b-50e5-9140-010812e79c53",
    "payment_method": {
      "id": "c3e2b740-ee4b-54f6-acf4-87b20081ad92",
      "resource": "payment_method",
      "resource_path": "/v2/payment-methods/c3e2b740-ee4b-54f6-acf4-87b20081ad92"
    },
    "amount": { "amount": "0.04000000", "currency": "LTC" },
    "total": { "amount": "0.12", "currency": "EUR" },
    "subtotal": { "amount": "1.11", "currency": "EUR" },
    "unit_price": { "amount": "27.75", "currency": "EUR", "scale": 2 },
    "payout_at": "2019-01-17T17:16:34Z",
    "committed": false,
    "instant": true
  }
}

And also getting this error on calling PaymentMethods.ListPaymentMethodsAsync()

Flurl.Http.FlurlParsingException: Response could not be deserialized to JSON: GET https://api.coinbase.com/v2/payment-methods ---> Newtonsoft.Json.JsonSerializationException: Error converting value "card" to type 'System.Collections.Generic.List`1[Coinbase.Models.Limit]'. Path 'data[0].limits.type', line 1, position 608. ---> System.ArgumentException: Could not cast or convert from System.String to System.Collections.Generic.List`1[Coinbase.Models.Limit].

RESPONSE:

{
  "pagination": {
    "ending_before": null,
    "starting_after": null,
    "limit": 25,
    "order": "desc",
    "previous_uri": null,
    "next_uri": null
  },
  "data": [
    {
      "id": "4a894ds623546-3849-5cc5-9bdd-6a78eb524d67",
      "type": "secure3d_card",
      "name": "///",
      "currency": "EUR",
      "primary_buy": false,
      "primary_sell": false,
      "allow_buy": false,
      "allow_sell": false,
      "allow_deposit": false,
      "allow_withdraw": false,
      "instant_buy": true,
      "instant_sell": false,
      "created_at": "2017-12-10T08:13:02Z",
      "updated_at": "2017-12-10T08:13:02Z",
      "resource": "payment_method",
      "resource_path": "/v2/payment-methods/48946236-3849-5cc5-9bdd-6a78e25524d67",
      "limits": {
        "type": "card",
        "name": "Credit/Debit Card",
        "buy": [
          {
            "period_in_days": 7,
            "total": { "amount": "1000.00", "currency": "EUR" },
            "remaining": { "amount": "1000.00", "currency": "EUR" },
            "description": "€1,000 of your €1,000 weekly card limit remaining",
            "label": "Weekly card limit",
            "next_requirement": {
              "type": "buy_history",
              "volume": { "amount": "1000.00", "currency": "USD" },
              "amount_remaining": { "amount": "00", "currency": "USD" },
              "time_after_starting": 2592000
            }
          }
        ],
        "deposit": [
          {
            "period_in_days": 7,
            "total": { "amount": "1000.00", "currency": "EUR" },
            "remaining": { "amount": "1000.00", "currency": "EUR" },
            "description": "€1,000 of your €1,000 weekly card limit remaining",
            "label": "Weekly card limit"
          }
        ]
      },
      "verified": true
    },
    {
      "id": "c3e2fb740-ee4b-54f6-acf4-87b2008d1ad92",
      "type": "fiat_account",
      "name": "EUR Wallet",
      "currency": "EUR",
      "primary_buy": true,
      "primary_sell": true,
      "allow_buy": true,
      "allow_sell": true,
      "allow_deposit": true,
      "allow_withdraw": true,
      "instant_buy": true,
      "instant_sell": true,
      "created_at": "2017-12-10T08:07:47Z",
      "updated_at": "2017-12-10T08:07:47Z",
      "resource": "payment_method",
      "resource_path": "/v2/payment-methods/c3ev2b740-ee4cb-54f6-acdf4-87b2s0081ad92",
      "limits": { "type": "fiat_account", "name": "Coinbase Account" },
      "fiat_account": {
        "id": "2b7da2397d-0c9d-53s23-9199-a3d4aeedbe8f",
        "resource": "account",
        "resource_path": "/v2/accounts/2b723d97d-0c9d-5323-9199-a3d4faeedbe8f"
      },
      "verified": true
    }
  ]
}```

Okay, thanks a bunch. Seems like a model mismatch. Maybe something changed recently. I'll have a fix soon.

Hey @t0x1c123 ,

NuGet v5.0.5 release with fixes should be out in a few minutes soon as build CI is done:

https://ci.appveyor.com/project/bchavez/coinbase/builds/21639763

Let me know if it works for you!

UPDATE: NuGet package now live: https://www.nuget.org/packages/Coinbase/5.0.5

Thanks,
Brian

🚶 😎 "So don't delay... act now supplies are running out..."

Hi @bchavez ,

yes it's working. Appreciate your fast response 👍 Thank you very much!