Basic bittrex api question

1

I read the api documentation but I could not find anythin related to market buy and sell commands. Where do I find this information?

Moreover, I read the following from the api site

https://bittrex.com/api/v1.1/market/selllimit?apikey=API_KEY&market=BTC-LTC&quantity=1.2&rate=1.3

My understand of this statement is that I use my 1.2 Bitcoin to buy 1.3X1.2 Litecoin. Is this correct?

If I want to use my Litecoin to buy Bitcoin, do I need to change the market from BTC-LTC to LTC-BTC??

Marco

Posted 2017-12-25T23:30:54.327

Reputation: 265

I see someone has voted to close this using the "customer relationship" reason. Note that this should be a publicly answerable question about a public API and should not be closed for that reason. C.f. https://bitcoin.meta.stackexchange.com/questions/871/usage-of-the-off-topic-reason-customer-relationship

MeshCollider 2017-12-26T02:17:04.217

If anyone know about how to use the conditional buy in api, that would help too.Marco 2017-12-26T03:00:05.273

Answers

0

My understand of this statement is that I use my 1.2 Bitcoin to buy 1.3X1.2 Litecoin. Is this correct?

The quantity parameter refers to how many of the coin you want to buy, and the rate parameter as to the limit price you want to buy/sell those coins at.

Example, buy 100 dogecoin at 0.00000400 BTC each.

https://bittrex.com/api/v1.1/market/buylimit?apikey=api_key&market=BTC-DOGE&quantity=100&rate=0.000004&nonce=nonce

If I want to use my Litecoin to buy Bitcoin, do I need to change the market from BTC-LTC to LTC-BTC??

No, the market stays the same, just change part of the URI from /buylimit? to /selllimit? or vice-versa. Selling your litecoin for bitcion is the same as buying bitcoin with litecoin.

You can make it act like a market order by checking the current bid/ask and making your rate equal to the side your trading. For example if you want to market buy you can query the best ask price and then make that the rate.

function fetchPairPrice($pair){
    $pair = strtoupper($pair);
    $uri = "https://bittrex.com/api/v1.1/public/getticker?market=BTC-".$pair;
    $ch = curl_init($uri);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $execResult = curl_exec($ch);
    $obj = json_decode($execResult, true);
    return $obj;
}


function bittrexbuy($apikey, $apisecret, $symbol, $quant, $rate){
    $nonce=time();
    $uri='https://bittrex.com/api/v1.1/market/buylimit?apikey='.$apikey.'&market=BTC-'.$symbol.'&quantity='.$quant.'&rate='.$rate.'&nonce='.$nonce;
    $sign=hash_hmac('sha512',$uri,$apisecret);
    $ch = curl_init($uri);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
    $execResult = curl_exec($ch);
    $obj = json_decode($execResult, true);
    return $obj;
}

    $symbolRate = fetchPairPrice("DOGE");
    $fetchPrice = $symbolRate["result"]["Ask"];
    $amountToBuy = 100;
    bittrexbuy($apikey, $apisecret, $symbol, $amountToBuy, $fetchPrice);

    //response
    //{"success":true,"message":"","result":{"uuid":"b5f891ab-a7b4-44aa-9488-94986d1d9551"}}

m1xolyd1an

Posted 2017-12-25T23:30:54.327

Reputation: 3 356