cfxmarkets / php-exchange-sdk
访问CFX Markets交易所的公共PHP SDK
v1.6.0
2019-06-24 21:11 UTC
Requires
- php: >=7.0.0
- cfxmarkets/php-persistence: ^0.3.0 || ^0.4.0 || ^0.5.0 || ^0.6.0
- cfxmarkets/php-public-models: ^1.21.0
- psr/http-message: ~1.0
Requires (Dev)
- guzzlehttp/guzzle: ^6.0.0
- kael-shipman/php-std-traits: ^7.0.0
- phpunit/phpunit: >=4.8.0
This package is auto-updated.
Last update: 2024-08-25 09:05:58 UTC
README
这是一个公共PHP SDK库,用于访问CFX Markets交易所。
此库可以帮助通过CFX交易所的REST API与CFX交易所进行交互。
使用方法
实例化
CFX交易所要求对所有交互使用经过认证的API密钥。您应将API密钥和密钥提供给构造函数,以及您想要针对的API URL(通常用于测试的是https://sandbox.apis.cfxtrading.com/exchange
,用于生产的是https://apis.cfxtrading.com/exchange
)。
// In your code, where you're planning on using the SDK... $cfx = new \CFX\SDK\Exchange\Client('https://sandbox.apis.cfxtrading.com/exchange', $apiKey, $secret, $httpClient);
操作对象
您可能主要对从服务器获取、创建、更新或删除数据对象感兴趣。为此,您将使用此库提供的周边对象类,然后通过您实例化的客户端发送指令到服务器(可选地)以及您创建的资源对象之一。
例如,以下是如何从服务器获取资产列表的方法。这返回一个包含Asset
资源的ResourceCollection
。
// Get a list of assets from the server $assets = $cfx->assets->get(); $asset = $assets[0]; echo $asset->getName(); // ...
以下是一个创建订单的示例
// First, create some peripherals $asset = $cfx->assets->create(['id' => $_POST['assetSymbol']]); $qty = $_POST['qty']; // Then create the order locally (assume that $user is a valid user in your system) $order = $cfx->orders->create() ->setType('sell') ->setOwnerToken($user->getToken()) ->setAsset($asset) ->setQuantity($qty); // Now, send the order to the server, catching any errors thrown try { $order->save(); $response = .... } catch (\CFX\BadInputException $e) { // Means there were data input errors } catch (.....) { // etc... }