BTCMarkets / API

API
120 stars 30 forks source link

Insufficient funds error using "/v3/batchorders" #173

Open sossee2 opened 4 years ago

sossee2 commented 4 years ago

I'm trying to implement a "Replace Order" where I cancel an existing order and place a similar order with a different price using the /v3/batchorders endpoint and passing in the order to cancel as well as the order to replace it with. However I get an insufficient funds error which tells me that the engine is trying to place the new order before cancelling the old one (I do not have enough funds for both). I would think the batchorders function should process the cancel orders first however that doesn't seem to be the case.

martin-nginio commented 4 years ago

Hi @sossee2

Thanks for your feedback.

I can confirm that with the current implementation it's possible that you can get "insufficient funds" error when the entire fund is used in one of the batch items and this is due to order processing and cancellation operations being asynchronous in our end.

I understand this could be an issue for your use case, so let me review this and will get back to you in the next few days with a solution or workaround. We want to support a variety of trading strategies, so we should try to cover such use cases.

On a related note, I also wanted to mention that the following request format should be helpful for your use case (cancelling an existing order and then creating a new one) but you may already have used this format.

[{"cancelOrder":{"orderId":"12345"}},{"placeOrder":{"marketId":"XRP-AUD","side":"Bid","type":"Limit","price":"0.22","amount":"0.26","clientOrderId":"abc-28"}}]

In above sample, the existing order with orderId 12345 is cancelled and a new order with clientOrderId of abc-28 will be created.

Thanks.

Regards, Martin

sossee2 commented 4 years ago

Thanks Martin, that is indeed what I've been using. I think this is an important feature but understand the challenges in it's implementation.

martin-nginio commented 4 years ago

Hi @sossee2

Thanks for your patience and my apologies for not getting back to you sooner.

Allowing batch orders to consume funds released in the same batch is now active with our dev team and we are aiming to finalize it in 2 weeks time (by November 8th).

I"m hoping this is not blocking your development for now.

Thanks.

Regards, Martin

sossee2 commented 4 years ago

Glad to hear Martin, thanks.

martin-nginio commented 4 years ago

Hi @sossee2

We have made some progress and our team is currently performing final test.

Please can you run your same case again (simulating replace order) and let us know if you are still getting insufficient fund.

Thanks for your help.

Regards, Martin

sossee2 commented 4 years ago

Hey Martin,

I don't appear to be getting any more insufficient funds errors in testing however when I release this into the wild I am getting throttled too hard to really tell. In fact I've had to turn off the feature as the API limits for batch orders are 6 times more restrictive than the regular ones. Given I'm only using batch orders to "replace" my existing orders, this isn't a good enough pay off for me personally. Is it possible to get the batch order API limits be modified so that it matches order placement? Let me know if you want me to raise a seperate ticket.

martin-nginio commented 4 years ago

Hi @sossee2

Thanks for your patience.

We should be able to help you with throttling so please can you create a ticket with our help desk and they can lookup your account and help.

Thanks.

Regards, Martin