farzai / bitkub
Bitkub API包装器
1.1.0
2023-12-24 09:01 UTC
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-09-30 01:51:12 UTC
README
简化Bitkub API集成到您的PHP应用程序中。 Bitkub API文档
**注意:我们与Bitkub、其子公司或任何关联方没有关联、合作、授权、赞助或以任何方式正式连接。
安装
您可以通过composer安装此包
composer require farzai/bitkub
基本用法
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();
文档
市场
调用市场端点。这将返回一个Farzai\Bitkub\Endpoints\MarketEndpoint
类的实例。
$market = $bitkub->market(); # Next, We will use this instance for the following examples below. # ...
列出所有可用符号。
- GET
/api/market/symbols
$market->symbols();
获取特定符号的行情。
- GET
/api/market/ticker
$market->ticker( // string: The symbol. 'THB_BTC' );
列出最近的交易。
- GET
/api/market/trades
$market->trades([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
列出开放的买入订单。
- GET
/api/market/bids
$market->bids([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
列出开放的卖出订单。
- GET
/api/market/asks
$market->asks([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
列出所有开放的订单。
- GET
/api/market/books
$market->books([ // string: The symbol. 'sym' => 'THB_BTC', // integer: Limit the number of results. 'lmt' => 10, ]);
获取用户可用余额
- GET
/api/market/wallet
$market->wallet();
创建买入订单。
- 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', ]);
创建卖出订单。
- 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', ]);
取消开放订单。
- 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', ]);
获取余额信息:包括可用和预留余额。
- POST
/api/v3/market/balances
$market->balances();
列出给定符号的所有开放订单。
- GET
/api/v3/market/my-open-orders
$market->openOrders( // string: The symbol. 'THB_BTC' );
列出已匹配的所有订单。
- 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
/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', ]);
加密货币
调用加密货币端点。这将返回一个Farzai\Bitkub\Endpoints\CryptoEndpoint
类的实例。
$crypto = $bitkub->crypto(); # Next, We will use this instance for the following examples below. # ...
列出所有加密货币地址。
- GET
/api/v3/crypto/addresses
$crypto->addresses([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
向受信任地址提款。
- 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', ]);
向内部地址提款。
- 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', ]);
列出加密货币存款历史。
- POST
/api/v3/crypto/deposit-history
$crypto->depositHistory([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
列出加密货币提款历史。
- POST
/api/v3/crypto/withdrawal-history
$crypto->withdrawalHistory([ // integer: The page number. 'p' => 1, // integer: Limit the number of results. 'lmt' => 10, ]);
生成新的加密货币地址
- POST
/api/v3/crypto/generate-address
$crypto->generateAddress( // string Symbol (e.g. THB_BTC, THB_ETH, etc.) 'THB_BTC' );
系统
调用系统端点。这将返回一个Farzai\Bitkub\Endpoints\SystemEndpoint
类的实例。
$system = $bitkub->system(); # Next, We will use this instance for the following examples below. # ...
获取服务器状态。
- GET
/api/status
$system->status();
获取服务器时间戳。
- GET
/api/v3/servertime
$system->serverTimestamp();
用户
调用用户端点。这将返回一个Farzai\Bitkub\Endpoints\UserEndpoint
类的实例。
$user = $bitkub->user(); # Next, We will use this instance for the following examples below. # ...
检查交易信用余额。
- POST
/api/v3/user/trading-credits
$user->tradingCredits();
检查存款/提款限制和使用情况。
- POST
/api/v3/user/limits
$user->limits();
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
有关如何报告安全漏洞,请参阅我们的安全策略。
致谢
许可证
麻省理工学院许可证(MIT)。请参阅许可文件以获取更多信息。