resnext / solaris-api-client
Solaris平台PHP客户端
v0.1.6
2016-10-03 22:40 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ~6.0
- psr/log: ^1.0
Requires (Dev)
- fzaninotto/faker: ~1.4
- monolog/monolog: ^1.18
- phpunit/phpunit: ^5.1
This package is not auto-updated.
Last update: 2024-09-14 19:47:44 UTC
README
为Solaris二进制期权平台提供的API客户端。
安装
当然使用Composer来安装。
$ composer require resnext/solaris-api-client
通用API客户端使用。
您可以使用ApiClient构造函数的$options参数配置使用的HTTP客户端。
错误处理
每个Solaris\ApiClient的方法都可以返回响应对象(\Solaris\Response的实例)或抛出两种类型的异常。
- \Solaris\ServerException:服务器端异常,通常是由于接收到无效数据或请求了不可能的操作。
- \Solaris\ClientException:客户端异常表示API客户端无法连接到Solaris服务器或由于任何原因接收有效响应。
配置和定制
示例
$httpClient = new GuzzleHttp\Client([ GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 2, ]); $apiClient = new \Solaris\ApiClient(<API_URL>, <API_USERNAME>, <API_PASSWORD>, [ 'httpClient' => $httpClient, ]);
获取可用国家列表
对于添加客户,您需要指定国家ISO 3166-1代码(例如:en,us,gb)。您可以得到以下可注册国家的列表:
/** @var \Solaris\Responses\GetCountriesResponse $response */ $response = $apiClient->getCountries(); /** @var \Solaris\Entities\Country[] $countries */ $countries = $response->getCountries();
添加客户
客户添加是任何交易平台的主要方法...
$request = new \Solaris\Requests\AddCustomerRequest([ 'firstName' => 'John', 'lastName' => 'Smith', 'email' => 'john.smith@domain.com', 'phone' => '123456789', 'country' => 'cz', 'currency' => 'USD', 'password' => 'qwerty', ]); /** @var \Solaris\Responses\AddCustomerResponse $response */ $response = $apiClient->addCustomer($request);
获取客户自动登录URL和授权密钥。
这非常简单
$request = new \Solaris\Requests\GetCustomerAuthKeyRequest(['email' => 'john.smith@domain.com']); /** * @var \Solaris\Responses\GetCustomerAuthKeyResponse $response */ $response = $apiClient->getCustomerAuthKey($request); echo $response->getAuthUrl();
取款检索
/** @var \Solaris\Responses\GetDepositsResponse $response */ $response = $apiClient->getDeposits(); /** @var \Solaris\Entities\Deposit[] $deposits */ $deposits = $response->getDeposits();