Anyone know a way I can get 'AsksPrice' by
USD volume, when trading BTC/USD?
I'm familiar with the function
trader.get("AsksPrice",volume), but this requires me knowing the volume in BTC. How do I convert to USD?
In short, I'm trying to create a function that will establish the lowest price in the order book that I can execute a market buy based on my current USD balance.
I can't do:-
var myUSD = trader.get("Balance","USD");
var price = trader.get("AsksPrice",myUSD);
and neither can I do:-
var myUSD = trader.get("Balance","USD");
var price = trader.get("AsksPrice",myUSD/price);
Any help would be appreciated!
try this:
var price = trader.get("AskPrice");
var myVolume = trader.get("Balance","USD") /price;
price = trader.get("AsksPrice", myVolume);
Most software doesn't handle math inside function calls. Doing all the math for it in advance helps a lot. The one problem I see with my suggestion is You need a starting price. Now you won't know for sure that the price of the current ask is the price the bot would settle on. If the price change where too high it could cause some error in the actual volume. This should be fairly small I would think but if it turns out to be non-negligible you might want to rerun the last two lines again. Like this.
var price = trader.get("AskPrice");
var myVolume = trader.get("Balance","USD") /price;
price = trader.get("AsksPrice", myVolume);
myVolume = trader.get("Balance","USD") /price;
price = trader.get("AsksPrice", myVolume);
This would find a price that should support your balance then use that price to try again. It should reduce the error amount but will not entirely eliminate it as the volume is based on price and as the price changes so will the volume. For small enough amounts the first should work perfectly. For large enough amounts there would likely need to be either an acceptable error rate or one could adjust the initial volume by some amount to make sure that the final price would definitely have the volume to cover it.
EDIT: After sleeping on this problem I can conclude that the worry I had about errors should be more or less a non-issue. As the price goes up the volume would actually be decreasing. The first example should work without issues. If it does not could you let everyone know? I may have another way to solve it if none of the above works for you.