Skip to content

polapi/API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

BitBay Trading API

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. Even though the requested host is bitbay.net responses contain cookies for market.bitbay.pl. That is how it is supposed to work, so there's no need to worry.

API Keys

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

https://bitbay.net/account

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 request / 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

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 user's operations

Input:

  • currency : Abbreviation of a currency name of which history will be displayed.
  • limit : Maximum number of returned history entries (notice that this time the argument is required). Usually limiting number of returned records makes sense when there's possibility to provide an offset. In this case it's not there, so better hurry up before your history will be unaccessable through API (because you'll have more transactions than maximum limit).

Output:

  • id : some kind of id
  • amount : amount of currency in operation
  • balance_after : total balance after operation (does not contain substracted locked balance)
  • currency : abbreviation of a currency name i.e. same thing as you provided in request
  • operation_type : type of operation (e.g. "+currency_transaction"), possible types nobody bothered to list.
  • time : operation date in format yyyy-MM-dd HH:mm:ss
  • comment : comment for operation (usually it is not type of operation, because there's seperate field for that)

transactions - history of user's 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 - it's basically the same thing as in history endpoint time output, but this time it's called date
  • 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 transaction
  • price : total price paid in transaction

Tips:

Transactions endpoint won't return information about fees. So to get them you will have to match transaction endpoint calls with history calls. Good luck with that!

Error codes

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

About

API trading

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors