Real buy amount is not the same with the input amount
haikalfouzi opened this issue · comments
Hi,
So i finally brave enough to turn off simulation for the trader.php and see how it operates with coinbase, but i ran into a serious issue. So i tried to buy 5 usd worth of eth using the trader.php and sell it after it reaches 6 usd in profit. Here's the command i used:
php trader.php buy 5 6
[i] Will use 'USD Wallet' as currency wallet :)
[i] Will use 'ETH Wallet' as crypto wallet :)
[i] Will use USD Wallet for payments
[i] Buy price: 86.1 USD
[i] Sell price: 84.42 USD
[i] Spot price: 85.21 USD
[i] Difference buy/sell: 1.68 USD
[B #1] Buying 5 USD = 0.058072009291521 ETH
But then i received an email from coinbase, stating that i initiated a buy for 99.13 USD (1.13892042 ETH). The amount that i bought is not the same with what I put in the command.
Just a follow up for this problem.
I think a found a lead, it seems like the php bot confused with the cryptocurrency that i wanted to buy which is ETH. During May 12, 2017, I initiated a buy of 5 usd worth of eth (0.058072009291521 ETH), but the bot bought 99.13 USD worth of eth. At that time, 1 BTC = 1,695.79 USD so i did a test calculation of 0.058072009291521*1,695.79 USD = 98.47 USD. The amount is close to the amount that the bot purchased for me (if i include the tax from the coinbase).
Looking at the trader.php code for buyBTC function, it doesn't specify in which cryptocurrency that it will buy (ETH or BTC), and i assume it will default to BTC since variable $buy will only equal to the value $amount/($this->buyPrice)
function buyBTC($amount,$sellat,$btc=false)
{
$eur = ($btc===true?($this->buyPrice*$amount):$amount); //this will return $eur=$amount
$btc = ($btc===true?$amount:($amount/$this->buyPrice)); //this will return $btc=$amount/($this->buyPrice)
if(SIMULATE===false)
{
$buy = new Buy([
'bitcoinAmount' => $btc,
//'amount' => new Money($btc, CRYPTO),
'paymentMethodId' => $this->wallet->getId()
]);
//check if account has enough currency
if($this->checkBalanceOfAccount($this->currencyWallet)<$eur)
{
echo " [ERR] You don't have enough ".CURRENCY." in your '".$this->currencyWallet->getName()."'. Cancelling buy\n";
return;
}
else
$this->client->createAccountBuy($this->account, $buy);
fixed that by changing $buy to this for function buyBTC and sellBTC
$buy = new Buy([
//'bitcoinAmount' => $btc,
'amount' => new Money($btc, CRYPTO),
'paymentMethodId' => $this->wallet->getId()
]);
testing the bot
php trader.php buy 2 1
[i] Will use 'USD Wallet' as currency wallet :)
[i] Will use 'ETH Wallet' as crypto wallet :)
[i] Will use USD Wallet for payments
[i] Buy price: 235.78 USD
[i] Sell price: 231.1 USD
[i] Spot price: 233.38 USD
[i] Difference buy/sell: 4.68 USD
[B #1] Buying 2 USD = 0.0084824836712189 ETH
Case solved.
oh wow.. for some reason with € it works with the old code. Want to send a pull request?
nevermind, already pushed it