barrywood78 / Coinbase.AdvancedTrade

Coinbase Advanced Trade API Wrapper
8 stars 1 forks source link

CreateMarketOrder #19

Closed stephanie-rimel closed 2 months ago

stephanie-rimel commented 2 months ago

Hi i am using your api with good success but yesterday i started having an error with the CreateMarketOrderAsync, it is returning clientOrderId instead of Orderid and i have no idea why because before it worked perfectly fine. Can you check it and help me? It places the order fine, but when i go to fetch the order with the order id it cannot get it because its the clientorderid and not the order id. Is there any way you could add functionality to just return the order with the CreateMarketOrder instead of just the order id also?

barrywood78 commented 2 months ago

Hi Stephanie. Thanks for bringing up this issue. I'm out of town right now but will look at tomorrow when I'm back.

On Wed, Jun 12, 2024, 2:28 a.m. Stephanie Rimel @.***> wrote:

Hi i am using your api with good success but yesterday i started having an error with the CreateMarketOrderAsync, it is returning clientOrderId instead of Orderid and i have no idea why because before it worked perfectly fine. Can you check it and help me? It places the order fine, but when i go to fetch the order with the order id it cannot get it because its the clientorderid and not the order id. Is there any way you could add functionality to just return the order with the CreateMarketOrder instead of just the order id also?

— Reply to this email directly, view it on GitHub https://github.com/barrywood78/Coinbase.AdvancedTrade/issues/19, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5WQUOZB6OXYYYII67MAZG3ZG7TBZAVCNFSM6AAAAABJFVUMDOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM2DOOJRGY4TAMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

stephanie-rimel commented 2 months ago

That would be great! I am wondering if maybe its a coinbase issue because before it worked completely fine, I updated the package and still having this error.

barrywood78 commented 2 months ago

@stephanie-rimel

I had a chance to look at this and at this point, everything appears to be normal for me. I'm not sure what your code looks like that you're using to confirm that it's returning the clientOrderId.

I have a test project that I'm using and I put a breakpoint on this function: CreateOrderAsync which is called in the CreateMarketOrderAsync function.

CreateOrderAsync is set to return the order_id from the Coinbase REST API call. Here's the code here that ultimately returns the order ID: image

This is what the REST API returns from Coinbase: { "order_id": "5ad103bc-1cb0-46ca-97fa-77068b6272ff", "product_id": "BTC-USDC", "side": "BUY", "client_order_id": "a8090b7e-0c27-4f15-98cc-74afe93dfd46" }

And here's a screenshot from Coinbase showing that order with that order_id: image

At some point, possibly Coinbase was returning the wrong ID for Order ID but when I test it currently, it appears to be working fine.

As for modifying the code to return an Order object, I can possibly do that. It would require a 2 step approach on my end as when you place an order, Coinbase ultimately just returns the Order ID and not the other details. I would have to place the order, and then run the GetOrderAsync to return the Order. I will have a look at this to see what's involved.

Please confirm though how your code is set up and if it's still not working properly for you.

Thanks! :)

stephanie-rimel commented 2 months ago

are you able to pull up the order with order = await _coinbaseCLient.Orders.GetOrderAsync(orderId); ? Because I still have this error for some reason. It makes no sense to me because I checked and I am receiving the OrderId as well but it is still not returning my order. This is the same code I used when it worked previously, I added a sleep of 5000 and checked that I am using the correct model as well

stephanie-rimel commented 2 months ago

the error i am getting is simply object not set to instance of an object. Please can you check? Thank you so much for your help.

barrywood78 commented 2 months ago

@stephanie-rimel

I put together a small test project. CreateMarketOrder_Issue19.zip

Code:

using Coinbase.AdvancedTrade; using Coinbase.AdvancedTrade.Enums; using Coinbase.AdvancedTrade.Models;

namespace CreateMarketOrder_Issue19 { internal class Program { private static CoinbaseClient? _coinbaseClient = null;

    static async Task Main(string[] args)
    {
        // Coinbase Developer Platform Keys
        var apiKey = Environment.GetEnvironmentVariable("COINBASE_CLOUD_TRADING_API_KEY", EnvironmentVariableTarget.User);
        var apiSecret = Environment.GetEnvironmentVariable("COINBASE_CLOUD_TRADING_API_SECRET", EnvironmentVariableTarget.User);

        _coinbaseClient = new CoinbaseClient(apiKey: apiKey, apiSecret: apiSecret);

        string orderNumber = await _coinbaseClient!.Orders.CreateMarketOrderAsync("BTC-USDC", OrderSide.BUY, "1");

        Console.ForegroundColor = ConsoleColor.Green;
        Console.WriteLine($"Market Buy order placed. Order Number: {orderNumber}");
        Console.WriteLine();

        Console.WriteLine("Market Buy Order Details:");
        Console.ResetColor();

        Order order = await _coinbaseClient!.Orders.GetOrderAsync(orderNumber);

        Console.WriteLine($"Order ID: {order.OrderId}");
        Console.WriteLine($"Product ID: {order.ProductId}");
        Console.WriteLine($"Order Side: {order.Side}");
        Console.WriteLine($"Order Type: {order.OrderType}");
        Console.WriteLine($"Status: {order.Status}");
        Console.WriteLine($"Created Time: {order.CreatedTime}");
        Console.WriteLine($"Completion Percentage: {order.CompletionPercentage}");
        Console.WriteLine($"Average Filled Price: {order.AverageFilledPrice}");
        Console.WriteLine($"Filled Size: {order.FilledSize}");
        Console.WriteLine($"Filled Value: {order.FilledValue}");
        Console.WriteLine($"Number of Fills: {order.NumberOfFills}");
        Console.WriteLine($"Fee: {order.Fee}");
        Console.WriteLine($"Total Fees: {order.TotalFees}");
        Console.WriteLine($"Total Value After Fees: {order.TotalValueAfterFees}");
        Console.WriteLine($"Time In Force: {order.TimeInForce}");
        Console.WriteLine($"Size In Quote: {order.SizeInQuote}");
    }

}

}

I ran this a bunch of times without issue:

image

But.....

Funny enough, after a bunch of runs, I got the following error because the order object was Null. It seemed like for whatever reason, Coinbase's API returned nothing back. This didn't happen all the time but I did get it to reoccur twice in about 15 runs. It's not this line causing the error though per se, "Order order = await _coinbaseClient!.Orders.GetOrderAsync(orderNumber);" but instead me not checking to see of order is null and directly calling its property: "Console.WriteLine($"Order ID: {order.OrderId}");" image

My assumption is Coinbase doesn't have the Order Id yet for this API call and just returns null image

Solutions:

Let me know if any of this helps in any way. :)

stephanie-rimel commented 2 months ago

I would love a method that returns the entire order if you can offer it, I dont know whats going on even with 10000 sleep I get a null error. I am going to post the output for you

stephanie-rimel commented 2 months ago

is there any way you can modify the code to return both the ClientOrderId and the OrderId? The only thing that could be happening on my end is that my coinbase server is returning the ClientOrderId and not the order Id because it is not the GetOrderAsync method so it has to be a problem on the coinbase end where its returning the ClientOrderId for me. It is so strange. Please can you help me with this I hate to trouble you with it but theres nothing else I can do except switch api's and the other one I used has a jwt token problem so AHHHH

stephanie-rimel commented 2 months ago

image every single one of the orderId's are returned by the CreateMarketOrderAsync

stephanie-rimel commented 2 months ago

maybe its one of those things where they roll out updates in different regions or something but I am getting the clientOrderId back and not the OrderId but it looks like there is a mixup of the fields in the database

barrywood78 commented 2 months ago

Thanks for the info. Unfortunately as I don't have access to your Coinbase orders to confirm the order ID's vs ClientOrderId within Coinbase itself, there's not a whole lot I can do. I've tested this multiple times today and it seems good on my end. I've had some others try without issue and unfortunately I haven't heard from anyone else suggesting an issue with this. You can confirm the order ID's by logging into Coinbase and confirming the order details: image

I would prefer not to modify the code to return both ClientOrderId and the OrderId from CreateMarketOrderAsync. Instead though, I am working on overloaded methods including CreateMarketOrderAsync that will return the Order object instead of the Order Id. I have already worked on some of this work and need to just do some final testing and hope to push to Github & Nuget tomorrow sometime.

barrywood78 commented 2 months ago

FYI, I just updated my code on GitHub and pushed version 1.4 to Nuget. This includes the order method overloads that return the Order object. Hope this helps.

stephanie-rimel commented 2 months ago

So i am still getting an order null for this. I even changed my key although I am positive this isnt it. It has to be on my coinbase. I think they have switched the orderId and clientorderid on my coinbase end because i am capable of placing the order i just cant get the order with the getorderasync call. I hate to keep troubling you but is there anyway you can return both the client order id and the order id? i am so sorry to bug you i can send some money to you on paypal if you can

barrywood78 commented 2 months ago

So I'm clear, you got the new version and the Market Order method is returning null? No need to send me money, all good thanks. You can also grab the solution here on GitHub to run the test project using your keys, put break points, etc to confirm what's being returned.

I can look to return both the order id and the client order id but I'm curious what you gain from that?

On Fri, Jun 14, 2024, 10:37 p.m. Stephanie Rimel @.***> wrote:

So i am still getting an order null for this. I even changed my key although I am positive this isnt it. It has to be on my coinbase. I think they have switched the orderId and clientorderid on my coinbase end because i am capable of placing the order i just cant get the order with the getorderasync call. I hate to keep troubling you but is there anyway you can return both the client order id and the order id? i am so sorry to bug you i can send some money to you on paypal if you can

— Reply to this email directly, view it on GitHub https://github.com/barrywood78/Coinbase.AdvancedTrade/issues/19#issuecomment-2169064481, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5WQUOZVNSDUIURLZ5TAHKDZHOSH5AVCNFSM6AAAAABJFVUMDOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZGA3DINBYGE . You are receiving this because you commented.Message ID: @.***>

stephanie-rimel commented 2 months ago

Or can you think of a way i could implemnt this on my end? Can i just overload this myself?

stephanie-rimel commented 2 months ago

Because there is a mixup of coinbase where clientorderid and orderid are switched, so if i have the other field i can fetch my order.

stephanie-rimel commented 2 months ago

Yes the new version is also returning null because my fields from coinbase are reversed so it wouldnt be able to get the order from your end either

barrywood78 commented 2 months ago

It's late where I am so I will look at tomorrow. One more question: you mentioned this was working fine recently and then suddenly stopped?

On Fri, Jun 14, 2024, 11:00 p.m. Stephanie Rimel @.***> wrote:

Yes the new version is also returning null because my fields from coinbase are reversed so it wouldnt be able to get the order from your end either

— Reply to this email directly, view it on GitHub https://github.com/barrywood78/Coinbase.AdvancedTrade/issues/19#issuecomment-2169070644, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5WQUOYCN7ROVO2ICFOYVFDZHOU3LAVCNFSM6AAAAABJFVUMDOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZGA3TANRUGQ . You are receiving this because you commented.Message ID: @.***>

stephanie-rimel commented 2 months ago

yes, its the exact same code i had before and the getOrderAsync call works on the other field, but its not the first time this has happened. Its definitly a coinbase error.

barrywood78 commented 2 months ago

Can you confirm what currency pair you're using. Saw this on the Coinbase discord channel. Screenshot_20240615_000141_Discord

stephanie-rimel commented 2 months ago

every single one has been like this for me fil-usd neon-usd storj-usd just to name a few

stephanie-rimel commented 2 months ago

but the thing is, i can still pull up the order when i use the order Id that is not returned by getOrderAsync

stephanie-rimel commented 2 months ago

ok dont do anything else i havent gotten any orders since the 11th and couldnt see it in the database

barrywood78 commented 2 months ago

@stephanie-rimel From what I gather, there appears to be no issues with the API wrapper and most likely your setup or understanding of your system since you're suggesting you haven't received orders since Jun 11. Closing this issue.