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.
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
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,
);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.
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;
}The rate limit is 1 request / second.
List of methods, which you have to send in method parameter.
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
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
Input:
- id : id used to recognize offer; you get it from trade method output
Output:
- success : if cancelation was successful
- error : if any
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
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
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
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
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)
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!
| 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 |