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

Market Orders - insufficient funds? #78

Open
cheriff opened this issue Dec 20, 2017 · 5 comments
Open

Market Orders - insufficient funds? #78

cheriff opened this issue Dec 20, 2017 · 5 comments

Comments

@cheriff
Copy link

cheriff commented Dec 20, 2017

So I used the API to buy some BCH:
{"currency":"AUD","instrument":"BCH","price":1,"volume":2026972,"orderSide":"Bid","ordertype":"Market","clientRequestId":"test"}
And eventually I saw that get Placed and then Fully Placed. So far so good.


Later I wanted to sell that BCH for BTC:
{"currency":"BTC","instrument":"BCH","price":1,"volume":2026972,"orderSide":"Ask","ordertype":"Market","clientRequestId":"test2"}

Yet this fails: {"success":false,"errorCode":3,"errorMessage":"Insufficient funds.", "id":0, "clientRequestId":"test2"}

But I do have funds, and it's not some rounding error on my side: Both the webpage says so, as does the account api: {"balance":2026972,"pendingFunds":0,"currency":"BCH"} so I should be able to sell 2026972 (/ 100000000.0) BCH, no?


Is the error message not correct and it's something unrelated to balance?
What am I missing

@cheriff cheriff changed the title Market Orders - Market Orders - insufficient funds? Dec 20, 2017
@cheriff
Copy link
Author

cheriff commented Dec 20, 2017

Actually, could this be a timing thing? I wait for the prior order to be FullyMatched before proceeding, and so assume that the balance is available for immediate re-spend.

But is it possible that the order status says matched, but the balance isn't yet visible for a new order to make use of?
I.e if I put a small sleep after seeing the previous order be matched, could that help? And if so, does that mean that the API isn't self-consistent, in that a trade has matched but the proceeds are not yet available?

@mattwithoos
Copy link

Yes, we encounted the same problem in our app, where a withdrawal would occur immediately after purchase and we'd get that error. Basically it's a result of BTCMarkets not being ready to give you those funds. We found that reversing the order of things gave BTCMarkets enough time.

@cheriff
Copy link
Author

cheriff commented Dec 20, 2017

Thanks for sharing your experience.
I guess next up I'll try polling the balance endpoint after the order matched, until it gets credited, and see if that API agrees with whether a new order will be able to access said balance.

@cheriff
Copy link
Author

cheriff commented Dec 30, 2017

OK, so it's not that. I've had a few LTC credited for weeks now, and the account API shows 22110844 LTC available.

I now post an order (that will never get filled due to outrageous price, but should still rest on the book):

# ./trades sell 0.22110844 LTC --btc 1.0
Request:
{ "currency":"BTC","instrument":"LTC","price":100000000, 
  "volume":22110844,"orderSide":"Ask","ordertype":"Limit","clientRequestId":"nop"}
Response:
{ "success":false,"errorCode":3,"errorMessage":"Insufficient funds.",
  "id":0,"clientRequestId":"nop"}

So it's not time related.


Doing the same thing via the web seems to work differently:

If I click to sell "all" my 0.22110844 LTC, it pre-fills the field as selling 0.22062306 LTC.
If I set a price of 1 BTC the expected receive is 0.22013768, i.e 99.78% what is sold, taking into account the fee. The order is then placed:

$ ./trades detail 1057414274
Request:
{"orderIds":[1057414274]}
Response:
{"success":true,"errorCode":null,"errorMessage":null, 
 "orders":[{ 
   "id":1057414274, "currency":"BTC", "instrument":"LTC", "orderSide":"Ask",
   "ordertype":"Limit",
   "creationTime":1514667576992,"status":"Placed",
   "errorMessage":null, "price":100000000, "volume":22062306, "openVolume":22062306, 
   "clientRequestId":null,"trades":[]}]}

Presumably would this match, I would still be left with 0.22110844 - 0.22062306 =0.0004853799999999797 LTC. Which is 0.22% of what I tried to trade for BTC. It looks like the fee is factored in twice: once when determining how much I can see, and again when calculating what I will receive for it. I assume only the latter is acted upon, resulting in an inability to ever trade all my LTC for BTC.

So, this appears to be a dup of #81.

@cheriff
Copy link
Author

cheriff commented Dec 30, 2017

yeah - if I have some amount of LTC, I can only sell 99.78% of that, since the fee is taken on top of what is specified in the order and I need to be able to cover it.

I had expected to be able to sell all my LTC, and simply receive 0.22% less BTC, which seems would have made sense since that what happens when you sell LTC for AUD ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants