익명 19:58

Basic bittrex api question

Basic bittrex api question

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??



Top Answer/Comment:

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"}}
상단 광고의 [X] 버튼을 누르면 내용이 보입니다