farzai / bitkub
The bitkub api wrapper
Fund package maintenance!
parsilver
Requires
- php: ^8.1
- farzai/support: ^1.2
- farzai/transport: ^1.2
- phrity/websocket: ^2.0
Requires (Dev)
- laravel/pint: ^1.0
- pestphp/pest: ^2.15
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2024-11-18 01:52:48 UTC
README
Simplify the integration of the Bitkub API into your PHP application. Bitkub API Documentation
**Notes We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with Bitkub, or any of its subsidiaries or its affiliates.
Installation
You can install the package via composer:
composer require farzai/bitkub
Basic Usage
Restful API
$bitkub = \Farzai\Bitkub\ClientBuilder::create() ->setCredentials('YOUR_API_KEY', 'YOUR_SECRET_KEY') ->build(); // Basic usage $market = $bitkub->market(); // Just call the market endpoint // Get balances $response = $market->balances(); // (Optional) You may call the `throw()` method to ensure that the response is successful $response->throw(); // Get response data $myBTC = $response->json('result.BTC.available'); echo "My BTC balance: {$myBTC}";
Websocket API
$websocket = new \Farzai\Bitkub\WebSocket\Endpoints\MarketEndpoint( new \Farzai\Bitkub\WebSocketClient( \Farzai\Bitkub\ClientBuilder::create() ->setCredentials('YOUR_API_KEY', 'YOUR_SECRET_KEY') ->build(), ), ); $websocket->listen('trade.thb_ada', function (\Farzai\Bitkub\WebSocket\Message $message) { // Do something echo $message->sym.PHP_EOL; }); // Or you can use multiple symbols like this $websocket->listen(['trade.thb_ada', 'trade.thb_btc', function (\Farzai\Bitkub\WebSocket\Message $message) { // Do something echo $message->sym.PHP_EOL; }); $websocket->run();
Documentation
- Bitkub Wrapper - PHP (Unofficial)
- Installation
- Basic Usage
- Documentation
- Market
- List all available symbols.
- Get the ticker for a specific symbol.
- List recent trades.
- List open buy orders.
- List open sell orders.
- List all open orders.
- Get user available balances
- Create a buy order.
- Create a sell order.
- Cancel an open order.
- Get balances info: this includes both available and reserved balances.
- List all open orders of the given symbol.
- List all orders that have already matched.
- Get information regarding the specified order.
- Crypto
- System
- User
- Market
- Testing
- Changelog
- Contributing
- Security Vulnerabilities
- Credits
- License
Market
Call the market endpoint.
This will return an instance of Farzai\Bitkub\Endpoints\MarketEndpoint
class.
$market = $bitkub->market(); # Next, We will use this instance for the following examples below. # ...
List all available symbols.
- GET
/api/market/symbols
$market->symbols();
Get the ticker for a specific symbol.
- GET
/api/market/ticker
$market->ticker( // string: The symbol. 'THB_BTC' );
List recent trades.
- GET
/api/market/trades
$market->trades([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
List open buy orders.
- GET
/api/market/bids
$market->bids([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
List open sell orders.
- GET
/api/market/asks
$market->asks([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
List all open orders.
- GET
/api/market/books
$market->books([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
Get user available balances
- GET
/api/market/wallet
$market->wallet();
Create a buy order.
- POST
/api/v3/market/place-bid
$market->placeBid([ // string: The symbol. 'sym' => 'THB_BTC', // float: Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok) 'amt' => 1000, // float: Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok) 'rat' => 1000000, // string: Order type: limit or market (for market order, please specify rat as 0) 'typ' => 'limit', // string: (Optional) your id for reference 'client_id' => 'your_id', ]);
Create a sell order.
- POST
/api/v3/market/place-ask
$market->placeAsk([ // string: The symbol. 'sym' => 'THB_BTC', // float: Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok) 'amt' => 1000, // float: Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok) 'rat' => 1000000, // string: Order type: limit or market (for market order, please specify rat as 0) 'typ' => 'limit', // string: (Optional) your id for reference 'client_id' => 'your_id', ]);
Cancel an open order.
- POST
/api/v3/market/cancel-order
$market->cancelOrder([ // string: The symbol. 'sym' => 'THB_BTC', // integer: The order ID. 'id' => 123456, // string: The side of the order. 'sd' => 'buy', // string: The hash of the order. 'hash' => 'your_hash', ]);
Get balances info: this includes both available and reserved balances.
- POST
/api/v3/market/balances
$market->balances();
List all open orders of the given symbol.
- GET
/api/v3/market/my-open-orders
$market->openOrders( // string: The symbol. 'THB_BTC' );
List all orders that have already matched.
- GET
/api/v3/market/my-order-history
$market->myOrderHistory([ // string: The symbol. 'sym' => 'THB_BTC', // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, // integer: The start timestamp. 'start' => 1614556800, // integer: The end timestamp. 'end' => 1614643199, ]);
Get information regarding the specified order.
- GET
/api/v3/market/order-info
$market->myOrderInfo([ // string: The symbol. 'sym' => 'THB_BTC', // integer: The order ID. 'id' => 123456, // string: The side of the order. 'sd' => 'buy', // string: The hash of the order. 'hash' => 'your_hash', ]);
Crypto
Call the crypto endpoint.
This will return an instance of Farzai\Bitkub\Endpoints\CryptoEndpoint
class.
$crypto = $bitkub->crypto(); # Next, We will use this instance for the following examples below. # ...
List all crypto addresses.
- GET
/api/v3/crypto/addresses
$crypto->addresses([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
Make a withdrawal to a trusted address.
- POST
/api/v3/crypto/withdraw
$crypto->withdrawal([ // string: Currency for withdrawal (e.g. BTC, ETH) 'cur' => 'BTC', // float: Amount you want to withdraw 'amt' => 0.001, // string: Address to which you want to withdraw 'adr' => 'your_address', // string: (Optional) Memo or destination tag to which you want to withdraw 'mem' => 'your_memo', // string: Cryptocurrency network to withdraw 'net' => 'BTC', ]);
Make a withdraw to an internal address.
- POST
/api/v3/crypto/internal-withdraw
$crypto->internalWithdrawal([ // string: Currency for withdrawal (e.g. BTC, ETH) 'cur' => 'BTC', // float: Amount you want to withdraw 'amt' => 0.001, // string: Address to which you want to withdraw 'adr' => 'your_address', // string: (Optional) Memo or destination tag to which you want to withdraw 'mem' => 'your_memo', ]);
List crypto deposit history.
- POST
/api/v3/crypto/deposit-history
$crypto->depositHistory([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
List crypto withdrawal history.
- POST
/api/v3/crypto/withdrawal-history
$crypto->withdrawalHistory([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
Generate a new crypto address
- POST
/api/v3/crypto/generate-address
$crypto->generateAddress( // string Symbol (e.g. THB_BTC, THB_ETH, etc.) 'THB_BTC' );
System
Call the system endpoint.
This will return an instance of Farzai\Bitkub\Endpoints\SystemEndpoint
class.
$system = $bitkub->system(); # Next, We will use this instance for the following examples below. # ...
Get server status.
- GET
/api/status
$system->status();
Get server timestamp.
- GET
/api/v3/servertime
$system->serverTimestamp();
User
Call the user endpoint.
This will return an instance of Farzai\Bitkub\Endpoints\UserEndpoint
class.
$user = $bitkub->user(); # Next, We will use this instance for the following examples below. # ...
Check trading credit balance.
- POST
/api/v3/user/trading-credits
$user->tradingCredits();
Check deposit/withdraw limitations and usage.
- POST
/api/v3/user/limits
$user->limits();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.