API Prywatne

API prywatne

Connecting with API

To connect with API you have to send POST request on address below:

https://bitbay.net/API/Trading/tradingApi.php

Request must have method parameter, which calls proper operation. Next parameter of each request is moment - it is current time in unix timestamp format.

API Keys

When you want to call API operation you need authentication key. Key generation is in account page, under “API Keys” tab

Each key consist of 3 properties:

  • public key : you can see it on keys list, it is used for recognizing user and key
  • secret key : this one is visible only after generating; after this operation you cannot see it anywhere. Secret key is used to authenticate user, which calls API operation
  • permissions : when generating new key you can set permissions for specific operations

Signing requests

POST requests have to be signed by authentication code. You have to use secret key for that, which you use to sign parameters with SHA512 algorithm. It is neccessary to send public key in header as API-Key and also hashed post message as API-Hash.

Example:

$params["method"] = “info”;    
$params["moment"] = time();
$post = http_build_query($params, "", "&");
$sign = hash_hmac("sha512", $post, $secret);
$headers = array(
        "API-Key: " . $key,
        "API-Hash: " . $sign,
        );

Moment parameter

It is request execution unix timestamp. This value is compared with server time. If difference is bigger than 5 seconds - operation won’t be executed. It is important to have synchronized time with NTP public time server - in other case server time can differ a lot than time of request machine.

Example PHP execution code

function BitBay_Trading_Api($method, $params = array())
{
    $key = "123";
    $secret = "321";

    $params["method"] = $method;        
    $params["moment"] = time();

    $post = http_build_query($params, "", "&");
    $sign = hash_hmac("sha512", $post, $secret);
    $headers = array(
        "API-Key: " . $key,
        "API-Hash: " . $sign,
    );
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_URL, "https://bitbay.net/API/Trading/tradingApi.php");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $ret = curl_exec($curl);

    return $ret;
}

API call rate limit

The rate limit is 1 req / second.

API methods

List of methods, which you have to send in method parameter.

info - returns information about account balances

Input:

  • (optional) currency : currency shortcut if you want to display only specific balance (e.g. “BTC”)

Output:

  • currency : shortcut
  • available : amount of available money/cryptocurrency
  • locked : amount of locked money/cryptocurrency
  • trade - places offer at the stock market

Input:

  • type : offer type bid/buy or ask/sell
  • currency : shortcut of main currency for offer (e.g. “BTC”)
  • amount : quantity of main currency
  • payment_currency : shortcut of currency used to pay for offer (e.g. “PLN”)
  • rate : rate for offer

Output:

  • order_id : id of placed order
  • error : if any took place
  • cancel - removes offer from the stock market

Input:

  • id : id used to recognize offer; you get it from trade method output

Output:

  • success : if cancelation was successful
  • error : if any
  • orderbook - list of all open offers at the stock market

orderbook - list of all open offers at the stock market

Input:

  • order_currency : shortcut of offer main currency (e.g. “BTC”)
  • payment_currency : shortcut of currency used to pay (e.g. EUR)

Output:

  • bids : object with bids details
  • currency : shortcut of payment currency
  • price : amount of currency for whole offer
  • quantity : amount of offer main currency
  • asks : object with asks details
  • currency : shortcut of payment currency
  • price : amount of currency for whole offer
  • quantity : amount of offer main currency
  • orders - list of all your offers

Input:

  • (optional) limit : number of rows to show; if no specified, returns latest 50 orders

Output:

  • order_id : id of offer
  • order_currency : main currency (e.g. “LTC”)
  • order_date : time, when offer was changed recently
  • payment_currency : shortcut of currency used to pay for offer
  • type : bid/ask
  • status : “active” if order is active, “inactive” if order is unactive
  • units : current amount of main currency in order
  • start_units : amount of main currency when order was added
  • current_price : price for whole amount of main currency
  • start_price : starting price for whole amount when offer was added

transfer - transfers cryptocurrency to other wallet

Input:

  • currency : cryptocurrency to transfer
  • quantity : amount of cryptocurrency, which will be transferred
  • address : wallet address of receiver

Output:

  • success - if transfer succeeded
  • error - if any
  • withdraw - withdraws money into bank account

Input:

  • currency : currency to withdraw (e.g. USD)
  • quantity : amount of money to withdraw
  • account : account number on which money would be transferred
  • express : true/false
  • bic : swift/bic number

Output:

  • success : if withdrawal succeeded
  • error : if any
  • history - history of all operations on user account

Input:

  • currency : name of the currency in which history will be displayed
  • limit : the limit for results

Output:

  • amount : amount of currency in operation
  • balance_after : total balance after operation (does not contain substracted locked balance)
  • currency : currency of operation
  • time : commission date
  • comment : comment for operation (usually it is type of operation)

transactions - history of account transactions

Input:

  • (optional) market : (e.g. BTC-USD) if set the result list would be limited to transactions with given currencies. Correct format is cryptoCurrencyShortcut-priceCurrencyShortcut. If parameter not set method returns all transactions ordered by date in descending order.

Output:

  • date : date of transaction
  • type : ASK if you sold crypto, BID when you were buyer
  • market : pair of currencies of transaction
  • amount : amount of crypto sold/bought
  • rate : crypto rate used in specified trasnaction
  • price : total price paid in transaction

Error codes

  • Code Description
  • 400 At least one parameter wasn't set
  • 401 Invalid order type
  • 402 No orders with specified currencies
  • 403 Invalid payment currency name
  • 404 Error. Wrong transaction type
  • 405 Order with this id doesn't exist
  • 406 No enough money or crypto
  • 408 Invalid currency name
  • 501 Invalid public key
  • 502 Invalid sign
  • 503 Invalid moment parameter. Request time doesn't match current server time
  • 504 Invalid method
  • 505 Key has no permission for this action
  • 506 Account locked. Please contact with customer service
  • 509 The BIC/SWIFT is required for this currency
  • 510 Invalid market name