├── src ├── Exception │ ├── PhitFlyerClientExceptionInterface.php │ ├── WebApiCallException.php │ ├── PhitFlyerClientException.php │ └── ServerResponseFormatException.php ├── NetDriverChangeListenerInterface.php ├── Object │ ├── Health.php │ ├── MeCommission.php │ ├── MeChildOrderResult.php │ ├── Ask.php │ ├── Bid.php │ ├── Market.php │ ├── BoardState.php │ ├── Chat.php │ ├── MeAddress.php │ ├── MeBalance.php │ ├── Board.php │ ├── MeCollateralAccount.php │ ├── MeCollateral.php │ ├── MeDeposit.php │ ├── MeBankAccount.php │ ├── Execution.php │ ├── MeCoinIn.php │ ├── MeExecution.php │ ├── MeCoinOut.php │ ├── MePosition.php │ ├── Ticker.php │ └── MeChildOrder.php ├── PhitFlyerApi.php ├── PhitFlyerClientInterface.php ├── PhitFlyerLoggerClient.php ├── PhitFlyerObjectClient.php └── PhitFlyerBenchmarkClient.php ├── samples ├── include │ ├── autoload.php │ └── sample.inc.php ├── get_health.php ├── get_boardstate.php ├── me_cancel_all_child_orders.php ├── me_cancel_child_order.php ├── get_markets.php ├── me_get_permissions.php ├── me_get_collateral.php ├── me_get_collateral_accounts.php ├── me_get_trading_commissions.php ├── me_get_balance.php ├── me_get_address.php ├── get_chats.php ├── me_get_deposits.php ├── get_executions.php ├── me_get_bank_accounts.php ├── me_get_coinins.php ├── me_send_child_order.php ├── get_board.php ├── get_ticker.php ├── me_get_coinouts.php ├── me_get_executions.php ├── me_get_positions.php ├── readme_sample.php ├── me_get_child_orders.php └── bench_all.php ├── phpunit.xml ├── composer.json ├── LICENSE ├── README.ja.md ├── README.md └── test ├── PhitFlyerObjectClientTest.php ├── PhitFlyerLoggerClientTest.php ├── PhitFlyerClientTest.php └── PhitFlyerBenchmarkClientTest.php /src/Exception/PhitFlyerClientExceptionInterface.php: -------------------------------------------------------------------------------- 1 | getHealth(); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | echo ' status:' . $health['status'] . PHP_EOL; 22 | 23 | } 24 | catch(\Throwable $e) 25 | { 26 | print_stacktrace($e); 27 | } 28 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | 20 | 21 | ./src/ 22 | 23 | 24 | -------------------------------------------------------------------------------- /samples/get_boardstate.php: -------------------------------------------------------------------------------- 1 | getBoardState(); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | echo ' health:' . $board_state['health'] . PHP_EOL; 22 | echo ' state:' . $board_state['state'] . PHP_EOL; 23 | 24 | } 25 | catch(\Throwable $e) 26 | { 27 | print_stacktrace($e); 28 | } -------------------------------------------------------------------------------- /samples/me_cancel_all_child_orders.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | ); 11 | list($product_code) = get_args($argdefs,__FILE__); 12 | 13 | list($api_key, $api_secret) = bitflyer_credentials(); 14 | 15 | try{ 16 | $flyer = new PhitFlyerClient($api_key, $api_secret); 17 | 18 | // call web API 19 | $flyer->meCancelAllChildOrders($product_code); 20 | 21 | // show request URI 22 | $uri = $flyer->getLastRequest()->getUrl(); 23 | echo 'URI:' . PHP_EOL; 24 | echo ' ' . $uri . PHP_EOL; 25 | 26 | } 27 | catch(\Throwable $e) 28 | { 29 | print_stacktrace($e); 30 | } 31 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stk2k/phitflyer", 3 | "description": "PHP bitflyer API client library", 4 | "keywords": ["bitflyer", "PHP", "library", "bitflyer api", "bitflyer lightning api"], 5 | "homepage": "https://github.com/stk2k/pitflyer", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Katsuki Shuto", 11 | "email": "stk2k@sazysoft.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=7.1", 16 | "ext-json": "*", 17 | "psr/log": "^1.0", 18 | "stk2k/net-driver": "~0.5" 19 | }, 20 | "require-dev": { 21 | "phpunit/phpunit": "^6.3.0", 22 | "wa72/simplelogger": "~v1.1.0" 23 | }, 24 | "autoload": { 25 | "psr-4": { 26 | "Stk2k\\PhitFlyer\\": "src/" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Stk2k\\PhitFlyer\\Test\\": "test/" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Object/Health.php: -------------------------------------------------------------------------------- 1 | status = $status; 19 | } 20 | 21 | /** 22 | * construct from stdObject 23 | * 24 | * @param array $data 25 | * 26 | * @return Health 27 | */ 28 | public static function fromArray(array $data) : Health 29 | { 30 | return new self( 31 | $data['status'] ?? null 32 | ); 33 | } 34 | 35 | /** 36 | * get status 37 | * 38 | * @return string 39 | */ 40 | public function getStatus() : string{ 41 | return $this->status; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /samples/me_cancel_child_order.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | 'child_order_id' => 'string', 11 | ); 12 | list($product_code, $child_order_id) = get_args($argdefs,__FILE__); 13 | 14 | list($api_key, $api_secret) = bitflyer_credentials(); 15 | 16 | try{ 17 | $flyer = new PhitFlyerClient($api_key, $api_secret); 18 | 19 | // call web API 20 | $flyer->meCancelChildOrder($product_code, $child_order_id); 21 | 22 | // show request URI 23 | $uri = $flyer->getLastRequest()->getUrl(); 24 | echo 'URI:' . PHP_EOL; 25 | echo ' ' . $uri . PHP_EOL; 26 | 27 | } 28 | catch(\Throwable $e) 29 | { 30 | print_stacktrace($e); 31 | } 32 | -------------------------------------------------------------------------------- /samples/get_markets.php: -------------------------------------------------------------------------------- 1 | getMarkets(); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | foreach($markets as $idx => $item){ 22 | echo ' [' . $idx . ']' . PHP_EOL; 23 | echo ' product_code:' . $item['product_code'] . PHP_EOL; 24 | echo ' alias:' . (isset($item['alias']) ? $item['alias'] : '') . PHP_EOL; 25 | } 26 | 27 | } 28 | catch(\Throwable $e) 29 | { 30 | print_stacktrace($e); 31 | } 32 | -------------------------------------------------------------------------------- /samples/me_get_permissions.php: -------------------------------------------------------------------------------- 1 | meGetPermissions(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($permissions as $idx => $permission){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' ' . $permission . PHP_EOL; 26 | } 27 | 28 | } 29 | catch(\Throwable $e) 30 | { 31 | print_stacktrace($e); 32 | } 33 | -------------------------------------------------------------------------------- /samples/me_get_collateral.php: -------------------------------------------------------------------------------- 1 | meGetCollateral(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | echo ' ' . $collateral['collateral'] . PHP_EOL; 24 | echo ' ' . $collateral['open_position_pnl'] . PHP_EOL; 25 | echo ' ' . $collateral['require_collateral'] . PHP_EOL; 26 | echo ' ' . $collateral['keep_rate'] . PHP_EOL; 27 | } 28 | catch(\Throwable $e) 29 | { 30 | print_stacktrace($e); 31 | } 32 | -------------------------------------------------------------------------------- /samples/me_get_collateral_accounts.php: -------------------------------------------------------------------------------- 1 | meGetCollateralAccounts(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($accounts as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' currency_code:' . $item['currency_code'] . PHP_EOL; 26 | echo ' amount:' . $item['amount']. PHP_EOL; 27 | } 28 | } 29 | catch(\Throwable $e) 30 | { 31 | print_stacktrace($e); 32 | } -------------------------------------------------------------------------------- /samples/me_get_trading_commissions.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | ); 11 | list($product_code) = get_args($argdefs,__FILE__); 12 | 13 | list($api_key, $api_secret) = bitflyer_credentials(); 14 | 15 | try{ 16 | $flyer = new PhitFlyerClient($api_key, $api_secret); 17 | 18 | // call web API 19 | $commission = $flyer->meGetTradingCommission( $product_code ); 20 | 21 | // show request URI 22 | $uri = $flyer->getLastRequest()->getUrl(); 23 | echo 'URI:' . PHP_EOL; 24 | echo ' ' . $uri . PHP_EOL; 25 | 26 | // show result 27 | echo 'RESULT:' . PHP_EOL; 28 | echo ' commission_rate:' . $commission['commission_rate'] . PHP_EOL; 29 | 30 | } 31 | catch(\Throwable $e) 32 | { 33 | print_stacktrace($e); 34 | } 35 | -------------------------------------------------------------------------------- /src/Object/MeCommission.php: -------------------------------------------------------------------------------- 1 | commission_rate = $commission_rate; 19 | } 20 | 21 | /** 22 | * construct from stdObject 23 | * 24 | * @param array $data 25 | * 26 | * @return MeCommission 27 | */ 28 | public static function fromArray(array $data) : MeCommission 29 | { 30 | return new self( 31 | $data['commission_rate'] ?? null 32 | ); 33 | } 34 | 35 | /** 36 | * get commission rate 37 | * 38 | * @return string 39 | */ 40 | public function getCommissionRate() : string 41 | { 42 | return $this->commission_rate; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /samples/me_get_balance.php: -------------------------------------------------------------------------------- 1 | meGetBalance(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($balances as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' ' . $item['currency_code'] . PHP_EOL; 26 | echo ' ' . $item['amount'] . PHP_EOL; 27 | echo ' ' . $item['available'] . PHP_EOL; 28 | } 29 | 30 | } 31 | catch(\Throwable $e) 32 | { 33 | print_stacktrace($e); 34 | } 35 | -------------------------------------------------------------------------------- /samples/me_get_address.php: -------------------------------------------------------------------------------- 1 | meGetAddress(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($addresses as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' type:' . $item['type'] . PHP_EOL; 26 | echo ' currency_code:' . $item['currency_code'] . PHP_EOL; 27 | echo ' address:' . $item['address'] . PHP_EOL; 28 | } 29 | 30 | } 31 | catch(\Throwable $e) 32 | { 33 | print_stacktrace($e); 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 stk2k 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Object/MeChildOrderResult.php: -------------------------------------------------------------------------------- 1 | child_order_acceptance_id = $child_order_acceptance_id; 19 | } 20 | 21 | /** 22 | * construct from stdObject 23 | * 24 | * @param array $data 25 | * 26 | * @return MeChildOrderResult 27 | */ 28 | public static function fromArray(array $data) : MeChildOrderResult 29 | { 30 | return new self( 31 | $data['child_order_acceptance_id'] ?? null 32 | ); 33 | } 34 | 35 | /** 36 | * get child order acceptance id(child order id) 37 | * 38 | * @return string 39 | */ 40 | public function getChildOrderAcceptanceId() : string 41 | { 42 | return $this->child_order_acceptance_id; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /samples/get_chats.php: -------------------------------------------------------------------------------- 1 | getChats($from_date); 19 | 20 | // show request URI 21 | $uri = $flyer->getLastRequest()->getUrl(); 22 | echo 'URI:' . PHP_EOL; 23 | echo ' ' . $uri . PHP_EOL; 24 | 25 | // show result 26 | echo 'RESULT:' . PHP_EOL; 27 | foreach($chats as $idx => $item){ 28 | echo ' [' . $idx . ']' . PHP_EOL; 29 | echo ' nickname:' . $item['nickname'] . PHP_EOL; 30 | echo ' message:' . $item['message'] . PHP_EOL; 31 | echo ' date:' . $item['date'] . PHP_EOL; 32 | } 33 | 34 | } 35 | catch(\Throwable $e) 36 | { 37 | print_stacktrace($e); 38 | } -------------------------------------------------------------------------------- /src/Object/Ask.php: -------------------------------------------------------------------------------- 1 | price = $price; 23 | $this->size = $size; 24 | } 25 | 26 | /** 27 | * construct from stdObject 28 | * 29 | * @param array $data 30 | * 31 | * @return Ask 32 | */ 33 | public static function fromArray(array $data) : Ask 34 | { 35 | return new self( 36 | $data['price'] ?? null, 37 | $data['size'] ?? null 38 | ); 39 | } 40 | 41 | /** 42 | * get price 43 | * 44 | * @return float 45 | */ 46 | public function getPrice() : float 47 | { 48 | return $this->price; 49 | } 50 | 51 | /** 52 | * get size 53 | * 54 | * @return float 55 | */ 56 | public function getSize() : float 57 | { 58 | return $this->size; 59 | } 60 | } -------------------------------------------------------------------------------- /src/Object/Bid.php: -------------------------------------------------------------------------------- 1 | price = $price; 23 | $this->size = $size; 24 | } 25 | 26 | /** 27 | * construct from stdObject 28 | * 29 | * @param array $data 30 | * 31 | * @return Bid 32 | */ 33 | public static function fromArray(array $data) : Bid 34 | { 35 | return new self( 36 | $data['price'] ?? null, 37 | $data['size'] ?? null 38 | ); 39 | } 40 | 41 | /** 42 | * get price 43 | * 44 | * @return float 45 | */ 46 | public function getPrice() : float 47 | { 48 | return $this->price; 49 | } 50 | 51 | /** 52 | * get size 53 | * 54 | * @return float 55 | */ 56 | public function getSize() : float 57 | { 58 | return $this->size; 59 | } 60 | } -------------------------------------------------------------------------------- /samples/me_get_deposits.php: -------------------------------------------------------------------------------- 1 | meGetDeposits(null,null,10); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($deposits as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' id:' . $item['id'] . PHP_EOL; 26 | echo ' order_id:' . $item['order_id'] . PHP_EOL; 27 | echo ' currency_code:' . $item['currency_code'] . PHP_EOL; 28 | echo ' amount:' . $item['amount'] . PHP_EOL; 29 | echo ' status:' . $item['status'] . PHP_EOL; 30 | echo ' event_date:' . $item['event_date'] . PHP_EOL; 31 | } 32 | 33 | } 34 | catch(\Throwable $e) 35 | { 36 | print_stacktrace($e); 37 | } 38 | -------------------------------------------------------------------------------- /samples/get_executions.php: -------------------------------------------------------------------------------- 1 | getExecutions('BTC_JPY',null,null,10); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | foreach($executions as $idx => $item){ 22 | echo ' [' . $idx . ']' . PHP_EOL; 23 | echo ' id:' . $item['id'] . PHP_EOL; 24 | echo ' side:' . $item['side'] . PHP_EOL; 25 | echo ' price:' . $item['price'] . PHP_EOL; 26 | echo ' size:' . $item['size'] . PHP_EOL; 27 | echo ' exec_date:' . $item['exec_date'] . PHP_EOL; 28 | echo ' buy_child_order_acceptance_id:' . $item['buy_child_order_acceptance_id'] . PHP_EOL; 29 | echo ' sell_child_order_acceptance_id:' . $item['sell_child_order_acceptance_id'] . PHP_EOL; 30 | } 31 | 32 | } 33 | catch(\Throwable $e) 34 | { 35 | print_stacktrace($e); 36 | } 37 | -------------------------------------------------------------------------------- /samples/me_get_bank_accounts.php: -------------------------------------------------------------------------------- 1 | meGetBankAccounts(); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($bank_accounts as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' id:' . $item['id'] . PHP_EOL; 26 | echo ' is_verified:' . $item['is_verified'] . PHP_EOL; 27 | echo ' bank_name:' . $item['bank_name'] . PHP_EOL; 28 | echo ' branch_name:' . $item['branch_name'] . PHP_EOL; 29 | echo ' account_type:' . $item['account_type'] . PHP_EOL; 30 | echo ' account_number:' . $item['account_number'] . PHP_EOL; 31 | echo ' account_name:' . $item['account_name'] . PHP_EOL; 32 | } 33 | 34 | } 35 | catch(\Throwable $e) 36 | { 37 | print_stacktrace($e); 38 | } 39 | -------------------------------------------------------------------------------- /src/Object/Market.php: -------------------------------------------------------------------------------- 1 | product_code = $product_code; 23 | $this->alias = $alias; 24 | } 25 | 26 | /** 27 | * construct from stdObject 28 | * 29 | * @param array $data 30 | * 31 | * @return Market 32 | */ 33 | public static function fromArray(array $data) : Market 34 | { 35 | return new self( 36 | $data['product_code'] ?? null, 37 | $data['alias'] ?? null 38 | ); 39 | } 40 | 41 | /** 42 | * get product code 43 | * 44 | * @return string|null 45 | */ 46 | public function getProductCode() : string 47 | { 48 | return $this->product_code; 49 | } 50 | 51 | /** 52 | * get alias 53 | * 54 | * @return string|null 55 | */ 56 | public function getAlias() : string 57 | { 58 | return $this->alias; 59 | } 60 | } -------------------------------------------------------------------------------- /samples/me_get_coinins.php: -------------------------------------------------------------------------------- 1 | meGetCoinIns(null,null,10); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($coinins as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' id:' . $item['id']. PHP_EOL; 26 | echo ' order_id:' . $item['order_id'] . PHP_EOL; 27 | echo ' currency_code:' . $item['currency_code'] . PHP_EOL; 28 | echo ' amount:' . $item['amount'] . PHP_EOL; 29 | echo ' address:' . $item['address'] . PHP_EOL; 30 | echo ' tx_hash:' . $item['tx_hash'] . PHP_EOL; 31 | echo ' status:' . $item['status'] . PHP_EOL; 32 | echo ' event_date:' . $item['event_date'] . PHP_EOL; 33 | } 34 | 35 | } 36 | catch(\Throwable $e) 37 | { 38 | print_stacktrace($e); 39 | } 40 | -------------------------------------------------------------------------------- /samples/me_send_child_order.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | 'child_order_type' => 'string', 11 | 'side' => 'string', 12 | 'price' => 'integer', 13 | 'size' => 'float', 14 | '[minute_to_expire]' => 'integer', 15 | '[time_in_force]' => 'string', 16 | ); 17 | list($product_code, $child_order_type, $side, $price, $size, $minute_to_expire, $time_in_force) = get_args($argdefs,__FILE__); 18 | 19 | list($api_key, $api_secret) = bitflyer_credentials(); 20 | 21 | try{ 22 | $flyer = new PhitFlyerClient($api_key, $api_secret); 23 | 24 | // call web API 25 | $result = $flyer->meSendChildOrder($product_code, $child_order_type, $side, $price, $size, $minute_to_expire, $time_in_force); 26 | 27 | // show request URI 28 | $uri = $flyer->getLastRequest()->getUrl(); 29 | echo 'URI:' . PHP_EOL; 30 | echo ' ' . $uri . PHP_EOL; 31 | 32 | // show result 33 | echo 'RESULT:' . PHP_EOL; 34 | echo ' child_order_acceptance_id:' . $result['child_order_acceptance_id'] . PHP_EOL; 35 | 36 | } 37 | catch(\Throwable $e) 38 | { 39 | print_stacktrace($e); 40 | } 41 | -------------------------------------------------------------------------------- /samples/get_board.php: -------------------------------------------------------------------------------- 1 | getBoard('BTC_JPY'); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | echo ' =========================' . PHP_EOL; 22 | echo ' mid_price:' . $board['mid_price'] . PHP_EOL; 23 | 24 | echo ' =========================' . PHP_EOL; 25 | echo ' bids:' . PHP_EOL; 26 | foreach($board['bids'] as $idx => $item){ 27 | echo ' [' . $idx . ']' . PHP_EOL; 28 | echo ' price:' . $item['price'] . PHP_EOL; 29 | echo ' size:' . $item['size'] . PHP_EOL; 30 | } 31 | 32 | echo '=========================' . PHP_EOL; 33 | echo 'asks:' . PHP_EOL; 34 | foreach($board['asks'] as $idx => $item){ 35 | echo ' [' . $idx . ']' . PHP_EOL; 36 | echo ' price:' . $item['price'] . PHP_EOL; 37 | echo ' size:' . $item['size'] . PHP_EOL; 38 | } 39 | } 40 | catch(\Throwable $e) 41 | { 42 | print_stacktrace($e); 43 | } 44 | -------------------------------------------------------------------------------- /samples/get_ticker.php: -------------------------------------------------------------------------------- 1 | getTicker('BTC_JPY'); 13 | 14 | // show request URI 15 | $uri = $flyer->getLastRequest()->getUrl(); 16 | echo 'URI:' . PHP_EOL; 17 | echo ' ' . $uri . PHP_EOL; 18 | 19 | // show result 20 | echo 'RESULT:' . PHP_EOL; 21 | echo ' product_code:' . $ticker['product_code'] . PHP_EOL; 22 | echo ' timestamp:' . $ticker['timestamp'] . PHP_EOL; 23 | echo ' tick_id:' . $ticker['tick_id'] . PHP_EOL; 24 | echo ' best_bid:' . $ticker['best_bid'] . PHP_EOL; 25 | echo ' best_ask:' . $ticker['best_ask'] . PHP_EOL; 26 | echo ' best_bid_size:' . $ticker['best_bid_size'] . PHP_EOL; 27 | echo ' best_ask_size:' . $ticker['best_ask_size'] . PHP_EOL; 28 | echo ' total_bid_depth:' . $ticker['total_bid_depth'] . PHP_EOL; 29 | echo ' total_ask_depth:' . $ticker['total_ask_depth'] . PHP_EOL; 30 | echo ' ltp:' . $ticker['ltp'] . PHP_EOL; 31 | echo ' volume:' . $ticker['volume'] . PHP_EOL; 32 | echo ' volume_by_product:' . $ticker['volume_by_product'] . PHP_EOL; 33 | 34 | } 35 | catch(\Throwable $e) 36 | { 37 | print_stacktrace($e); 38 | } 39 | -------------------------------------------------------------------------------- /samples/me_get_coinouts.php: -------------------------------------------------------------------------------- 1 | meGetCoinOuts(null,null,10); 15 | 16 | // show request URI 17 | $uri = $flyer->getLastRequest()->getUrl(); 18 | echo 'URI:' . PHP_EOL; 19 | echo ' ' . $uri . PHP_EOL; 20 | 21 | // show result 22 | echo 'RESULT:' . PHP_EOL; 23 | foreach($coininouts as $idx => $item){ 24 | echo ' [' . $idx . ']' . PHP_EOL; 25 | echo ' id:' . $item['id'] . PHP_EOL; 26 | echo ' order_id:' . $item['order_id'] . PHP_EOL; 27 | echo ' currency_code:' . $item['currency_code'] . PHP_EOL; 28 | echo ' amount:' . $item['amount'] . PHP_EOL; 29 | echo ' address:' . $item['address'] . PHP_EOL; 30 | echo ' tx_hash:' . $item['tx_hash'] . PHP_EOL; 31 | echo ' fee:' . $item['fee'] . PHP_EOL; 32 | echo ' additional_fee:' . $item['additional_fee'] . PHP_EOL; 33 | echo ' status:' . $item['status'] . PHP_EOL; 34 | echo ' event_date:' . $item['event_date'] . PHP_EOL; 35 | } 36 | 37 | } 38 | catch(\Throwable $e) 39 | { 40 | print_stacktrace($e); 41 | } 42 | -------------------------------------------------------------------------------- /samples/me_get_executions.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | '[before]' => 'integer', 11 | '[after]' => 'integer', 12 | '[count]' => 'integer', 13 | ); 14 | list($product_code,$before,$after,$count) = get_args($argdefs,__FILE__); 15 | 16 | list($api_key, $api_secret) = bitflyer_credentials(); 17 | 18 | try{ 19 | $flyer = new PhitFlyerClient($api_key, $api_secret); 20 | 21 | // call web API 22 | $executions = $flyer->meGetExecutions( $product_code, $before, $after, $count ); 23 | 24 | // show request URI 25 | $uri = $flyer->getLastRequest()->getUrl(); 26 | echo 'URI:' . PHP_EOL; 27 | echo ' ' . $uri . PHP_EOL; 28 | 29 | // show result 30 | echo 'RESULT:' . PHP_EOL; 31 | foreach($executions as $idx => $item){ 32 | echo ' [' . $idx . ']' . PHP_EOL; 33 | echo ' id:' . $item['id'] . PHP_EOL; 34 | echo ' child_order_id:' . $item['child_order_id'] . PHP_EOL; 35 | echo ' side:' . $item['side'] . PHP_EOL; 36 | echo ' price:' . $item['price'] . PHP_EOL; 37 | echo ' size:' . $item['size'] . PHP_EOL; 38 | echo ' commission:' . $item['commission'] . PHP_EOL; 39 | echo ' exec_date:' . $item['exec_date'] . PHP_EOL; 40 | } 41 | 42 | } 43 | catch(\Throwable $e) 44 | { 45 | print_stacktrace($e); 46 | } 47 | -------------------------------------------------------------------------------- /src/Object/BoardState.php: -------------------------------------------------------------------------------- 1 | health = $health; 27 | $this->state = $state; 28 | $this->data = $data; 29 | } 30 | 31 | /** 32 | * construct from stdObject 33 | * 34 | * @param array $data 35 | * 36 | * @return BoardState 37 | */ 38 | public static function fromArray(array $data) : BoardState 39 | { 40 | return new self( 41 | $data['health'] ?? null, 42 | $data['state'] ?? null, 43 | $data['data'] ?? [] 44 | ); 45 | } 46 | 47 | /** 48 | * get health 49 | * 50 | * @return string 51 | */ 52 | public function getHealth() : string 53 | { 54 | return $this->state; 55 | } 56 | 57 | /** 58 | * get state 59 | * 60 | * @return string 61 | */ 62 | public function getState() : string 63 | { 64 | return $this->state; 65 | } 66 | 67 | /** 68 | * get data 69 | * 70 | * @return array 71 | */ 72 | public function getData() : array 73 | { 74 | return $this->data; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /samples/me_get_positions.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | ); 11 | list($product_code) = get_args($argdefs,__FILE__); 12 | 13 | list($api_key, $api_secret) = bitflyer_credentials(); 14 | 15 | try{ 16 | $flyer = new PhitFlyerClient($api_key, $api_secret); 17 | 18 | // call web API 19 | $positions = $flyer->meGetPositions( $product_code ); 20 | 21 | // show request URI 22 | $uri = $flyer->getLastRequest()->getUrl(); 23 | echo 'URI:' . PHP_EOL; 24 | echo ' ' . $uri . PHP_EOL; 25 | 26 | // show result 27 | echo 'RESULT:' . PHP_EOL; 28 | foreach($positions as $idx => $item){ 29 | echo ' [' . $idx . ']' . PHP_EOL; 30 | echo ' product_code:' . $item['product_code'] . PHP_EOL; 31 | echo ' side:' . $item['side'] . PHP_EOL; 32 | echo ' price:' . $item['price'] . PHP_EOL; 33 | echo ' size:' . $item['size'] . PHP_EOL; 34 | echo ' commission:' . $item['commission'] . PHP_EOL; 35 | echo ' swap_point_accumulate:' . $item['swap_point_accumulate'] . PHP_EOL; 36 | echo ' exec_require_collateraldate:' . $item['require_collateral'] . PHP_EOL; 37 | echo ' open_date:' . $item['open_date'] . PHP_EOL; 38 | echo ' leverage:' . $item['leverage'] . PHP_EOL; 39 | echo ' pnl:' . $item['pnl'] . PHP_EOL; 40 | } 41 | 42 | } 43 | catch(\Throwable $e) 44 | { 45 | print_stacktrace($e); 46 | } 47 | -------------------------------------------------------------------------------- /src/Object/Chat.php: -------------------------------------------------------------------------------- 1 | nickname = $nickname; 27 | $this->message = $message; 28 | $this->date = $date; 29 | } 30 | 31 | /** 32 | * construct from stdObject 33 | * 34 | * @param array $data 35 | * 36 | * @return Chat 37 | */ 38 | public static function fromArray(array $data) : Chat 39 | { 40 | return new self( 41 | $data['nickname'] ?? null, 42 | $data['message'] ?? null, 43 | $data['date'] ?? null 44 | ); 45 | } 46 | 47 | /** 48 | * get nickname 49 | * 50 | * @return string 51 | * @noinspection PhpUnused 52 | */ 53 | public function getNickname() : string 54 | { 55 | return $this->nickname; 56 | } 57 | 58 | /** 59 | * get message 60 | * 61 | * @return string 62 | */ 63 | public function getMessage() : string{ 64 | return $this->message; 65 | } 66 | 67 | /** 68 | * get date 69 | * 70 | * @return string 71 | */ 72 | public function getDate() : string 73 | { 74 | return $this->date; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /src/Object/MeAddress.php: -------------------------------------------------------------------------------- 1 | type = $type; 27 | $this->currency_code = $currency_code; 28 | $this->address = $address; 29 | } 30 | 31 | /** 32 | * construct from stdObject 33 | * 34 | * @param array $data 35 | * 36 | * @return MeAddress 37 | */ 38 | public static function fromArray(array $data) : MeAddress 39 | { 40 | return new self( 41 | $data['type'] ?? null, 42 | $data['currency_code'] ?? null, 43 | $data['address'] ?? null 44 | ); 45 | } 46 | 47 | /** 48 | * get type 49 | * 50 | * @return string 51 | */ 52 | public function getType() : string 53 | { 54 | return $this->type; 55 | } 56 | 57 | /** 58 | * get currency code 59 | * 60 | * @return string 61 | */ 62 | public function getCurrencyCode() : string 63 | { 64 | return $this->currency_code; 65 | } 66 | 67 | /** 68 | * get address 69 | * 70 | * @return string 71 | */ 72 | public function getAddress() : string 73 | { 74 | return $this->address; 75 | } 76 | } -------------------------------------------------------------------------------- /src/Object/MeBalance.php: -------------------------------------------------------------------------------- 1 | currency_code = $currency_code; 27 | $this->amount = $amount; 28 | $this->available = $available; 29 | } 30 | 31 | /** 32 | * construct from stdObject 33 | * 34 | * @param array $data 35 | * 36 | * @return MeBalance 37 | */ 38 | public static function fromArray(array $data) : MeBalance 39 | { 40 | return new self( 41 | $data['currency_code'] ?? null, 42 | $data['amount'] ?? null, 43 | $data['available'] ?? null 44 | ); 45 | } 46 | 47 | /** 48 | * get currency code 49 | * 50 | * @return string 51 | */ 52 | public function getCurrenecyCode() : string 53 | { 54 | return $this->currency_code; 55 | } 56 | 57 | /** 58 | * get amount 59 | * 60 | * @return float 61 | */ 62 | public function getAmount() : float 63 | { 64 | return $this->amount; 65 | } 66 | 67 | /** 68 | * get available 69 | * 70 | * @return float 71 | */ 72 | public function getAvailable() : float 73 | { 74 | return $this->available; 75 | } 76 | } -------------------------------------------------------------------------------- /src/Object/Board.php: -------------------------------------------------------------------------------- 1 | mid_price = $mid_price; 27 | $this->bids = $bids; 28 | $this->asks = $asks; 29 | } 30 | 31 | /** 32 | * construct from stdObject 33 | * 34 | * @param array $data 35 | * 36 | * @return Board 37 | */ 38 | public static function fromArray(array $data) : Board 39 | { 40 | return new self( 41 | $data['mid_price'] ?? null, 42 | array_map(function($i){ return Bid::fromArray($i); }, $data['bids'] ?? []), 43 | array_map(function($i){ return Ask::fromArray($i); }, $data['asks'] ?? []) 44 | ); 45 | } 46 | 47 | /** 48 | * get mid price 49 | * 50 | * @return int 51 | * @noinspection PhpUnused 52 | */ 53 | public function getMidPrice() : int 54 | { 55 | return $this->mid_price; 56 | } 57 | 58 | /** 59 | * get bids 60 | * 61 | * @return Bid[] 62 | * @noinspection PhpUnused 63 | */ 64 | public function getBids() : array 65 | { 66 | return $this->bids; 67 | } 68 | 69 | /** 70 | * get bids 71 | * 72 | * @return Ask[] 73 | */ 74 | public function getAsks() : array 75 | { 76 | return $this->asks; 77 | } 78 | } -------------------------------------------------------------------------------- /src/Object/MeCollateralAccount.php: -------------------------------------------------------------------------------- 1 | currency_code = $currency_code; 31 | $this->amount = $amount; 32 | $this->require_collateral = $require_collateral; 33 | $this->keep_rate = $keep_rate; 34 | } 35 | 36 | /** 37 | * construct from stdObject 38 | * 39 | * @param array $data 40 | * 41 | * @return MeCollateralAccount 42 | */ 43 | public static function fromArray(array $data) : MeCollateralAccount 44 | { 45 | return new self( 46 | $data['currency_code'] ?? null, 47 | $data['amount'] ?? null, 48 | $data['require_collateral'] ?? null, 49 | $data['keep_rate'] ?? null 50 | ); 51 | } 52 | 53 | /** 54 | * get currency code 55 | * 56 | * @return string 57 | */ 58 | public function getCurrencyCode() : string 59 | { 60 | return $this->currency_code; 61 | } 62 | 63 | /** 64 | * get amount 65 | * 66 | * @return float 67 | */ 68 | public function getAmount() : float 69 | { 70 | return $this->amount; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/PhitFlyerApi.php: -------------------------------------------------------------------------------- 1 | getMarkets(); 21 | 22 | foreach($markets as $idx => $market){ 23 | echo $idx . '.' . PHP_EOL; 24 | echo 'product_code:' . $market['product_code'] . PHP_EOL; 25 | echo 'alias:' . (isset($market['alias']) ? $market['alias'] : '') . PHP_EOL; 26 | } 27 | echo PHP_EOL; 28 | 29 | echo '===[ objective access sample ]===', PHP_EOL; 30 | 31 | $flyer = new PhitFlyerObjectClient(new PhitFlyerClient()); 32 | 33 | $markets = $flyer->getMarkets(); 34 | 35 | foreach($markets as $idx => $market){ 36 | /** @var \PhitFlyer\Object\Market $market */ 37 | echo $idx . '.' . PHP_EOL; 38 | echo 'product_code:' . $market->getProductCode() . PHP_EOL; 39 | echo 'alias:' . $market->getAlias() . PHP_EOL; 40 | } 41 | echo PHP_EOL; 42 | 43 | echo '===[ benchmark sample ]===', PHP_EOL; 44 | 45 | $flyer = new PhitFlyerBenchmarkClient( 46 | new PhitFlyerClient(), 47 | function ($m, $e){ 48 | echo "[$m]finished in $e sec" . PHP_EOL; 49 | } 50 | ); 51 | 52 | $flyer->getMarkets(); 53 | 54 | echo '===[ logger client sample ]===', PHP_EOL; 55 | 56 | $client = new PhitFlyerLoggerClient( 57 | new PhitFlyerClient(), 58 | new YourLogger() // YourLogger: Psr-3 compliant logger 59 | ); 60 | $client->getNetDriver()->setVerbose(true); 61 | 62 | } 63 | catch(\Throwable $e) 64 | { 65 | print_stacktrace($e); 66 | } 67 | -------------------------------------------------------------------------------- /src/Object/MeCollateral.php: -------------------------------------------------------------------------------- 1 | collateral = $collateral; 31 | $this->open_position_pnl = $open_position_pnl; 32 | $this->require_collateral = $require_collateral; 33 | $this->keep_rate = $keep_rate; 34 | } 35 | 36 | /** 37 | * construct from stdObject 38 | * 39 | * @param array $data 40 | * 41 | * @return MeCollateral 42 | */ 43 | public static function fromArray(array $data) : MeCollateral 44 | { 45 | return new self( 46 | $data['collateral'] ?? null, 47 | $data['open_position_pnl'] ?? null, 48 | $data['require_collateral'] ?? null, 49 | $data['keep_rate'] ?? null 50 | ); 51 | } 52 | 53 | /** 54 | * get collateral 55 | * 56 | * @return string 57 | */ 58 | public function getCollateral() : string 59 | { 60 | return $this->collateral; 61 | } 62 | 63 | /** 64 | * get open position Pnl 65 | * 66 | * @return float 67 | * @noinspection PhpUnused 68 | */ 69 | public function getOpenPositionPnl() : float 70 | { 71 | return $this->open_position_pnl; 72 | } 73 | 74 | /** 75 | * get require collateral 76 | * 77 | * @return float 78 | */ 79 | public function getRequireCollateral() : float 80 | { 81 | return $this->require_collateral; 82 | } 83 | 84 | /** 85 | * get keep rate 86 | * 87 | * @return float 88 | */ 89 | public function getKeepRate() : float 90 | { 91 | return $this->keep_rate; 92 | } 93 | } -------------------------------------------------------------------------------- /samples/me_get_child_orders.php: -------------------------------------------------------------------------------- 1 | 'string', 10 | '[before]' => 'integer', 11 | '[after]' => 'integer', 12 | '[count]' => 'integer', 13 | '[child_order_state]' => 'string', 14 | '[parent_order_id]' => 'string', 15 | ); 16 | list($product_code,$before,$after,$count,$child_order_state,$parent_order_id) = get_args($argdefs,__FILE__); 17 | 18 | list($api_key, $api_secret) = bitflyer_credentials(); 19 | 20 | try{ 21 | $flyer = new PhitFlyerClient($api_key, $api_secret); 22 | 23 | // call web API 24 | $deposits = $flyer->meGetChildOrders($product_code,$before,$after,$count,$child_order_state,$parent_order_id); 25 | 26 | // show request URI 27 | $uri = $flyer->getLastRequest()->getUrl(); 28 | echo 'URI:' . PHP_EOL; 29 | echo ' ' . $uri . PHP_EOL; 30 | 31 | // show result 32 | echo 'RESULT:' . PHP_EOL; 33 | foreach($deposits as $idx => $item){ 34 | echo ' [' . $idx . ']' . PHP_EOL; 35 | echo ' id:' . $item['id'] . PHP_EOL; 36 | echo ' child_order_id:' . $item['child_order_id'] . PHP_EOL; 37 | echo ' product_code:' . $item['product_code'] . PHP_EOL; 38 | echo ' side:' . $item['side'] . PHP_EOL; 39 | echo ' child_order_type:' . $item['child_order_type'] . PHP_EOL; 40 | echo ' price:' . $item['price'] . PHP_EOL; 41 | echo ' average_price:' . $item['average_price'] . PHP_EOL; 42 | echo ' size:' . $item['size'] . PHP_EOL; 43 | echo ' child_order_state:' . $item['child_order_state'] . PHP_EOL; 44 | echo ' expire_date:' . $item['expire_date'] . PHP_EOL; 45 | echo ' child_order_date:' . $item['child_order_date'] . PHP_EOL; 46 | echo ' child_order_acceptance_id:' . $item['child_order_acceptance_id'] . PHP_EOL; 47 | echo ' outstanding_size:' . $item['outstanding_size'] . PHP_EOL; 48 | echo ' cancel_size:' . $item['cancel_size'] . PHP_EOL; 49 | echo ' executed_size:' . $item['executed_size'] . PHP_EOL; 50 | echo ' total_commission:' . $item['total_commission'] . PHP_EOL; 51 | } 52 | 53 | } 54 | catch(\Throwable $e) 55 | { 56 | print_stacktrace($e); 57 | } 58 | -------------------------------------------------------------------------------- /samples/bench_all.php: -------------------------------------------------------------------------------- 1 | getMarkets(); 20 | 21 | sleep(1); 22 | 23 | // call API: /v1/board 24 | echo 'calling api: ' . PhitFlyerApi::BOARD . PHP_EOL; 25 | $flyer->getBoard('BTC_JPY'); 26 | 27 | sleep(1); 28 | 29 | // call API: /v1/ticker 30 | echo 'calling api: ' . PhitFlyerApi::TICKER . PHP_EOL; 31 | $flyer->getTicker('BTC_JPY'); 32 | 33 | sleep(1); 34 | 35 | // call API: /v1/executions 36 | echo 'calling api: ' . PhitFlyerApi::EXECUTIONS . PHP_EOL; 37 | $flyer->getExecutions('BTC_JPY',null,null,10); 38 | 39 | sleep(1); 40 | 41 | // call API: /v1/gethealth 42 | echo 'calling api: ' . PhitFlyerApi::GETHEALTH . PHP_EOL; 43 | $flyer->getHealth(); 44 | 45 | sleep(1); 46 | 47 | // call API: /v1/getchats 48 | echo 'calling api: ' . PhitFlyerApi::GETCHATS . PHP_EOL; 49 | 50 | $from_date = date('Y-m-d\Th:i:s', strtotime('-10 min')); 51 | $chats = $flyer->getChats($from_date); 52 | 53 | // call API: /v1/getpermissions 54 | echo 'calling api: ' . PhitFlyerApi::ME_GETPERMISSIONS . PHP_EOL; 55 | $flyer->meGetPermissions(); 56 | 57 | sleep(1); 58 | 59 | // call API: /v1/getbalance 60 | echo 'calling api: ' . PhitFlyerApi::ME_GETBALANCE . PHP_EOL; 61 | $flyer->meGetBalance(); 62 | 63 | sleep(1); 64 | 65 | // call API: /v1/getcollateral 66 | echo 'calling api: ' . PhitFlyerApi::ME_GETCOLLATERAL . PHP_EOL; 67 | $flyer->meGetCollateral(); 68 | 69 | sleep(1); 70 | 71 | // call API: /v1/getcollateralaccounts 72 | echo 'calling api: ' . PhitFlyerApi::ME_GETCOLLATERALACCOUNTS . PHP_EOL; 73 | $flyer->meGetCollateralAccounts(); 74 | 75 | sleep(1); 76 | 77 | // call API: /v1/getaddresses 78 | echo 'calling api: ' . PhitFlyerApi::ME_GETADDRESS . PHP_EOL; 79 | $flyer->meGetAddress(); 80 | 81 | sleep(1); 82 | 83 | // call API: /v1/getcoinins 84 | echo 'calling api: ' . PhitFlyerApi::ME_GETCOININS . PHP_EOL; 85 | $flyer->meGetCoinIns(); 86 | 87 | sleep(1); 88 | 89 | // call API: /v1/getcoinouts 90 | echo 'calling api: ' . PhitFlyerApi::ME_GETCOINOUTS . PHP_EOL; 91 | $flyer->meGetCoinOuts(); 92 | 93 | sleep(1); 94 | -------------------------------------------------------------------------------- /samples/include/sample.inc.php: -------------------------------------------------------------------------------- 1 | $type){ 18 | 19 | $is_option = preg_match('/\[([a-zA-Z0-9].*)\]/', $key); 20 | if(!$is_option){ 21 | $param_count ++; 22 | } 23 | 24 | $index++; 25 | } 26 | 27 | if ($argc < $param_count){ 28 | show_usage($filename, $args_for_usage); 29 | exit; 30 | } 31 | 32 | $args = array(); 33 | 34 | $index = 1; 35 | foreach($argdefs as $key => $type){ 36 | 37 | $arg = isset($argv[$index]) ? $argv[$index] : null; 38 | 39 | $is_option = preg_match('/\[([a-zA-Z0-9].*)\]/', $key); 40 | 41 | // empty check 42 | if(!$is_option && strlen($arg) === 0){ 43 | echo 'bad parameter: ',$key,'(empty)',PHP_EOL; 44 | show_usage($filename, $args_for_usage); 45 | exit; 46 | } 47 | 48 | if (strlen($arg) === 0||$arg === 'NULL'||$arg === 'null'){ 49 | $arg = null; 50 | } 51 | else{ 52 | // integer check 53 | if(!empty($arg) && $type =='integer' && !is_numeric($arg)){ 54 | echo 'bad parameter: ',$key,'(integer)',PHP_EOL; 55 | show_usage($filename, $args_for_usage); 56 | exit; 57 | } 58 | // float check 59 | if(!empty($arg) && $type =='float' && !is_numeric($arg)){ 60 | echo 'bad parameter: ',$key,'(float)',PHP_EOL; 61 | show_usage($filename, $args_for_usage); 62 | exit; 63 | } 64 | } 65 | 66 | $args[] = $arg; 67 | $index++; 68 | } 69 | return $args; 70 | } 71 | 72 | function print_stacktrace(\Exception $e) 73 | { 74 | $no = 0; 75 | while($e){ 76 | $file = $e->getFile(); 77 | $line = $e->getLine(); 78 | $message = $e->getMessage(); 79 | 80 | echo "#{$no} {$message} @$file($line)" . PHP_EOL; 81 | 82 | $e = $e->getPrevious(); 83 | $no ++; 84 | } 85 | } 86 | 87 | 88 | function bitflyer_credentials() 89 | { 90 | $api_key = getenv('PHITFLYER_API_KEY'); 91 | $api_secret = getenv('PHITFLYER_API_SECRET'); 92 | 93 | echo 'PHITFLYER_API_KEY:',$api_key,PHP_EOL; 94 | echo 'PHITFLYER_API_SECRET:',$api_secret,PHP_EOL; 95 | 96 | return array($api_key, $api_secret); 97 | } 98 | -------------------------------------------------------------------------------- /src/Object/MeDeposit.php: -------------------------------------------------------------------------------- 1 | id = $id; 40 | $this->order_id = $order_id; 41 | $this->currency_code = $currency_code; 42 | $this->amount = $amount; 43 | $this->status = $status; 44 | $this->event_date = $event_date; 45 | } 46 | 47 | /** 48 | * construct from stdObject 49 | * 50 | * @param array $data 51 | * 52 | * @return MeDeposit 53 | */ 54 | public static function fromArray(array $data) : MeDeposit 55 | { 56 | return new self( 57 | $data['id'] ?? null, 58 | $data['order_id'] ?? null, 59 | $data['currency_code'] ?? null, 60 | $data['amount'] ?? null, 61 | $data['status'] ?? null, 62 | $data['event_date'] ?? null 63 | ); 64 | } 65 | 66 | /** 67 | * get id 68 | * 69 | * @return int 70 | */ 71 | public function getId() : int 72 | { 73 | return $this->id; 74 | } 75 | 76 | /** 77 | * get order id 78 | * 79 | * @return string 80 | */ 81 | public function getOrderId() : string 82 | { 83 | return $this->order_id; 84 | } 85 | 86 | /** 87 | * get currency code 88 | * 89 | * @return string 90 | */ 91 | public function getCurrencyCode() : string 92 | { 93 | return $this->currency_code; 94 | } 95 | 96 | /** 97 | * get amount 98 | * 99 | * @return int 100 | */ 101 | public function getAmount() : int 102 | { 103 | return $this->amount; 104 | } 105 | 106 | /** 107 | * get status 108 | * 109 | * @return string 110 | */ 111 | public function getStatus() : string 112 | { 113 | return $this->status; 114 | } 115 | 116 | /** 117 | * get event date 118 | * 119 | * @return string 120 | */ 121 | public function getEventDate() : string 122 | { 123 | return $this->event_date; 124 | } 125 | 126 | } -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | phitFlyer, bitFlyer API PHP クライアント 2 | ======================= 3 | 4 | ## 説明 5 | 6 | phitFlyerはbitFLyer-APIを呼び出す機能を持つPHPライブラリです。 7 | 配列やオブジェクトなど、複数のアクセス方法に対応しています。 8 | 9 | ## 特徴 10 | 11 | - シンプルなインターフェース 12 | - 返却値はデフォルトでjsonデコード結果(配列orオブジェクト)だが、デコレータによりオブジェクトで返却することも可能 13 | - オプションで使用できるベンチマーククラスを内蔵 14 | 15 | 16 | ## デモ 17 | 18 | ### シンプルかつ最速の例: 19 | ```php 20 | use Stk2k\PhitFlyer\PhitFlyerClient; 21 | 22 | $client = new PhitFlyerClient(); 23 | 24 | $markets = $client->getMarkets(); 25 | 26 | foreach($markets as $idx => $market){ 27 | echo $idx . '.' . PHP_EOL; 28 | echo 'product_code:' . $market->product_code . PHP_EOL; 29 | echo 'alias:' . (isset($market['alias']) ? $market['alias'] : '') . PHP_EOL; 30 | } 31 | 32 | ``` 33 | 34 | ### オブジェクトアクセスの例: 35 | ```php 36 | use Stk2k\PhitFlyer\PhitFlyerClient; 37 | use Stk2k\PhitFlyer\PhitFlyerObjectClient; 38 | 39 | $client = new PhitFlyerObjectClient(new PhitFlyerClient()); 40 | 41 | $markets = $client->getMarkets(); 42 | 43 | foreach($markets as $idx => $market){ 44 | echo $idx . '.' . PHP_EOL; 45 | echo 'product_code:' . $market->getProductCode() . PHP_EOL; 46 | echo 'alias:' . $market->getAlias() . PHP_EOL; 47 | } 48 | 49 | ``` 50 | 51 | ### ベンチマークの例: 52 | ```php 53 | use Stk2k\PhitFlyer\PhitFlyerClient; 54 | use Stk2k\PhitFlyer\PhitFlyerBenchmarkClient; 55 | 56 | $client = new PhitFlyerBenchmarkClient( 57 | new PhitFlyerClient(), 58 | function ($m, $e) use(&$method, &$elapsed){ 59 | echo "[$m]finished in $e sec" . PHP_EOL; 60 | } 61 | ); 62 | 63 | $client->getMarkets(); 64 | 65 | ``` 66 | 67 | ### ロガーの例: 68 | ```php 69 | use Stk2k\PhitFlyer\PhitFlyerClient; 70 | use Stk2k\PhitFlyer\PhitFlyerLoggerClient; 71 | 72 | $client = new PhitFlyerLoggerClient( 73 | new PhitFlyerClient(), 74 | new YourLogger() // YourLoggerはPSR-3 Loggerに準拠している必要があります 75 | ); 76 | $client->getNetDriver()->setVerbose(true); // 詳細なログを出力 77 | ``` 78 | 79 | ### 独自ネットドライバの使用例: 80 | ```php 81 | use Stk2k\PhitFlyer\PhitFlyerClient; 82 | use Stk2k\NetDriver\NetDriver\Php\PhpNetDriver; 83 | 84 | $client = new PhitFlyerClient(); 85 | $client->setNetDriver(new PhpNetDriver()); // cURL関数の代わりにfile_get_contentsを使ってWebAPIをコールします 86 | 87 | $markets = $client->getMarkets(); 88 | ``` 89 | 90 | ## 使い方 91 | 92 | 1. PhitFlyerClientオブジェクトを作成する。 93 | 2. APIに対応するメソッドを呼び出す。 94 | 3. PhitFlyerクラスが配列またはオブジェクト(stdClass)を返却。 95 | 96 | ## 要件 97 | 98 | PHP 5.5 かまたはそれ以上 99 | 100 | 101 | ## phitFlyerのインストール方法 102 | 103 | phitFlyerのインストールはComposerからのインストールが便利です。 104 | [Composer](http://getcomposer.org). 105 | 106 | ```bash 107 | composer require stk2k/phitflyer 108 | ``` 109 | 110 | インストール後、Composerのオートローダーを以下のようにrequireしてください。 111 | 112 | ```php 113 | require 'vendor/autoload.php'; 114 | ``` 115 | 116 | ## ライセンス 117 | [MIT](https://github.com/stk2k/grasshopper/blob/master/LICENSE) 118 | 119 | ## 作者 120 | 121 | [stk2k](https://github.com/stk2k) 122 | 123 | 124 | ## 免責事項 125 | 126 | このソフトウェアは無保証です。 127 | 私たちはこのソフトウェアによるいかなる結果も責任を負いません。 128 | あなた自身の責任においてこのソフトウェアを使用するようにしてください。 129 | 130 | 131 | ## 寄付 132 | 133 | -Bitcoin: 3HCw9pp6dSq1xU9iPoPKVFyVbM8iBrrinn 134 | 135 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | phitFlyer, bitFlyer API PHP client 2 | ======================= 3 | 4 | ## Description 5 | 6 | phitFlyer is a PHP library which provides calling bitFLyer-API. 7 | It provides multiple access methods, such as array, class. 8 | 9 | ## Feature 10 | 11 | - simple interface 12 | - return values are result of json decoding(array/object), but it also has object interface by using decorator class. 13 | - bundles benchmark class which can be used alternatively. 14 | 15 | ## Demo 16 | 17 | ### simple and fastest sample: 18 | ```php 19 | use Stk2k\PhitFlyer\PhitFlyerClient; 20 | 21 | $client = new PhitFlyerClient(); 22 | 23 | $markets = $client->getMarkets(); 24 | 25 | foreach($markets as $idx => $market){ 26 | echo $idx . '.' . PHP_EOL; 27 | echo 'product_code:' . $market->product_code . PHP_EOL; 28 | echo 'alias:' . (isset($market['alias']) ? $market['alias'] : '') . PHP_EOL; 29 | } 30 | 31 | ``` 32 | 33 | ### objective access sample: 34 | ```php 35 | use Stk2k\PhitFlyer\PhitFlyerClient; 36 | use Stk2k\PhitFlyer\PhitFlyerObjectClient; 37 | 38 | $client = new PhitFlyerObjectClient(new PhitFlyerClient()); 39 | 40 | $markets = $client->getMarkets(); 41 | 42 | foreach($markets as $idx => $market){ 43 | echo $idx . '.' . PHP_EOL; 44 | echo 'product_code:' . $market->getProductCode() . PHP_EOL; 45 | echo 'alias:' . $market->getAlias() . PHP_EOL; 46 | } 47 | 48 | ``` 49 | 50 | ### benchmark sample: 51 | ```php 52 | use Stk2k\PhitFlyer\PhitFlyerClient; 53 | use Stk2k\PhitFlyer\PhitFlyerBenchmarkClient; 54 | 55 | $client = new PhitFlyerBenchmarkClient( 56 | new PhitFlyerClient(), 57 | function ($m, $e) use(&$method, &$elapsed){ 58 | echo "[$m]finished in $e sec" . PHP_EOL; 59 | } 60 | ); 61 | 62 | $client->getMarkets(); 63 | 64 | ``` 65 | 66 | ### logger client sample: 67 | ```php 68 | use Stk2k\PhitFlyer\PhitFlyerClient; 69 | use Stk2k\PhitFlyer\PhitFlyerLoggerClient; 70 | 71 | $client = new PhitFlyerLoggerClient( 72 | new PhitFlyerClient(), 73 | new YourLogger() // YourLogger: Psr-3 compliant logger 74 | ); 75 | $client->getNetDriver()->setVerbose(true); // ouput detail log 76 | ``` 77 | 78 | ### using different net driver sample: 79 | ```php 80 | use Stk2k\PhitFlyer\PhitFlyerClient; 81 | use Stk2k\NetDriver\NetDriver\Php\PhpNetDriver; 82 | 83 | $client = new PhitFlyerClient(); 84 | $client->setNetDriver(new PhpNetDriver()); // use file_get_contents to call web api instead of cURL function 85 | 86 | $markets = $client->getMarkets(); 87 | ``` 88 | 89 | ## Usage 90 | 91 | 1. create PhitFlyerClient object. 92 | 2. call API method. 93 | 3. PhitFlyer returns array or object(stdClass). 94 | 95 | ## Requirement 96 | 97 | PHP 5.5 or later 98 | php-mbstring 99 | php-xml 100 | 101 | ## Installing phitFlyer 102 | 103 | The recommended way to install phitFlyer is through 104 | [Composer](http://getcomposer.org). 105 | 106 | ```bash 107 | composer require stk2k/phitflyer 108 | ``` 109 | 110 | After installing, you need to require Composer's autoloader: 111 | 112 | ```php 113 | require 'vendor/autoload.php'; 114 | ``` 115 | 116 | ## License 117 | [MIT](https://github.com/stk2k/phitflyer/blob/master/LICENSE) 118 | 119 | ## Author 120 | 121 | [stk2k](https://github.com/stk2k) 122 | 123 | ## Disclaimer 124 | 125 | This software is no warranty. 126 | 127 | We are not responsible for any results caused by the use of this software. 128 | 129 | Please use the responsibility of the your self. 130 | 131 | 132 | ## Donation 133 | 134 | -Bitcoin: 3HCw9pp6dSq1xU9iPoPKVFyVbM8iBrrinn 135 | -------------------------------------------------------------------------------- /src/Object/MeBankAccount.php: -------------------------------------------------------------------------------- 1 | id = $id; 44 | $this->is_verified = $is_verified; 45 | $this->bank_name = $bank_name; 46 | $this->branch_name = $branch_name; 47 | $this->account_type = $account_type; 48 | $this->account_number = $account_number; 49 | $this->account_name = $account_name; 50 | } 51 | 52 | /** 53 | * construct from stdObject 54 | * 55 | * @param array $data 56 | * 57 | * @return MeBankAccount 58 | */ 59 | public static function fromArray(array $data) : MeBankAccount 60 | { 61 | return new self( 62 | $data['id'] ?? null, 63 | $data['is_verified'] ?? null, 64 | $data['bank_name'] ?? null, 65 | $data['branch_name'] ?? null, 66 | $data['account_type'] ?? null, 67 | $data['account_number'] ?? null, 68 | $data['account_name'] ?? null 69 | ); 70 | } 71 | 72 | /** 73 | * get id 74 | * 75 | * @return int 76 | */ 77 | public function getId() : int 78 | { 79 | return $this->id; 80 | } 81 | 82 | /** 83 | * is verified 84 | * 85 | * @return bool 86 | */ 87 | public function getIsVerified() : bool 88 | { 89 | return $this->is_verified; 90 | } 91 | 92 | /** 93 | * get bank name 94 | * 95 | * @return string 96 | * @noinspection PhpUnused 97 | */ 98 | public function getBankName() : string 99 | { 100 | return $this->bank_name; 101 | } 102 | 103 | /** 104 | * get branch name 105 | * 106 | * @return string 107 | * @noinspection PhpUnused 108 | */ 109 | public function getBranchName() : string 110 | { 111 | return $this->branch_name; 112 | } 113 | 114 | /** 115 | * get account type 116 | * 117 | * @return string 118 | */ 119 | public function getAccountType() : string 120 | { 121 | return $this->account_type; 122 | } 123 | 124 | /** 125 | * get account number 126 | * 127 | * @return string 128 | */ 129 | public function getAccountNumber() : string 130 | { 131 | return $this->account_number; 132 | } 133 | 134 | /** 135 | * get account name 136 | * 137 | * @return string 138 | */ 139 | public function getAccountName() : string 140 | { 141 | return $this->account_name; 142 | } 143 | 144 | } -------------------------------------------------------------------------------- /src/Object/Execution.php: -------------------------------------------------------------------------------- 1 | id = $id; 51 | $this->side = $side; 52 | $this->price = $price; 53 | $this->size= $size; 54 | $this->exec_date = $exec_date; 55 | $this->buy_child_order_acceptance_id = $buy_child_order_acceptance_id; 56 | $this->sell_child_order_acceptance_id = $sell_child_order_acceptance_id; 57 | } 58 | 59 | /** 60 | * construct from stdObject 61 | * 62 | * @param array $data 63 | * 64 | * @return Execution 65 | */ 66 | public static function fromArray(array $data) : Execution 67 | { 68 | return new self( 69 | $data['id'] ?? null, 70 | $data['side'] ?? null, 71 | $data['price'] ?? null, 72 | $data['size'] ?? null, 73 | $data['exec_date'] ?? null, 74 | $data['buy_child_order_acceptance_id'] ?? null, 75 | $data['sell_child_order_acceptance_id'] ?? null 76 | ); 77 | } 78 | 79 | /** 80 | * get id 81 | * 82 | * @return int 83 | */ 84 | public function getId() : int 85 | { 86 | return $this->id; 87 | } 88 | 89 | /** 90 | * get side 91 | * 92 | * @return string 93 | */ 94 | public function getSide() : string 95 | { 96 | return $this->side; 97 | } 98 | 99 | /** 100 | * get price 101 | * 102 | * @return float 103 | */ 104 | public function getPrice() : float 105 | { 106 | return $this->price; 107 | } 108 | 109 | /** 110 | * get size 111 | * 112 | * @return float 113 | */ 114 | public function getSize() : float 115 | { 116 | return $this->size; 117 | } 118 | 119 | /** 120 | * get exec date 121 | * 122 | * @return string 123 | */ 124 | public function getExecDate() : string 125 | { 126 | return $this->exec_date; 127 | } 128 | 129 | /** 130 | * get buy child order acceptance id 131 | * 132 | * @return string 133 | * @noinspection PhpUnused 134 | */ 135 | public function getBuyChildOrderAcceptanceId() : string 136 | { 137 | return $this->buy_child_order_acceptance_id; 138 | } 139 | 140 | /** 141 | * get sell child order acceptance id 142 | * 143 | * @return string 144 | */ 145 | public function getSellChildOrderAcceptanceId() : string 146 | { 147 | return $this->sell_child_order_acceptance_id; 148 | } 149 | } -------------------------------------------------------------------------------- /src/Object/MeCoinIn.php: -------------------------------------------------------------------------------- 1 | id = $id; 48 | $this->order_id = $order_id; 49 | $this->currency_code = $currency_code; 50 | $this->amount = $amount; 51 | $this->address = $address; 52 | $this->tx_hash = $tx_hash; 53 | $this->status = $status; 54 | $this->event_date = $event_date; 55 | } 56 | 57 | /** 58 | * construct from stdObject 59 | * 60 | * @param array $data 61 | * 62 | * @return MeCoinIn 63 | */ 64 | public static function fromArray(array $data) : MeCoinIn 65 | { 66 | return new self( 67 | $data['id'] ?? null, 68 | $data['order_id'] ?? null, 69 | $data['currency_code'] ?? null, 70 | $data['amount'] ?? null, 71 | $data['address'] ?? null, 72 | $data['tx_hash'] ?? null, 73 | $data['status'] ?? null, 74 | $data['event_date'] ?? null 75 | ); 76 | } 77 | 78 | /** 79 | * get id 80 | * 81 | * @return int 82 | */ 83 | public function getId() : int 84 | { 85 | return $this->id; 86 | } 87 | 88 | /** 89 | * get order id 90 | * 91 | * @return string 92 | */ 93 | public function getOrderId() : string 94 | { 95 | return $this->order_id; 96 | } 97 | 98 | /** 99 | * get currency code 100 | * 101 | * @return string 102 | */ 103 | public function getCurrencyCode() : string 104 | { 105 | return $this->currency_code; 106 | } 107 | 108 | /** 109 | * get amount 110 | * 111 | * @return float 112 | */ 113 | public function getAmount() : float 114 | { 115 | return $this->amount; 116 | } 117 | 118 | /** 119 | * get address 120 | * 121 | * @return string 122 | */ 123 | public function getAddress() : string 124 | { 125 | return $this->address; 126 | } 127 | 128 | /** 129 | * get tx hash 130 | * 131 | * @return string 132 | * @noinspection PhpUnused 133 | */ 134 | public function getTxHash() : string 135 | { 136 | return $this->tx_hash; 137 | } 138 | 139 | /** 140 | * get status 141 | * 142 | * @return string 143 | */ 144 | public function getStatus() : string 145 | { 146 | return $this->status; 147 | } 148 | 149 | /** 150 | * get event date 151 | * 152 | * @return string 153 | */ 154 | public function getEventDate() : string 155 | { 156 | return $this->event_date; 157 | } 158 | } -------------------------------------------------------------------------------- /src/Object/MeExecution.php: -------------------------------------------------------------------------------- 1 | id = $id; 56 | $this->child_order_id = $child_order_id; 57 | $this->side = $side; 58 | $this->price = $price; 59 | $this->size= $size; 60 | $this->commission= $commission; 61 | $this->exec_date = $exec_date; 62 | $this->child_order_acceptance_id = $child_order_acceptance_id; 63 | } 64 | 65 | /** 66 | * construct from stdObject 67 | * 68 | * @param array $data 69 | * 70 | * @return MeExecution 71 | */ 72 | public static function fromArray(array $data) : MeExecution 73 | { 74 | return new self( 75 | $data['id'] ?? null, 76 | $data['child_order_id'] ?? null, 77 | $data['side'] ?? null, 78 | $data['price'] ?? null, 79 | $data['size'] ?? null, 80 | $data['commission'] ?? null, 81 | $data['exec_date'] ?? null, 82 | $data['child_order_acceptance_id'] ?? null 83 | ); 84 | } 85 | 86 | /** 87 | * get id 88 | * 89 | * @return int 90 | */ 91 | public function getId() : int 92 | { 93 | return $this->id; 94 | } 95 | 96 | /** 97 | * get child order id 98 | * 99 | * @return string 100 | */ 101 | public function getChildOrderId() : string 102 | { 103 | return $this->child_order_id; 104 | } 105 | 106 | /** 107 | * get side 108 | * 109 | * @return string 110 | */ 111 | public function getSide() : string 112 | { 113 | return $this->side; 114 | } 115 | 116 | /** 117 | * get price 118 | * 119 | * @return float 120 | */ 121 | public function getPrice() : float 122 | { 123 | return $this->price; 124 | } 125 | 126 | /** 127 | * get size 128 | * 129 | * @return float 130 | */ 131 | public function getSize() : float 132 | { 133 | return $this->size; 134 | } 135 | 136 | /** 137 | * get commission 138 | * 139 | * @return string 140 | */ 141 | public function getCommission() : string 142 | { 143 | return $this->commission; 144 | } 145 | 146 | /** 147 | * get exec date 148 | * 149 | * @return string 150 | */ 151 | public function getExecDate() : string 152 | { 153 | return $this->exec_date; 154 | } 155 | 156 | /** 157 | * get buy child order acceptance id 158 | * 159 | * @return string 160 | * @noinspection PhpUnused 161 | */ 162 | public function getBuyChildOrderAcceptanceId() : string 163 | { 164 | return $this->child_order_acceptance_id; 165 | } 166 | 167 | } -------------------------------------------------------------------------------- /src/Object/MeCoinOut.php: -------------------------------------------------------------------------------- 1 | id = $id; 56 | $this->order_id = $order_id; 57 | $this->currency_code = $currency_code; 58 | $this->amount = $amount; 59 | $this->address = $address; 60 | $this->tx_hash = $tx_hash; 61 | $this->fee = $fee; 62 | $this->additional_fee = $additional_fee; 63 | $this->status = $status; 64 | $this->event_date = $event_date; 65 | } 66 | 67 | /** 68 | * construct from stdObject 69 | * 70 | * @param array $data 71 | * 72 | * @return MeCoinOut 73 | */ 74 | public static function fromArray(array $data) : MeCoinOut 75 | { 76 | return new self( 77 | $data['id'] ?? null, 78 | $data['order_id'] ?? null, 79 | $data['currency_code'] ?? null, 80 | $data['amount'] ?? null, 81 | $data['address'] ?? null, 82 | $data['tx_hash'] ?? null, 83 | $data['fee'] ?? null, 84 | $data['additional_fee'] ?? null, 85 | $data['status'] ?? null, 86 | $data['event_date'] ?? null 87 | ); 88 | } 89 | 90 | /** 91 | * get id 92 | * 93 | * @return int 94 | */ 95 | public function getId() : int 96 | { 97 | return $this->id; 98 | } 99 | 100 | /** 101 | * get order id 102 | * 103 | * @return string 104 | */ 105 | public function getOrderId() : string 106 | { 107 | return $this->order_id; 108 | } 109 | 110 | /** 111 | * get currency code 112 | * 113 | * @return string 114 | */ 115 | public function getCurrencyCode() : string 116 | { 117 | return $this->currency_code; 118 | } 119 | 120 | /** 121 | * get amount 122 | * 123 | * @return float 124 | */ 125 | public function getAmount() : float 126 | { 127 | return $this->amount; 128 | } 129 | 130 | /** 131 | * get address 132 | * 133 | * @return string 134 | */ 135 | public function getAddress() : string 136 | { 137 | return $this->address; 138 | } 139 | 140 | /** 141 | * get tx hash 142 | * 143 | * @return string 144 | * @noinspection PhpUnused 145 | */ 146 | public function getTxHash() : string 147 | { 148 | return $this->tx_hash; 149 | } 150 | 151 | /** 152 | * get fee 153 | * 154 | * @return float 155 | * @noinspection PhpUnused 156 | */ 157 | public function getFee() : float 158 | { 159 | return $this->fee; 160 | } 161 | 162 | /** 163 | * get additional fee 164 | * 165 | * @return float 166 | * @noinspection PhpUnused 167 | */ 168 | public function getAdditionalFee() : float 169 | { 170 | return $this->additional_fee; 171 | } 172 | 173 | /** 174 | * get status 175 | * 176 | * @return string 177 | */ 178 | public function getStatus() : string 179 | { 180 | return $this->status; 181 | } 182 | 183 | /** 184 | * get event date 185 | * 186 | * @return string 187 | */ 188 | public function getEventDate() : string 189 | { 190 | return $this->event_date; 191 | } 192 | } -------------------------------------------------------------------------------- /src/Object/MePosition.php: -------------------------------------------------------------------------------- 1 | product_code = $product_code; 66 | $this->side = $side; 67 | $this->price = $price; 68 | $this->size = $size; 69 | $this->commission = $commission; 70 | $this->swap_point_accumulate = $swap_point_accumulate; 71 | $this->require_collateral = $require_collateral; 72 | $this->open_date = $open_date; 73 | $this->leverage = $leverage; 74 | $this->pnl = $pnl; 75 | } 76 | 77 | /** 78 | * construct from stdObject 79 | * 80 | * @param array $data 81 | * 82 | * @return MePosition 83 | */ 84 | public static function fromArray(array $data) : MePosition{ 85 | return new self( 86 | $data['product_code'] ?? null, 87 | $data['side'] ?? null, 88 | $data['price'] ?? null, 89 | $data['size'] ?? null, 90 | $data['commission'] ?? null, 91 | $data['swap_point_accumulate'] ?? null, 92 | $data['require_collateral'] ?? null, 93 | $data['open_date'] ?? null, 94 | $data['leverage'] ?? null, 95 | $data['pnl'] ?? null 96 | ); 97 | } 98 | 99 | /** 100 | * get product code 101 | * 102 | * @return string 103 | */ 104 | public function getProductCode() : string 105 | { 106 | return $this->product_code; 107 | } 108 | 109 | /** 110 | * get side 111 | * 112 | * @return string 113 | */ 114 | public function getSide() : string 115 | { 116 | return $this->side; 117 | } 118 | 119 | /** 120 | * get price 121 | * 122 | * @return int 123 | */ 124 | public function getPrice() : int 125 | { 126 | return $this->price; 127 | } 128 | 129 | /** 130 | * get size 131 | * 132 | * @return float 133 | */ 134 | public function getSize() : float 135 | { 136 | return $this->size; 137 | } 138 | 139 | /** 140 | * get commission 141 | * 142 | * @return float 143 | */ 144 | public function getCommission() : float 145 | { 146 | return $this->commission; 147 | } 148 | 149 | /** 150 | * get swap point accumulate 151 | * 152 | * @return int 153 | * @noinspection PhpUnused 154 | */ 155 | public function getSwapPointAccumulate() : int 156 | { 157 | return $this->swap_point_accumulate; 158 | } 159 | 160 | /** 161 | * get require collateral 162 | * 163 | * @return int 164 | */ 165 | public function getRequireCollateral() : int 166 | { 167 | return $this->require_collateral; 168 | } 169 | 170 | /** 171 | * get open date 172 | * 173 | * @return string 174 | */ 175 | public function getOpenDate() : string 176 | { 177 | return $this->open_date; 178 | } 179 | 180 | /** 181 | * get leverage 182 | * 183 | * @return int 184 | */ 185 | public function getLeverage() : int 186 | { 187 | return $this->leverage; 188 | } 189 | 190 | /** 191 | * get pnl 192 | * 193 | * @return int 194 | * @noinspection PhpUnused 195 | */ 196 | public function getPnl() : int 197 | { 198 | return $this->pnl; 199 | } 200 | 201 | } -------------------------------------------------------------------------------- /src/Object/Ticker.php: -------------------------------------------------------------------------------- 1 | product_code = $product_code; 53 | $this->timestamp = $timestamp; 54 | $this->tick_id = $tick_id; 55 | $this->best_bid = $best_bid; 56 | $this->best_ask = $best_ask; 57 | $this->best_bid_size = $best_bid_size; 58 | $this->best_ask_size = $best_ask_size; 59 | $this->total_bid_depth = $total_bid_depth; 60 | $this->total_ask_depth = $total_ask_depth; 61 | $this->ltp = $ltp; 62 | $this->volume = $volume; 63 | $this->volume_by_product = $volume_by_product; 64 | } 65 | 66 | /** 67 | * construct from stdObject 68 | * 69 | * @param array $data 70 | * 71 | * @return Ticker 72 | */ 73 | public static function fromArray(array $data) : Ticker 74 | { 75 | return new self( 76 | $data['product_code'] ?? null, 77 | $data['timestamp'] ?? null, 78 | $data['tick_id'] ?? null, 79 | $data['best_bid'] ?? null, 80 | $data['best_ask'] ?? null, 81 | $data['best_bid_size'] ?? null, 82 | $data['best_ask_size'] ?? null, 83 | $data['total_bid_depth'] ?? null, 84 | $data['total_ask_depth'] ?? null, 85 | $data['ltp'] ?? null, 86 | $data['volume'] ?? null, 87 | $data['volume_by_product'] ?? null 88 | ); 89 | } 90 | 91 | /** 92 | * get product code 93 | * 94 | * @return string 95 | */ 96 | public function getProductCode() : string 97 | { 98 | return $this->product_code; 99 | } 100 | 101 | /** 102 | * get timestamp 103 | * 104 | * @return string 105 | * @noinspection PhpUnused 106 | */ 107 | public function getTimeStamp() : string 108 | { 109 | return $this->timestamp; 110 | } 111 | 112 | /** 113 | * get ticker id 114 | * 115 | * @return int 116 | * @noinspection PhpUnused 117 | */ 118 | public function getTickId() : int 119 | { 120 | return $this->tick_id; 121 | } 122 | 123 | /** 124 | * get best bid 125 | * 126 | * @return float 127 | * @noinspection PhpUnused 128 | */ 129 | public function getBestBid() : float 130 | { 131 | return $this->best_bid; 132 | } 133 | 134 | /** 135 | * get best bid size 136 | * 137 | * @return float 138 | * @noinspection PhpUnused 139 | */ 140 | public function getBestBidSize() : float 141 | { 142 | return $this->best_bid_size; 143 | } 144 | 145 | /** 146 | * get best ask size 147 | * 148 | * @return float 149 | */ 150 | public function getBestAskSize() : float 151 | { 152 | return $this->best_ask_size; 153 | } 154 | 155 | /** 156 | * get total bid depth 157 | * 158 | * @return float 159 | */ 160 | public function getTotalBidDepth() : float 161 | { 162 | return $this->total_bid_depth; 163 | } 164 | 165 | /** 166 | * get total ask depth 167 | * 168 | * @return float 169 | * @noinspection PhpUnused 170 | */ 171 | public function getTotalAskDepth() : float 172 | { 173 | return $this->total_ask_depth; 174 | } 175 | 176 | /** 177 | * get ltp 178 | * 179 | * @return float 180 | * @noinspection PhpUnused 181 | */ 182 | public function getLtp() : float 183 | { 184 | return $this->ltp; 185 | } 186 | 187 | /** 188 | * get volume 189 | * 190 | * @return float 191 | * @noinspection PhpUnused 192 | */ 193 | public function getVolume() : float 194 | { 195 | return $this->volume; 196 | } 197 | 198 | /** 199 | * get volume 200 | * 201 | * @return float 202 | * @noinspection PhpUnused 203 | */ 204 | public function getVolumeByProduct() : float 205 | { 206 | return $this->volume_by_product; 207 | } 208 | } -------------------------------------------------------------------------------- /src/Object/MeChildOrder.php: -------------------------------------------------------------------------------- 1 | id = $id; 96 | $this->child_order_id = $child_order_id; 97 | $this->product_code = $product_code; 98 | $this->side = $side; 99 | $this->child_order_type = $child_order_type; 100 | $this->price = $price; 101 | $this->average_price = $average_price; 102 | $this->size = $size; 103 | $this->child_order_state = $child_order_state; 104 | $this->expire_date = $expire_date; 105 | $this->child_order_date = $child_order_date; 106 | $this->child_order_acceptance_id = $child_order_acceptance_id; 107 | $this->outstanding_size = $outstanding_size; 108 | $this->cancel_size = $cancel_size; 109 | $this->executed_size = $executed_size; 110 | $this->total_commission = $total_commission; 111 | } 112 | 113 | /** 114 | * construct from stdObject 115 | * 116 | * @param array $data 117 | * 118 | * @return MeChildOrder 119 | */ 120 | public static function fromArray(array $data) : MeChildOrder 121 | { 122 | return new self( 123 | $data['id'] ?? null, 124 | $data['child_order_id'] ?? null, 125 | $data['product_code'] ?? null, 126 | $data['side'] ?? null, 127 | $data['child_order_type'] ?? null, 128 | $data['price'] ?? null, 129 | $data['average_price'] ?? null, 130 | $data['size'] ?? null, 131 | $data['child_order_state'] ?? null, 132 | $data['expire_date'] ?? null, 133 | $data['child_order_date'] ?? null, 134 | $data['child_order_acceptance_id'] ?? null, 135 | $data['outstanding_size'] ?? null, 136 | $data['cancel_size'] ?? null, 137 | $data['executed_size'] ?? null, 138 | $data['total_commission'] ?? null 139 | ); 140 | } 141 | 142 | /** 143 | * get id 144 | * 145 | * @return int 146 | */ 147 | public function getId() : int 148 | { 149 | return $this->id; 150 | } 151 | 152 | /** 153 | * get child order id 154 | * 155 | * @return string 156 | */ 157 | public function getChildOrderId() : string 158 | { 159 | return $this->child_order_id; 160 | } 161 | 162 | /** 163 | * get product code 164 | * 165 | * @return string 166 | */ 167 | public function getProductCode() : string 168 | { 169 | return $this->product_code; 170 | } 171 | 172 | /** 173 | * get side 174 | * 175 | * @return string 176 | */ 177 | public function getSide() : string 178 | { 179 | return $this->side; 180 | } 181 | 182 | /** 183 | * get child order type 184 | * 185 | * @return string 186 | */ 187 | public function getChildOrderType() : string 188 | { 189 | return $this->child_order_type; 190 | } 191 | 192 | /** 193 | * get price 194 | * 195 | * @return int 196 | */ 197 | public function getPrice() : int 198 | { 199 | return $this->price; 200 | } 201 | 202 | /** 203 | * get average price 204 | * 205 | * @return int 206 | * @noinspection PhpUnused 207 | */ 208 | public function getAveragePrice() : int 209 | { 210 | return $this->average_price; 211 | } 212 | 213 | /** 214 | * get size 215 | * 216 | * @return float 217 | */ 218 | public function getSize() : float 219 | { 220 | return $this->size; 221 | } 222 | 223 | /** 224 | * get child order state 225 | * 226 | * @return string 227 | */ 228 | public function getChildOrderState() : string 229 | { 230 | return $this->child_order_state; 231 | } 232 | 233 | /** 234 | * get expire date 235 | * 236 | * @return string 237 | */ 238 | public function getExpireDate() : string 239 | { 240 | return $this->expire_date; 241 | } 242 | 243 | /** 244 | * get child order date 245 | * 246 | * @return string 247 | */ 248 | public function getChildOrderDate() : string 249 | { 250 | return $this->child_order_date; 251 | } 252 | 253 | /** 254 | * get child order acceptance id 255 | * 256 | * @return string 257 | */ 258 | public function getChildOrderAcceptanceId() : string 259 | { 260 | return $this->child_order_acceptance_id; 261 | } 262 | 263 | /** 264 | * get outstanding size 265 | * 266 | * @return float 267 | * @noinspection PhpUnused 268 | */ 269 | public function getOutstandingSize() : float 270 | { 271 | return $this->outstanding_size; 272 | } 273 | 274 | /** 275 | * get cancel size 276 | * 277 | * @return float 278 | */ 279 | public function getCancelSize() : float 280 | { 281 | return $this->cancel_size; 282 | } 283 | 284 | /** 285 | * get executed size 286 | * 287 | * @return float 288 | */ 289 | public function getExecutedSize() : float 290 | { 291 | return $this->executed_size; 292 | } 293 | 294 | /** 295 | * get total commission 296 | * 297 | * @return float 298 | */ 299 | public function getTotalCommission() : float 300 | { 301 | return $this->total_commission; 302 | } 303 | 304 | } -------------------------------------------------------------------------------- /src/PhitFlyerClientInterface.php: -------------------------------------------------------------------------------- 1 | assertGreaterThan(0,strlen($api_key),'Plase set environment variable(PHITFLYER_API_KEY) before running this test.'); 22 | $this->assertGreaterThan(0,strlen($api_secret),'Plase set environment variable(PHITFLYER_API_SECRET) before running this test.'); 23 | 24 | $this->client = new PhitFlyerClient($api_key, $api_secret); 25 | 26 | sleep(1); 27 | } 28 | 29 | public function testGetMarkets() 30 | { 31 | $client = new PhitFlyerObjectClient($this->client); 32 | 33 | $markets = $client->getMarkets(); 34 | 35 | $this->assertInternalType('array', $markets ); 36 | $this->assertGreaterThanOrEqual(0, count($markets) ); 37 | 38 | foreach($markets as $item){ 39 | $this->assertInstanceOf('PhitFlyer\Object\Market', $item ); 40 | } 41 | } 42 | 43 | public function testGetBoard() 44 | { 45 | $client = new PhitFlyerObjectClient($this->client); 46 | 47 | $board = $client->getBoard(); 48 | 49 | $this->assertInternalType('object', $board ); 50 | $this->assertInstanceOf('PhitFlyer\Object\Board', $board ); 51 | } 52 | 53 | public function testGetBoardWithProductCode() 54 | { 55 | $client = new PhitFlyerObjectClient($this->client); 56 | 57 | $board = $client->getBoard('BTC_JPY'); 58 | 59 | $this->assertInternalType('object', $board ); 60 | $this->assertInstanceOf('PhitFlyer\Object\Board', $board ); 61 | } 62 | 63 | public function testTicker() 64 | { 65 | $client = new PhitFlyerObjectClient($this->client); 66 | 67 | $ticker = $client->getTicker(); 68 | 69 | $this->assertInternalType('object', $ticker ); 70 | $this->assertInstanceOf('PhitFlyer\Object\Ticker', $ticker ); 71 | } 72 | 73 | public function testGetTickerWithProductCode() 74 | { 75 | $client = new PhitFlyerObjectClient($this->client); 76 | 77 | $ticker = $client->getTicker('BTC_JPY'); 78 | 79 | $this->assertInternalType('object', $ticker ); 80 | $this->assertInstanceOf('PhitFlyer\Object\Ticker', $ticker ); 81 | } 82 | 83 | public function testGetExecutions() 84 | { 85 | $client = new PhitFlyerObjectClient($this->client); 86 | 87 | $executions = $client->getExecutions(); 88 | 89 | $this->assertInternalType('array', $executions ); 90 | $this->assertGreaterThanOrEqual(0, count($executions) ); 91 | 92 | foreach($executions as $item){ 93 | $this->assertInstanceOf('PhitFlyer\Object\Execution', $item ); 94 | } 95 | } 96 | 97 | public function testGetExecutionsWithProductCode() 98 | { 99 | $client = new PhitFlyerObjectClient($this->client); 100 | 101 | $executions = $client->getExecutions('BTC_JPY'); 102 | 103 | $this->assertInternalType('array', $executions ); 104 | $this->assertGreaterThanOrEqual(0, count($executions) ); 105 | 106 | foreach($executions as $item){ 107 | $this->assertInstanceOf('PhitFlyer\Object\Execution', $item ); 108 | } 109 | } 110 | 111 | public function testGetBoardState() 112 | { 113 | $client = new PhitFlyerObjectClient($this->client); 114 | 115 | $board_state = $client->getBoardState('BTC_JPY'); 116 | 117 | $this->assertInternalType('object', $board_state ); 118 | $this->assertInstanceOf('PhitFlyer\Object\BoardState', $board_state ); 119 | } 120 | 121 | public function testGetHealth() 122 | { 123 | $client = new PhitFlyerObjectClient($this->client); 124 | 125 | $health = $client->getHealth(); 126 | 127 | $this->assertInternalType('object', $health ); 128 | $this->assertInstanceOf('PhitFlyer\Object\Health', $health ); 129 | } 130 | 131 | public function testGetChats() 132 | { 133 | $client = new PhitFlyerObjectClient($this->client); 134 | 135 | $from_date = date('Y-m-d\Th:i:s', strtotime('-1 min')); 136 | $chats = $client->getChats($from_date); 137 | 138 | $this->assertInternalType('array', $chats ); 139 | $this->assertGreaterThanOrEqual(0, count($chats) ); 140 | 141 | foreach($chats as $item){ 142 | $this->assertInstanceOf('PhitFlyer\Object\Chat', $item ); 143 | } 144 | } 145 | 146 | public function testMeGetPermissions() 147 | { 148 | $client = new PhitFlyerObjectClient($this->client); 149 | 150 | $permissions = $client->meGetPermissions(); 151 | 152 | $this->assertInternalType('array', $permissions ); 153 | $this->assertGreaterThanOrEqual(0, count($permissions) ); 154 | 155 | foreach($permissions as $item){ 156 | $this->assertInternalType('string', $item ); 157 | } 158 | } 159 | 160 | public function testMeGetBalance() 161 | { 162 | $client = new PhitFlyerObjectClient($this->client); 163 | 164 | $balances = $client->meGetBalance(); 165 | 166 | $this->assertInternalType('array', $balances ); 167 | $this->assertGreaterThanOrEqual(0, count($balances) ); 168 | 169 | foreach($balances as $item){ 170 | $this->assertInstanceOf('PhitFlyer\Object\MeBalance', $item ); 171 | } 172 | } 173 | 174 | public function testMeGetCollateral() 175 | { 176 | $client = new PhitFlyerObjectClient($this->client); 177 | 178 | $collateral = $client->meGetCollateral(); 179 | 180 | $this->assertInternalType('object', $collateral ); 181 | $this->assertInstanceOf('PhitFlyer\Object\MeCollateral', $collateral ); 182 | } 183 | 184 | public function testMeGetCollateralAccounts() 185 | { 186 | $client = new PhitFlyerObjectClient($this->client); 187 | 188 | $accounts = $client->meGetCollateralAccounts(); 189 | 190 | $this->assertInternalType('array', $accounts ); 191 | $this->assertGreaterThanOrEqual(0, count($accounts) ); 192 | 193 | foreach($accounts as $item){ 194 | $this->assertInstanceOf('PhitFlyer\Object\MeCollateralAccount', $item ); 195 | } 196 | } 197 | 198 | public function testMeGetAddress() 199 | { 200 | $client = new PhitFlyerObjectClient($this->client); 201 | 202 | $addresses = $client->meGetAddress(); 203 | 204 | $this->assertInternalType('array', $addresses ); 205 | $this->assertGreaterThanOrEqual(0, count($addresses) ); 206 | 207 | foreach($addresses as $item){ 208 | $this->assertInstanceOf('PhitFlyer\Object\MeAddress', $item ); 209 | } 210 | } 211 | 212 | public function testMeGetCoinIns() 213 | { 214 | $client = new PhitFlyerObjectClient($this->client); 215 | 216 | $coinins = $client->meGetCoinIns(); 217 | 218 | $this->assertInternalType('array', $coinins ); 219 | $this->assertGreaterThanOrEqual(0, count($coinins) ); 220 | 221 | foreach($coinins as $item){ 222 | $this->assertInstanceOf('PhitFlyer\Object\MeCoinIn', $item ); 223 | } 224 | } 225 | 226 | public function testMeGetCoinOuts() 227 | { 228 | $client = new PhitFlyerObjectClient($this->client); 229 | 230 | $coinouts = $client->meGetCoinOuts(); 231 | 232 | $this->assertInternalType('array', $coinouts ); 233 | $this->assertGreaterThanOrEqual(0, count($coinouts) ); 234 | 235 | foreach($coinouts as $item){ 236 | $this->assertInstanceOf('PhitFlyer\Object\MeCoinOut', $item ); 237 | } 238 | } 239 | 240 | public function testMeGetBankAccounts() 241 | { 242 | $client = new PhitFlyerObjectClient($this->client); 243 | 244 | $bank_accounts = $client->meGetBankAccounts(); 245 | 246 | $this->assertInternalType('array', $bank_accounts ); 247 | $this->assertGreaterThanOrEqual(0, count($bank_accounts) ); 248 | 249 | foreach($bank_accounts as $item){ 250 | $this->assertInstanceOf('PhitFlyer\Object\MeBankAccount', $item ); 251 | } 252 | } 253 | 254 | public function testMeGetDeposits() 255 | { 256 | $client = new PhitFlyerObjectClient($this->client); 257 | 258 | $deposits = $client->meGetDeposits(); 259 | 260 | $this->assertInternalType('array', $deposits ); 261 | $this->assertGreaterThanOrEqual(0, count($deposits) ); 262 | 263 | foreach($deposits as $item){ 264 | $this->assertInstanceOf('PhitFlyer\Object\MeDeposit', $item ); 265 | } 266 | } 267 | 268 | public function testMeSendChildOrder() 269 | { 270 | $this->assertTrue(true); 271 | 272 | //$client = new PhitFlyerObjectClient($this->client); 273 | 274 | //$result = $client->meSendChildOrder( 275 | // 'FX_BTC_JPY', 'LIMIT', 'SELL' ,300000, 0.1 276 | //); 277 | 278 | //$this->assertInternalType('object', $result ); 279 | //$this->assertInstanceOf('PhitFlyer\Object\MeChildOrderResult', $result ); 280 | } 281 | 282 | public function testMeCancelChildOrder() 283 | { 284 | $this->assertTrue(true); 285 | 286 | //$client = new PhitFlyerObjectClient($this->client); 287 | 288 | //$client->meCancelChildOrder('FX_BTC_JPY', 'JFX20170717-213404-907976F'); 289 | } 290 | 291 | public function testMeCancelAllChildOrders() 292 | { 293 | $client = new PhitFlyerObjectClient($this->client); 294 | 295 | $client->meCancelAllChildOrders('FX_BTC_JPY'); 296 | } 297 | 298 | public function testMeGetChildOrders() 299 | { 300 | $client = new PhitFlyerObjectClient($this->client); 301 | 302 | $child_orders = $client->meGetChildOrders( 303 | 'FX_BTC_JPY', null, null, null, 'ACTIVE' 304 | ); 305 | 306 | $this->assertInternalType('array', $child_orders ); 307 | $this->assertGreaterThanOrEqual(0, count($child_orders) ); 308 | 309 | foreach($child_orders as $item){ 310 | $this->assertInstanceOf('PhitFlyer\Object\MeChildOrder', $item ); 311 | } 312 | } 313 | 314 | public function testMeGetExecutions() 315 | { 316 | $client = new PhitFlyerObjectClient($this->client); 317 | 318 | $executions = $client->meGetExecutions( 'FX_BTC_JPY', null, null, 10 ); 319 | 320 | $this->assertInternalType('array', $executions ); 321 | $this->assertGreaterThanOrEqual(0, count($executions) ); 322 | 323 | foreach($executions as $item){ 324 | $this->assertInstanceOf('PhitFlyer\Object\MeExecution', $item ); 325 | } 326 | } 327 | 328 | public function testMeGetPositions() 329 | { 330 | $client = new PhitFlyerObjectClient($this->client); 331 | 332 | $positions = $client->meGetPositions('FX_BTC_JPY'); 333 | 334 | $this->assertInternalType('array', $positions ); 335 | $this->assertGreaterThanOrEqual(0, count($positions) ); 336 | 337 | foreach($positions as $item){ 338 | $this->assertInstanceOf('PhitFlyer\Object\MePosition', $item ); 339 | } 340 | } 341 | 342 | public function testMeGetTradingCommission() 343 | { 344 | $client = new PhitFlyerObjectClient($this->client); 345 | 346 | $commissions = $client->meGetTradingCommission('FX_BTC_JPY'); 347 | 348 | $this->assertInternalType('object', $commissions ); 349 | $this->assertInstanceOf('PhitFlyer\Object\MeCommission', $commissions ); 350 | } 351 | } -------------------------------------------------------------------------------- /test/PhitFlyerLoggerClientTest.php: -------------------------------------------------------------------------------- 1 | assertGreaterThan(0,strlen($api_key),'Plase set environment variable(PHITFLYER_API_KEY) before running this test.'); 26 | $this->assertGreaterThan(0,strlen($api_secret),'Plase set environment variable(PHITFLYER_API_SECRET) before running this test.'); 27 | 28 | $this->client = new PhitFlyerLoggerClient(new PhitFlyerClient($api_key, $api_secret), new EchoLogger()); 29 | 30 | sleep(1); 31 | } 32 | 33 | public function testGetMarkets() 34 | { 35 | $markets = $this->client->getMarkets(); 36 | 37 | /** @var HttpGetRequest $req */ 38 | $req = $this->client->getLastRequest(); 39 | 40 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::MARKETS, $req->getUrl() ); 41 | $this->assertInternalType('array', $markets ); 42 | $this->assertGreaterThanOrEqual(0, count($markets) ); 43 | } 44 | 45 | public function testGetBoard() 46 | { 47 | $board = $this->client->getBoard(); 48 | 49 | /** @var HttpGetRequest $req */ 50 | $req = $this->client->getLastRequest(); 51 | 52 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::BOARD, $req->getUrl() ); 53 | $this->assertInternalType('array', $board ); 54 | } 55 | 56 | public function testGetBoardWithProductCode() 57 | { 58 | $board = $this->client->getBoard('BTC_JPY'); 59 | 60 | /** @var HttpGetRequest $req */ 61 | $req = $this->client->getLastRequest(); 62 | 63 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::BOARD . '?product_code=BTC_JPY', $req->getUrl() ); 64 | $this->assertInternalType('array', $board ); 65 | } 66 | 67 | public function testTicker() 68 | { 69 | $ticker = $this->client->getTicker(); 70 | 71 | /** @var HttpGetRequest $req */ 72 | $req = $this->client->getLastRequest(); 73 | 74 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::TICKER, $req->getUrl() ); 75 | $this->assertInternalType('array', $ticker ); 76 | } 77 | 78 | public function testGetTickerWithProductCode() 79 | { 80 | $ticker = $this->client->getTicker('BTC_JPY'); 81 | 82 | /** @var HttpGetRequest $req */ 83 | $req = $this->client->getLastRequest(); 84 | 85 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::TICKER . '?product_code=BTC_JPY', $req->getUrl() ); 86 | $this->assertInternalType('array', $ticker ); 87 | } 88 | 89 | public function testGetExecutions() 90 | { 91 | $executions = $this->client->getExecutions(); 92 | 93 | /** @var HttpGetRequest $req */ 94 | $req = $this->client->getLastRequest(); 95 | 96 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::EXECUTIONS, $req->getUrl() ); 97 | $this->assertInternalType('array', $executions ); 98 | } 99 | 100 | public function testGetExecutionsWithProductCode() 101 | { 102 | $executions = $this->client->getExecutions('BTC_JPY'); 103 | 104 | /** @var HttpGetRequest $req */ 105 | $req = $this->client->getLastRequest(); 106 | 107 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::EXECUTIONS . '?product_code=BTC_JPY', $req->getUrl() ); 108 | $this->assertInternalType('array', $executions ); 109 | } 110 | 111 | public function testGetBoardState() 112 | { 113 | $board_state = $this->client->getBoardState(); 114 | 115 | /** @var HttpGetRequest $req */ 116 | $req = $this->client->getLastRequest(); 117 | 118 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETBOARDSTATE, $req->getUrl() ); 119 | $this->assertInternalType('array', $board_state ); 120 | } 121 | 122 | public function testGetHealth() 123 | { 124 | $health = $this->client->getHealth(); 125 | 126 | /** @var HttpGetRequest $req */ 127 | $req = $this->client->getLastRequest(); 128 | 129 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETHEALTH, $req->getUrl() ); 130 | $this->assertInternalType('array', $health ); 131 | } 132 | 133 | public function testGetChats() 134 | { 135 | $from_date = date('Y-m-d\Th:i:s', strtotime('-1 min')); 136 | $chats = $this->client->getChats($from_date); 137 | 138 | /** @var HttpGetRequest $req */ 139 | $req = $this->client->getLastRequest(); 140 | 141 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETCHATS . '?from_date=' . rawurlencode($from_date), $req->getUrl() ); 142 | $this->assertInternalType('array', $chats ); 143 | } 144 | 145 | public function testMeGetPermissions() 146 | { 147 | $permissions = $this->client->meGetPermissions(); 148 | 149 | /** @var HttpGetRequest $req */ 150 | $req = $this->client->getLastRequest(); 151 | 152 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETPERMISSIONS, $req->getUrl() ); 153 | $this->assertInternalType('array', $permissions ); 154 | 155 | foreach($permissions as $item){ 156 | $this->assertInternalType('string', $item ); 157 | } 158 | } 159 | 160 | public function testMeGetBalance() 161 | { 162 | $balances = $this->client->meGetBalance(); 163 | 164 | /** @var HttpGetRequest $req */ 165 | $req = $this->client->getLastRequest(); 166 | 167 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETBALANCE, $req->getUrl() ); 168 | $this->assertInternalType('array', $balances ); 169 | 170 | foreach($balances as $item){ 171 | $this->assertInternalType('array', $item ); 172 | } 173 | } 174 | 175 | public function testMeGetCollateral() 176 | { 177 | $collateral = $this->client->meGetCollateral(); 178 | 179 | /** @var HttpGetRequest $req */ 180 | $req = $this->client->getLastRequest(); 181 | 182 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOLLATERAL, $req->getUrl() ); 183 | $this->assertInternalType('array', $collateral ); 184 | } 185 | 186 | public function testMeGetCollateralAccounts() 187 | { 188 | $accounts = $this->client->meGetCollateralAccounts(); 189 | 190 | /** @var HttpGetRequest $req */ 191 | $req = $this->client->getLastRequest(); 192 | 193 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOLLATERALACCOUNTS, $req->getUrl() ); 194 | $this->assertInternalType('array', $accounts ); 195 | 196 | foreach($accounts as $item){ 197 | $this->assertInternalType('array', $item ); 198 | } 199 | } 200 | 201 | public function testMeGetAddress() 202 | { 203 | $addresses = $this->client->meGetAddress(); 204 | 205 | /** @var HttpGetRequest $req */ 206 | $req = $this->client->getLastRequest(); 207 | 208 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETADDRESS, $req->getUrl() ); 209 | $this->assertInternalType('array', $addresses ); 210 | 211 | foreach($addresses as $item){ 212 | $this->assertInternalType('array', $item ); 213 | } 214 | } 215 | 216 | public function testMeGetCoinIns() 217 | { 218 | $coinins = $this->client->meGetCoinIns(); 219 | 220 | /** @var HttpGetRequest $req */ 221 | $req = $this->client->getLastRequest(); 222 | 223 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOININS, $req->getUrl() ); 224 | $this->assertInternalType('array', $coinins ); 225 | 226 | foreach($coinins as $item){ 227 | $this->assertInternalType('array', $item ); 228 | } 229 | } 230 | 231 | public function testMeGetCoinOuts() 232 | { 233 | $coinouts = $this->client->meGetCoinOuts(); 234 | 235 | /** @var HttpGetRequest $req */ 236 | $req = $this->client->getLastRequest(); 237 | 238 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOINOUTS, $req->getUrl() ); 239 | $this->assertInternalType('array', $coinouts ); 240 | 241 | foreach($coinouts as $item){ 242 | $this->assertInternalType('array', $item ); 243 | } 244 | } 245 | 246 | public function testMeGetBankAccounts() 247 | { 248 | $bank_accounts = $this->client->meGetBankAccounts(); 249 | 250 | /** @var HttpGetRequest $req */ 251 | $req = $this->client->getLastRequest(); 252 | 253 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETBANKACCOUNTS, $req->getUrl() ); 254 | $this->assertInternalType('array', $bank_accounts ); 255 | 256 | foreach($bank_accounts as $item){ 257 | $this->assertInternalType('array', $item ); 258 | } 259 | } 260 | 261 | public function testMeGetDeposits() 262 | { 263 | $deposits = $this->client->meGetDeposits(); 264 | 265 | /** @var HttpGetRequest $req */ 266 | $req = $this->client->getLastRequest(); 267 | 268 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETDEPOSITS, $req->getUrl() ); 269 | $this->assertInternalType('array', $deposits ); 270 | 271 | foreach($deposits as $item){ 272 | $this->assertInternalType('array', $item ); 273 | } 274 | } 275 | 276 | public function testMeSendChildOrder() 277 | { 278 | $this->assertTrue(true); 279 | 280 | //$result = $this->client->meSendChildOrder( 281 | // 'FX_BTC_JPY', 'LIMIT', 'SELL' ,300000, 0.001 282 | //); 283 | 284 | /** @var HttpGetRequest $req */ 285 | //$req = $this->client->getLastRequest(); 286 | 287 | //$this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_SENDCHILDORDER, $req->getUrl() ); 288 | //$this->assertInternalType('object', $result ); 289 | } 290 | 291 | public function testMeCancelChildOrder() 292 | { 293 | $this->assertTrue(true); 294 | 295 | //$this->client->meCancelChildOrder('FX_BTC_JPY', 'JFX20170717-213828-930722F'); 296 | 297 | /** @var HttpGetRequest $req */ 298 | //$req = $this->client->getLastRequest(); 299 | 300 | //$this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_CANCELCHILDORDER, $req->getUrl() ); 301 | } 302 | 303 | public function testMeCancelAllChildOrders() 304 | { 305 | $this->client->meCancelAllChildOrders('FX_BTC_JPY'); 306 | 307 | /** @var HttpGetRequest $req */ 308 | $req = $this->client->getLastRequest(); 309 | 310 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_CANCELALLCHILDORDERS, $req->getUrl() ); 311 | } 312 | 313 | public function testMeGetChildOrders() 314 | { 315 | $child_orders = $this->client->meGetChildOrders( 316 | 'FX_BTC_JPY', null, null, null, 'ACTIVE' 317 | ); 318 | 319 | /** @var HttpGetRequest $req */ 320 | $req = $this->client->getLastRequest(); 321 | 322 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCHILDORDERS . '?product_code=FX_BTC_JPY&child_order_state=ACTIVE', $req->getUrl() ); 323 | $this->assertInternalType('array', $child_orders ); 324 | 325 | foreach($child_orders as $item){ 326 | $this->assertInternalType('array', $item ); 327 | } 328 | } 329 | 330 | public function testMeGetExecutions() 331 | { 332 | $executions = $this->client->meGetExecutions( 'FX_BTC_JPY', null, null, 10 ); 333 | 334 | /** @var HttpGetRequest $req */ 335 | $req = $this->client->getLastRequest(); 336 | 337 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETEXECUTIONS . '?product_code=FX_BTC_JPY&count=10', $req->getUrl() ); 338 | $this->assertInternalType('array', $executions ); 339 | 340 | foreach($executions as $item){ 341 | $this->assertInternalType('array', $item ); 342 | } 343 | } 344 | 345 | public function testMeGetPositions() 346 | { 347 | $positions = $this->client->meGetPositions('FX_BTC_JPY'); 348 | 349 | /** @var HttpGetRequest $req */ 350 | $req = $this->client->getLastRequest(); 351 | 352 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETPOSITIONS . '?product_code=FX_BTC_JPY', $req->getUrl() ); 353 | $this->assertInternalType('array', $positions ); 354 | 355 | foreach($positions as $item){ 356 | $this->assertInternalType('array', $item ); 357 | } 358 | } 359 | 360 | public function testMeGetTradingCommission() 361 | { 362 | $commissions = $this->client->meGetTradingCommission('FX_BTC_JPY'); 363 | 364 | /** @var HttpGetRequest $req */ 365 | $req = $this->client->getLastRequest(); 366 | 367 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETTRADINGCOMMISSION . '?product_code=FX_BTC_JPY', $req->getUrl() ); 368 | $this->assertInternalType('array', $commissions ); 369 | } 370 | } -------------------------------------------------------------------------------- /test/PhitFlyerClientTest.php: -------------------------------------------------------------------------------- 1 | assertGreaterThan(0,strlen($api_key),'Plase set environment variable(PHITFLYER_API_KEY) before running this test.'); 23 | $this->assertGreaterThan(0,strlen($api_secret),'Plase set environment variable(PHITFLYER_API_SECRET) before running this test.'); 24 | 25 | $this->client = new PhitFlyerClient($api_key, $api_secret); 26 | 27 | sleep(1); 28 | } 29 | 30 | public function testGetMarkets() 31 | { 32 | $markets = $this->client->getMarkets(); 33 | 34 | /** @var HttpGetRequest $req */ 35 | $req = $this->client->getLastRequest(); 36 | 37 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::MARKETS, $req->getUrl() ); 38 | $this->assertInternalType('array', $markets ); 39 | $this->assertGreaterThanOrEqual(0, count($markets) ); 40 | } 41 | 42 | public function testGetBoard() 43 | { 44 | $board = $this->client->getBoard(); 45 | 46 | /** @var HttpGetRequest $req */ 47 | $req = $this->client->getLastRequest(); 48 | 49 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::BOARD, $req->getUrl() ); 50 | $this->assertInternalType('array', $board ); 51 | } 52 | 53 | public function testGetBoardWithProductCode() 54 | { 55 | $board = $this->client->getBoard('BTC_JPY'); 56 | 57 | /** @var HttpGetRequest $req */ 58 | $req = $this->client->getLastRequest(); 59 | 60 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::BOARD . '?product_code=BTC_JPY', $req->getUrl() ); 61 | $this->assertInternalType('array', $board ); 62 | } 63 | 64 | public function testTicker() 65 | { 66 | $ticker = $this->client->getTicker(); 67 | 68 | /** @var HttpGetRequest $req */ 69 | $req = $this->client->getLastRequest(); 70 | 71 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::TICKER, $req->getUrl() ); 72 | $this->assertInternalType('array', $ticker ); 73 | } 74 | 75 | public function testGetTickerWithProductCode() 76 | { 77 | $ticker = $this->client->getTicker('BTC_JPY'); 78 | 79 | /** @var HttpGetRequest $req */ 80 | $req = $this->client->getLastRequest(); 81 | 82 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::TICKER . '?product_code=BTC_JPY', $req->getUrl() ); 83 | $this->assertInternalType('array', $ticker ); 84 | } 85 | 86 | public function testGetExecutions() 87 | { 88 | $executions = $this->client->getExecutions(); 89 | 90 | /** @var HttpGetRequest $req */ 91 | $req = $this->client->getLastRequest(); 92 | 93 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::EXECUTIONS, $req->getUrl() ); 94 | $this->assertInternalType('array', $executions ); 95 | } 96 | 97 | public function testGetExecutionsWithProductCode() 98 | { 99 | $executions = $this->client->getExecutions('BTC_JPY'); 100 | 101 | /** @var HttpGetRequest $req */ 102 | $req = $this->client->getLastRequest(); 103 | 104 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::EXECUTIONS . '?product_code=BTC_JPY', $req->getUrl() ); 105 | $this->assertInternalType('array', $executions ); 106 | } 107 | 108 | public function testGetBoardState() 109 | { 110 | $board_state = $this->client->getBoardState(); 111 | 112 | /** @var HttpGetRequest $req */ 113 | $req = $this->client->getLastRequest(); 114 | 115 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETBOARDSTATE, $req->getUrl() ); 116 | $this->assertInternalType('array', $board_state ); 117 | } 118 | 119 | public function testGetHealth() 120 | { 121 | $health = $this->client->getHealth(); 122 | 123 | /** @var HttpGetRequest $req */ 124 | $req = $this->client->getLastRequest(); 125 | 126 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETHEALTH, $req->getUrl() ); 127 | $this->assertInternalType('array', $health ); 128 | } 129 | 130 | public function testGetChats() 131 | { 132 | $from_date = date('Y-m-d\Th:i:s', strtotime('-1 min')); 133 | $chats = $this->client->getChats($from_date); 134 | 135 | /** @var HttpGetRequest $req */ 136 | $req = $this->client->getLastRequest(); 137 | 138 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::GETCHATS . '?from_date=' . rawurlencode($from_date), $req->getUrl() ); 139 | $this->assertInternalType('array', $chats ); 140 | } 141 | 142 | public function testMeGetPermissions() 143 | { 144 | $permissions = $this->client->meGetPermissions(); 145 | 146 | /** @var HttpGetRequest $req */ 147 | $req = $this->client->getLastRequest(); 148 | 149 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETPERMISSIONS, $req->getUrl() ); 150 | $this->assertInternalType('array', $permissions ); 151 | 152 | foreach($permissions as $item){ 153 | $this->assertInternalType('string', $item ); 154 | } 155 | } 156 | 157 | public function testMeGetBalance() 158 | { 159 | $balances = $this->client->meGetBalance(); 160 | 161 | /** @var HttpGetRequest $req */ 162 | $req = $this->client->getLastRequest(); 163 | 164 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETBALANCE, $req->getUrl() ); 165 | $this->assertInternalType('array', $balances ); 166 | 167 | foreach($balances as $item){ 168 | $this->assertInternalType('array', $item ); 169 | } 170 | } 171 | 172 | public function testMeGetCollateral() 173 | { 174 | $collateral = $this->client->meGetCollateral(); 175 | 176 | /** @var HttpGetRequest $req */ 177 | $req = $this->client->getLastRequest(); 178 | 179 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOLLATERAL, $req->getUrl() ); 180 | $this->assertInternalType('array', $collateral ); 181 | } 182 | 183 | public function testMeGetCollateralAccounts() 184 | { 185 | $accounts = $this->client->meGetCollateralAccounts(); 186 | 187 | /** @var HttpGetRequest $req */ 188 | $req = $this->client->getLastRequest(); 189 | 190 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOLLATERALACCOUNTS, $req->getUrl() ); 191 | $this->assertInternalType('array', $accounts ); 192 | 193 | foreach($accounts as $item){ 194 | $this->assertInternalType('array', $item ); 195 | } 196 | } 197 | 198 | public function testMeGetAddress() 199 | { 200 | $addresses = $this->client->meGetAddress(); 201 | 202 | /** @var HttpGetRequest $req */ 203 | $req = $this->client->getLastRequest(); 204 | 205 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETADDRESS, $req->getUrl() ); 206 | $this->assertInternalType('array', $addresses ); 207 | 208 | foreach($addresses as $item){ 209 | $this->assertInternalType('array', $item ); 210 | } 211 | } 212 | 213 | public function testMeGetCoinIns() 214 | { 215 | $coinins = $this->client->meGetCoinIns(); 216 | 217 | /** @var HttpGetRequest $req */ 218 | $req = $this->client->getLastRequest(); 219 | 220 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOININS, $req->getUrl() ); 221 | $this->assertInternalType('array', $coinins ); 222 | 223 | foreach($coinins as $item){ 224 | $this->assertInternalType('array', $item ); 225 | } 226 | } 227 | 228 | public function testMeGetCoinOuts() 229 | { 230 | $coinouts = $this->client->meGetCoinOuts(); 231 | 232 | /** @var HttpGetRequest $req */ 233 | $req = $this->client->getLastRequest(); 234 | 235 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCOINOUTS, $req->getUrl() ); 236 | $this->assertInternalType('array', $coinouts ); 237 | 238 | foreach($coinouts as $item){ 239 | $this->assertInternalType('array', $item ); 240 | } 241 | } 242 | 243 | public function testMeGetBankAccounts() 244 | { 245 | $bank_accounts = $this->client->meGetBankAccounts(); 246 | 247 | /** @var HttpGetRequest $req */ 248 | $req = $this->client->getLastRequest(); 249 | 250 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETBANKACCOUNTS, $req->getUrl() ); 251 | $this->assertInternalType('array', $bank_accounts ); 252 | 253 | foreach($bank_accounts as $item){ 254 | $this->assertInternalType('array', $item ); 255 | } 256 | } 257 | 258 | public function testMeGetDeposits() 259 | { 260 | $deposits = $this->client->meGetDeposits(); 261 | 262 | /** @var HttpGetRequest $req */ 263 | $req = $this->client->getLastRequest(); 264 | 265 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETDEPOSITS, $req->getUrl() ); 266 | $this->assertInternalType('array', $deposits ); 267 | 268 | foreach($deposits as $item){ 269 | $this->assertInternalType('array', $item ); 270 | } 271 | } 272 | 273 | public function testMeSendChildOrder() 274 | { 275 | $this->assertTrue(true); 276 | 277 | //$result = $this->client->meSendChildOrder( 278 | // 'FX_BTC_JPY', 'LIMIT', 'SELL' ,300000, 0.001 279 | //); 280 | 281 | /** @var HttpGetRequest $req */ 282 | //$req = $this->client->getLastRequest(); 283 | 284 | //$this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_SENDCHILDORDER, $req->getUrl() ); 285 | //$this->assertInternalType('object', $result ); 286 | } 287 | 288 | public function testMeCancelChildOrder() 289 | { 290 | $this->assertTrue(true); 291 | 292 | //$this->client->meCancelChildOrder('FX_BTC_JPY', 'JFX20170717-213828-930722F'); 293 | 294 | /** @var HttpGetRequest $req */ 295 | //$req = $this->client->getLastRequest(); 296 | 297 | //$this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_CANCELCHILDORDER, $req->getUrl() ); 298 | } 299 | 300 | public function testMeCancelAllChildOrders() 301 | { 302 | $this->client->meCancelAllChildOrders('FX_BTC_JPY'); 303 | 304 | /** @var HttpGetRequest $req */ 305 | $req = $this->client->getLastRequest(); 306 | 307 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_CANCELALLCHILDORDERS, $req->getUrl() ); 308 | } 309 | 310 | public function testMeGetChildOrders() 311 | { 312 | $child_orders = $this->client->meGetChildOrders( 313 | 'FX_BTC_JPY', null, null, null, 'ACTIVE' 314 | ); 315 | 316 | /** @var HttpGetRequest $req */ 317 | $req = $this->client->getLastRequest(); 318 | 319 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETCHILDORDERS . '?product_code=FX_BTC_JPY&child_order_state=ACTIVE', $req->getUrl() ); 320 | $this->assertInternalType('array', $child_orders ); 321 | 322 | foreach($child_orders as $item){ 323 | $this->assertInternalType('array', $item ); 324 | } 325 | } 326 | 327 | public function testMeGetExecutions() 328 | { 329 | $executions = $this->client->meGetExecutions( 'FX_BTC_JPY', null, null, 10 ); 330 | 331 | /** @var HttpGetRequest $req */ 332 | $req = $this->client->getLastRequest(); 333 | 334 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETEXECUTIONS . '?product_code=FX_BTC_JPY&count=10', $req->getUrl() ); 335 | $this->assertInternalType('array', $executions ); 336 | 337 | foreach($executions as $item){ 338 | $this->assertInternalType('array', $item ); 339 | } 340 | } 341 | 342 | public function testMeGetPositions() 343 | { 344 | $positions = $this->client->meGetPositions('FX_BTC_JPY'); 345 | 346 | /** @var HttpGetRequest $req */ 347 | $req = $this->client->getLastRequest(); 348 | 349 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETPOSITIONS . '?product_code=FX_BTC_JPY', $req->getUrl() ); 350 | $this->assertInternalType('array', $positions ); 351 | 352 | foreach($positions as $item){ 353 | $this->assertInternalType('array', $item ); 354 | } 355 | } 356 | 357 | public function testMeGetTradingCommission() 358 | { 359 | $commissions = $this->client->meGetTradingCommission('FX_BTC_JPY'); 360 | 361 | /** @var HttpGetRequest $req */ 362 | $req = $this->client->getLastRequest(); 363 | 364 | $this->assertEquals(PhitFlyerApi::ENDPOINT . PhitFlyerApi::ME_GETTRADINGCOMMISSION . '?product_code=FX_BTC_JPY', $req->getUrl() ); 365 | $this->assertInternalType('array', $commissions ); 366 | } 367 | } -------------------------------------------------------------------------------- /src/PhitFlyerLoggerClient.php: -------------------------------------------------------------------------------- 1 | client = $client; 32 | $this->logger = $logger; 33 | 34 | $client->addNetDriverChangeListener($this); 35 | } 36 | 37 | /** 38 | * get last request 39 | * 40 | * @return HttpRequest|null 41 | */ 42 | public function getLastRequest() : ?HttpRequest 43 | { 44 | return $this->client->getLastRequest(); 45 | } 46 | 47 | /** 48 | * Net driver change callback 49 | * 50 | * @param NetDriverInterface $net_driver 51 | */ 52 | public function onNetDriverChanged(NetDriverInterface $net_driver) 53 | { 54 | $net_driver->setLogger($this->logger); 55 | } 56 | 57 | /** 58 | * add net driver change listener 59 | * 60 | * @param NetDriverChangeListenerInterface|callable $listener 61 | */ 62 | public function addNetDriverChangeListener($listener) 63 | { 64 | $this->client->addNetDriverChangeListener($listener); 65 | } 66 | 67 | /** 68 | * get net driver 69 | * 70 | * @return NetDriverInterface|null 71 | */ 72 | public function getNetDriver() : ?NetDriverInterface 73 | { 74 | return $this->client->getNetDriver(); 75 | } 76 | 77 | /** 78 | * set net driver 79 | * 80 | * @param NetDriverInterface $net_driver 81 | */ 82 | public function setNetDriver(NetDriverInterface $net_driver) 83 | { 84 | $this->client->setNetDriver($net_driver); 85 | } 86 | 87 | /** 88 | * [public] get markets 89 | * 90 | * @return mixed 91 | * 92 | * @throws PhitFlyerClientExceptionInterface 93 | */ 94 | public function getMarkets() 95 | { 96 | $this->logger->debug('started getMarkets'); 97 | $ret = $this->client->getMarkets(); 98 | $this->logger->debug('finished getMarkets'); 99 | return $ret; 100 | } 101 | 102 | /** 103 | * [public] get boards 104 | * 105 | * @param string $product_code 106 | * 107 | * @return mixed 108 | * 109 | * @throws PhitFlyerClientExceptionInterface 110 | */ 111 | public function getBoard($product_code = null) 112 | { 113 | $this->logger->debug('started getBoard'); 114 | $ret = $this->client->getBoard($product_code); 115 | $this->logger->debug('finished getBoard'); 116 | return $ret; 117 | } 118 | 119 | /** 120 | * [public] get ticker 121 | * 122 | * @param string $product_code 123 | * 124 | * @return mixed 125 | * 126 | * @throws PhitFlyerClientExceptionInterface 127 | */ 128 | public function getTicker($product_code = null) 129 | { 130 | $this->logger->debug('started getTicker'); 131 | $ret = $this->client->getTicker($product_code); 132 | $this->logger->debug('finished getTicker'); 133 | return $ret; 134 | } 135 | 136 | /** 137 | * [public] get executions 138 | * 139 | * @param string $product_code 140 | * @param integer $before 141 | * @param integer $after 142 | * @param integer $count 143 | * 144 | * @return mixed 145 | * 146 | * @throws PhitFlyerClientExceptionInterface 147 | */ 148 | public function getExecutions($product_code = null, $before = null, $after = null, $count = null) 149 | { 150 | $this->logger->debug('started getExecutions'); 151 | $ret = $this->client->getExecutions($product_code, $before, $after, $count); 152 | $this->logger->debug('finished getExecutions'); 153 | return $ret; 154 | } 155 | 156 | /** 157 | * [public] get board state 158 | * 159 | * @param string $product_code 160 | * 161 | * @return mixed 162 | * 163 | * @throws PhitFlyerClientExceptionInterface 164 | */ 165 | public function getBoardState($product_code = null) 166 | { 167 | $this->logger->debug('started getBoardState'); 168 | $ret = $this->client->getBoardState($product_code); 169 | $this->logger->debug('finished getBoardState'); 170 | return $ret; 171 | } 172 | 173 | /** 174 | * [public] get health 175 | * 176 | * @return mixed 177 | * 178 | * @throws PhitFlyerClientExceptionInterface 179 | */ 180 | public function getHealth() 181 | { 182 | $this->logger->debug('started getHealth'); 183 | $ret = $this->client->getHealth(); 184 | $this->logger->debug('finished getHealth'); 185 | return $ret; 186 | } 187 | 188 | /** 189 | * [public] get chats 190 | * 191 | * @param string $from_date 192 | * 193 | * @return mixed 194 | * 195 | * @throws PhitFlyerClientExceptionInterface 196 | */ 197 | public function getChats($from_date = null) 198 | { 199 | $this->logger->debug('started getChats'); 200 | $ret = $this->client->getChats($from_date); 201 | $this->logger->debug('finished getChats'); 202 | return $ret; 203 | } 204 | 205 | /** 206 | * [private] get permissions 207 | * 208 | * @return mixed 209 | * 210 | * @throws PhitFlyerClientExceptionInterface 211 | */ 212 | public function meGetPermissions() 213 | { 214 | $this->logger->debug('started meGetPermissions'); 215 | $ret = $this->client->meGetPermissions(); 216 | $this->logger->debug('finished meGetPermissions'); 217 | return $ret; 218 | } 219 | 220 | /** 221 | * [private] get balance 222 | * 223 | * @return mixed 224 | * 225 | * @throws PhitFlyerClientExceptionInterface 226 | */ 227 | public function meGetBalance() 228 | { 229 | $this->logger->debug('started meGetBalance'); 230 | $ret = $this->client->meGetBalance(); 231 | $this->logger->debug('finished meGetBalance'); 232 | return $ret; 233 | } 234 | 235 | /** 236 | * [private] get collateral 237 | * 238 | * @return mixed 239 | * 240 | * @throws PhitFlyerClientExceptionInterface 241 | */ 242 | public function meGetCollateral() 243 | { 244 | $this->logger->debug('started meGetCollateral'); 245 | $ret = $this->client->meGetCollateral(); 246 | $this->logger->debug('finished meGetCollateral'); 247 | return $ret; 248 | } 249 | 250 | /** 251 | * [private] get collateral accounts 252 | * 253 | * @return mixed 254 | * 255 | * @throws PhitFlyerClientExceptionInterface 256 | */ 257 | public function meGetCollateralAccounts() 258 | { 259 | $this->logger->debug('started meGetCollateralAccounts'); 260 | $ret = $this->client->meGetCollateralAccounts(); 261 | $this->logger->debug('finished meGetCollateralAccounts'); 262 | return $ret; 263 | } 264 | 265 | /** 266 | * [private] get address 267 | * 268 | * @return mixed 269 | * 270 | * @throws PhitFlyerClientExceptionInterface 271 | */ 272 | public function meGetAddress() 273 | { 274 | $this->logger->debug('started meGetAddress'); 275 | $ret = $this->client->meGetAddress(); 276 | $this->logger->debug('finished meGetAddress'); 277 | return $ret; 278 | } 279 | 280 | /** 281 | * [private] get coin ins 282 | * 283 | * @param integer $before 284 | * @param integer $after 285 | * @param integer $count 286 | * 287 | * @return mixed 288 | * 289 | * @throws PhitFlyerClientExceptionInterface 290 | */ 291 | public function meGetCoinIns($before = null, $after = null, $count = null) 292 | { 293 | $this->logger->debug('started meGetCoinIns'); 294 | $ret = $this->client->meGetCoinIns($before, $after, $count); 295 | $this->logger->debug('finished meGetCoinIns'); 296 | return $ret; 297 | } 298 | 299 | /** 300 | * [private] get coin outs 301 | * 302 | * @param integer $before 303 | * @param integer $after 304 | * @param integer $count 305 | * 306 | * @return mixed 307 | * 308 | * @throws PhitFlyerClientExceptionInterface 309 | */ 310 | public function meGetCoinOuts($before = null, $after = null, $count = null) 311 | { 312 | $this->logger->debug('started meGetCoinOuts'); 313 | $ret = $this->client->meGetCoinOuts($before, $after, $count); 314 | $this->logger->debug('finished meGetCoinOuts'); 315 | return $ret; 316 | } 317 | 318 | /** 319 | * [private] get bank accounts 320 | * 321 | * @return mixed 322 | * 323 | * @throws PhitFlyerClientExceptionInterface 324 | */ 325 | public function meGetBankAccounts() 326 | { 327 | $this->logger->debug('started meGetBankAccounts'); 328 | $ret = $this->client->meGetBankAccounts(); 329 | $this->logger->debug('finished meGetBankAccounts'); 330 | return $ret; 331 | } 332 | 333 | /** 334 | * [private] get deposits 335 | * 336 | * @param integer $before 337 | * @param integer $after 338 | * @param integer $count 339 | * 340 | * @return mixed 341 | * 342 | * @throws PhitFlyerClientExceptionInterface 343 | */ 344 | public function meGetDeposits($before = null, $after = null, $count = null) 345 | { 346 | $this->logger->debug('started meGetDeposits'); 347 | $ret = $this->client->meGetDeposits($before, $after, $count); 348 | $this->logger->debug('finished meGetDeposits'); 349 | return $ret; 350 | } 351 | 352 | /** 353 | * [private] send child order 354 | * 355 | * @param string $product_code 356 | * @param string $child_order_type 357 | * @param string $side 358 | * @param int $price 359 | * @param float $size 360 | * @param int|null $minute_to_expire 361 | * @param string|null $time_in_force 362 | * 363 | * @return mixed 364 | * @throws PhitFlyerClientExceptionInterface 365 | */ 366 | public function meSendChildOrder(string $product_code, string $child_order_type, string $side, int $price, float $size, 367 | int $minute_to_expire = null, string $time_in_force = null) 368 | { 369 | $this->logger->debug('started meSendChildOrder'); 370 | $ret = $this->client->meSendChildOrder($product_code, $child_order_type, $side, $price, $size, $minute_to_expire, $time_in_force); 371 | $this->logger->debug('finished meSendChildOrder'); 372 | return $ret; 373 | } 374 | 375 | /** 376 | * [private] cancel child order 377 | * 378 | * @param string $product_code 379 | * @param string $child_order_id 380 | * 381 | * @throws PhitFlyerClientExceptionInterface 382 | */ 383 | public function meCancelChildOrder(string $product_code, string $child_order_id) 384 | { 385 | $this->logger->debug('started meCancelChildOrder'); 386 | $this->client->meCancelChildOrder($product_code, $child_order_id); 387 | $this->logger->debug('finished meCancelChildOrder'); 388 | } 389 | 390 | /** 391 | * [private] cancel all child orders 392 | * 393 | * @param string $product_code 394 | * 395 | * @throws PhitFlyerClientExceptionInterface 396 | */ 397 | public function meCancelAllChildOrders(string $product_code) 398 | { 399 | $this->logger->debug('started meCancelAllChildOrders'); 400 | $this->client->meCancelAllChildOrders($product_code); 401 | $this->logger->debug('finished meCancelAllChildOrders'); 402 | } 403 | 404 | /** 405 | * [private] get child orders 406 | * 407 | * @param string $product_code 408 | * @param int|null $before 409 | * @param int|null $after 410 | * @param int|null $count 411 | * @param string|null $child_order_state 412 | * @param string|null $parent_order_id 413 | * 414 | * @return mixed 415 | * @throws PhitFlyerClientExceptionInterface 416 | */ 417 | public function meGetChildOrders(string $product_code, int $before = null, int $after = null, int $count = null, 418 | string $child_order_state = null, string $parent_order_id = null) 419 | { 420 | $this->logger->debug('started meGetChildOrders'); 421 | $ret = $this->client->meGetChildOrders($product_code, $before, $after, $count, $child_order_state, $parent_order_id); 422 | $this->logger->debug('finished meGetChildOrders'); 423 | return $ret; 424 | } 425 | 426 | /** 427 | * [private] get executions 428 | * 429 | * @param string $product_code 430 | * @param int|null $before 431 | * @param int|null $after 432 | * @param int|null $count 433 | * @param string|null $child_order_id 434 | * @param string|null $child_order_acceptance_id 435 | * 436 | * @return mixed 437 | * @throws PhitFlyerClientExceptionInterface 438 | */ 439 | public function meGetExecutions(string $product_code, int $before = null, int $after = null, int $count = null, 440 | string $child_order_id = null, string $child_order_acceptance_id = null) 441 | { 442 | $this->logger->debug('started meGetExecutions'); 443 | $ret = $this->client->meGetExecutions($product_code, $before, $after, $count, $child_order_id, $child_order_acceptance_id); 444 | $this->logger->debug('finished meGetExecutions'); 445 | return $ret; 446 | } 447 | 448 | /** 449 | * [private] get positions 450 | * 451 | * @param string $product_code 452 | * 453 | * @return mixed 454 | * @throws PhitFlyerClientExceptionInterface 455 | */ 456 | public function meGetPositions(string $product_code) 457 | { 458 | $this->logger->debug('started meGetPositions'); 459 | $ret = $this->client->meGetPositions($product_code); 460 | $this->logger->debug('finished meGetPositions'); 461 | return $ret; 462 | } 463 | 464 | /** 465 | * [private] get trading commission 466 | * 467 | * @param string $product_code 468 | * 469 | * @return mixed 470 | * @throws PhitFlyerClientExceptionInterface 471 | */ 472 | public function meGetTradingCommission(string $product_code) 473 | { 474 | $this->logger->debug('started meGetTradingCommission'); 475 | $ret = $this->client->meGetTradingCommission($product_code); 476 | $this->logger->debug('finished meGetTradingCommission'); 477 | return $ret; 478 | } 479 | } -------------------------------------------------------------------------------- /src/PhitFlyerObjectClient.php: -------------------------------------------------------------------------------- 1 | client = $flyer; 46 | } 47 | 48 | /** 49 | * get last request 50 | * 51 | * @return HttpRequest 52 | */ 53 | public function getLastRequest() : HttpRequest 54 | { 55 | return $this->client->getLastRequest(); 56 | } 57 | 58 | /** 59 | * add net driver change listener 60 | * 61 | * @param NetDriverChangeListenerInterface|callable $listener 62 | */ 63 | public function addNetDriverChangeListener($listener) 64 | { 65 | $this->client->addNetDriverChangeListener($listener); 66 | } 67 | 68 | /** 69 | * get net driver 70 | * 71 | * @return NetDriverInterface 72 | */ 73 | public function getNetDriver() : NetDriverInterface 74 | { 75 | return $this->client->getNetDriver(); 76 | } 77 | 78 | /** 79 | * set net driver 80 | * 81 | * @param NetDriverInterface $net_driver 82 | */ 83 | public function setNetDriver(NetDriverInterface $net_driver) 84 | { 85 | $this->client->setNetDriver($net_driver); 86 | } 87 | 88 | /** 89 | * [public] get markets 90 | * 91 | * @return Market[] 92 | * 93 | * @throws PhitFlyerClientExceptionInterface 94 | */ 95 | public function getMarkets() : array 96 | { 97 | // get result from server 98 | $json = $this->client->getMarkets(); 99 | // make market list 100 | $items = []; 101 | foreach ($json as $item){ 102 | $items[] = Market::fromArray($item); 103 | } 104 | return $items; 105 | } 106 | 107 | /** 108 | * [public] get boards 109 | * 110 | * @param string $product_code 111 | * 112 | * @return Board 113 | * 114 | * @throws PhitFlyerClientExceptionInterface 115 | */ 116 | public function getBoard($product_code = null) : Board 117 | { 118 | // get result from server 119 | $json = $this->client->getBoard($product_code); 120 | // make board 121 | return Board::fromArray($json); 122 | } 123 | 124 | /** 125 | * [public] get ticker 126 | * 127 | * @param string $product_code 128 | * 129 | * @return Ticker 130 | * 131 | * @throws PhitFlyerClientExceptionInterface 132 | */ 133 | public function getTicker($product_code = null) : Ticker 134 | { 135 | // get result from server 136 | $json = $this->client->getTicker($product_code); 137 | // make ticker 138 | return Ticker::fromArray($json); 139 | } 140 | 141 | /** 142 | * [public] get executions 143 | * 144 | * @param string $product_code 145 | * @param integer $before 146 | * @param integer $after 147 | * @param integer $count 148 | * 149 | * @return Execution[] 150 | * 151 | * @throws PhitFlyerClientExceptionInterface 152 | */ 153 | public function getExecutions($product_code = null, $before = null, $after = null, $count = null) : array 154 | { 155 | // get result from server 156 | $json = $this->client->getExecutions($product_code, $before, $after, $count); 157 | // make execution list 158 | $items = array(); 159 | foreach ($json as $item){ 160 | $items[] = Execution::fromArray($item); 161 | } 162 | return $items; 163 | } 164 | 165 | /** 166 | * [public] get board state 167 | * 168 | * @param string $product_code 169 | * 170 | * @return BoardState 171 | * 172 | * @throws PhitFlyerClientExceptionInterface 173 | */ 174 | public function getBoardState($product_code = null) : BoardState 175 | { 176 | // get result from server 177 | $json = $this->client->getBoardState($product_code); 178 | // make board state 179 | return BoardState::fromArray($json); 180 | } 181 | 182 | /** 183 | * [public] get health 184 | * 185 | * @return Health 186 | * 187 | * @throws PhitFlyerClientExceptionInterface 188 | */ 189 | public function getHealth() : Health 190 | { 191 | // get result from server 192 | $json = $this->client->getHealth(); 193 | // make health 194 | return Health::fromArray($json); 195 | } 196 | 197 | /** 198 | * [public] get chats 199 | * 200 | * @param string $from_date 201 | * 202 | * @return Chat[] 203 | * 204 | * @throws PhitFlyerClientExceptionInterface 205 | */ 206 | public function getChats($from_date = null) : array 207 | { 208 | // get result from server 209 | $json = $this->client->getChats($from_date); 210 | // make chat list 211 | $items = array(); 212 | foreach ($json as $item){ 213 | $items[] = Chat::fromArray($item); 214 | } 215 | return $items; 216 | } 217 | 218 | /** 219 | * [private] get permissions 220 | * 221 | * @return string[] 222 | * 223 | * @throws PhitFlyerClientExceptionInterface 224 | */ 225 | public function meGetPermissions() : array 226 | { 227 | // get result from server 228 | return $this->client->meGetPermissions(); 229 | } 230 | 231 | /** 232 | * [private] get balance 233 | * 234 | * @return MeBalance[] 235 | * 236 | * @throws PhitFlyerClientExceptionInterface 237 | */ 238 | public function meGetBalance() : array 239 | { 240 | // get result from server 241 | $json = $this->client->meGetBalance(); 242 | // make balances list 243 | $items = array(); 244 | foreach ($json as $item){ 245 | $items[] = MeBalance::fromArray($item); 246 | } 247 | return $items; 248 | } 249 | 250 | /** 251 | * [private] get collateral 252 | * 253 | * @return MeCollateral 254 | * 255 | * @throws PhitFlyerClientExceptionInterface 256 | */ 257 | public function meGetCollateral() : MeCollateral 258 | { 259 | // get result from server 260 | $json = $this->client->meGetCollateral(); 261 | // make collateral 262 | return MeCollateral::fromArray($json); 263 | } 264 | 265 | /** 266 | * [private] get collateral accounts 267 | * 268 | * @return MeCollateralAccount[] 269 | * 270 | * @throws PhitFlyerClientExceptionInterface 271 | */ 272 | public function meGetCollateralAccounts() : array 273 | { 274 | // get result from server 275 | $json = $this->client->meGetCollateralAccounts(); 276 | // make collateral account list 277 | $items = array(); 278 | foreach ($json as $item){ 279 | $items[] = MeCollateralAccount::fromArray($item); 280 | } 281 | return $items; 282 | } 283 | 284 | /** 285 | * [private] get address 286 | * 287 | * @return MeAddress[] 288 | * 289 | * @throws PhitFlyerClientExceptionInterface 290 | */ 291 | public function meGetAddress() : array 292 | { 293 | // get result from server 294 | $json = $this->client->meGetAddress(); 295 | // make address list 296 | $items = array(); 297 | foreach ($json as $item){ 298 | $items[] = MeAddress::fromArray($item); 299 | } 300 | return $items; 301 | } 302 | 303 | /** 304 | * [private] get coin ins 305 | * 306 | * @param integer $before 307 | * @param integer $after 308 | * @param integer $count 309 | * 310 | * @return MeCoinIn[] 311 | * 312 | * @throws PhitFlyerClientExceptionInterface 313 | */ 314 | public function meGetCoinIns($before = null, $after = null, $count = null) : array 315 | { 316 | // get result from server 317 | $json = $this->client->meGetCoinIns($before, $after, $count); 318 | // make coin in list 319 | $items = array(); 320 | foreach ($json as $item){ 321 | $items[] = MeCoinIn::fromArray($item); 322 | } 323 | return $items; 324 | } 325 | 326 | /** 327 | * [private] get coin outs 328 | * 329 | * @param integer $before 330 | * @param integer $after 331 | * @param integer $count 332 | * 333 | * @return MeCoinOut[] 334 | * 335 | * @throws PhitFlyerClientExceptionInterface 336 | */ 337 | public function meGetCoinOuts($before = null, $after = null, $count = null) : array 338 | { 339 | // get result from server 340 | $json = $this->client->meGetCoinOuts($before, $after, $count); 341 | // make coin out list 342 | $items = array(); 343 | foreach ($json as $item){ 344 | $items[] = MeCoinOut::fromArray($item); 345 | } 346 | return $items; 347 | } 348 | 349 | /** 350 | * [private] get bank accounts 351 | * 352 | * @return MeBankAccount[] 353 | * 354 | * @throws PhitFlyerClientExceptionInterface 355 | */ 356 | public function meGetBankAccounts() : array 357 | { 358 | // get result from server 359 | $json = $this->client->meGetBankAccounts(); 360 | // make bank account list 361 | $items = array(); 362 | foreach ($json as $item){ 363 | $items[] = MeBankAccount::fromArray($item); 364 | } 365 | return $items; 366 | } 367 | 368 | /** 369 | * [private] get deposits 370 | * 371 | * @param integer $before 372 | * @param integer $after 373 | * @param integer $count 374 | * 375 | * @return MeDeposit[] 376 | * 377 | * @throws PhitFlyerClientExceptionInterface 378 | */ 379 | public function meGetDeposits($before = null, $after = null, $count = null) : array 380 | { 381 | // get result from server 382 | $json = $this->client->meGetDeposits($before, $after, $count); 383 | // make deposit list 384 | $items = array(); 385 | foreach ($json as $item){ 386 | $items[] = MeDeposit::fromArray($item); 387 | } 388 | return $items; 389 | } 390 | 391 | /** 392 | * [private] send child order 393 | * 394 | * @param string $product_code 395 | * @param string $child_order_type 396 | * @param string $side 397 | * @param int $price 398 | * @param float $size 399 | * @param int|null $minute_to_expire 400 | * @param string|null $time_in_force 401 | * 402 | * @return MeChildOrderResult 403 | * 404 | * @throws PhitFlyerClientExceptionInterface 405 | */ 406 | public function meSendChildOrder(string $product_code, string $child_order_type, string $side, int $price, float $size, 407 | int $minute_to_expire = null, string $time_in_force = null) : MeChildOrderResult 408 | { 409 | // get result from server 410 | $json = $this->client->meSendChildOrder($product_code, $child_order_type, $side, $price, $size, $minute_to_expire, $time_in_force); 411 | // make message 412 | return MeChildOrderResult::fromArray($json); 413 | } 414 | 415 | /** 416 | * [private] cancel child order 417 | * 418 | * @param string $product_code 419 | * @param string $child_order_id 420 | * 421 | * @throws PhitFlyerClientExceptionInterface 422 | */ 423 | public function meCancelChildOrder(string $product_code, string $child_order_id) 424 | { 425 | // get result from server 426 | $this->client->meCancelChildOrder($product_code, $child_order_id); 427 | } 428 | 429 | /** 430 | * [private] cancel all child orders 431 | * 432 | * @param string $product_code 433 | * 434 | * @throws PhitFlyerClientExceptionInterface 435 | */ 436 | public function meCancelAllChildOrders(string $product_code) 437 | { 438 | // get result from server 439 | $this->client->meCancelAllChildOrders($product_code); 440 | } 441 | 442 | /** 443 | * [private] get child orders 444 | * 445 | * @param string $product_code 446 | * @param int|null $before 447 | * @param int|null $after 448 | * @param int|null $count 449 | * @param string|null $child_order_state 450 | * @param string|null $parent_order_id 451 | * 452 | * @return MeChildOrder[] 453 | * 454 | * @throws PhitFlyerClientExceptionInterface 455 | */ 456 | public function meGetChildOrders(string $product_code, int $before = null, int $after = null, int $count = null, 457 | string $child_order_state = null, string $parent_order_id = null) : array 458 | { 459 | // get result from server 460 | $json = $this->client->meGetChildOrders($product_code, $before, $after, $count, $child_order_state, $parent_order_id); 461 | // make child order list 462 | $items = array(); 463 | foreach ($json as $item){ 464 | $items[] = MeChildOrder::fromArray($item); 465 | } 466 | return $items; 467 | } 468 | 469 | /** 470 | * [private] get executions 471 | * 472 | * @param string $product_code 473 | * @param int|null $before 474 | * @param int|null $after 475 | * @param int|null $count 476 | * @param string|null $child_order_id 477 | * @param string|null $child_order_acceptance_id 478 | * 479 | * @return MeExecution[] 480 | * 481 | * @throws PhitFlyerClientExceptionInterface 482 | */ 483 | public function meGetExecutions(string $product_code, int $before = null, int $after = null, int $count = null, 484 | string $child_order_id = null, string $child_order_acceptance_id = null) : array 485 | { 486 | // get result from server 487 | $json = $this->client->meGetExecutions($product_code, $before, $after, $count, $child_order_id, $child_order_acceptance_id); 488 | // make child order list 489 | $items = array(); 490 | foreach ($json as $item){ 491 | $items[] = MeExecution::fromArray($item); 492 | } 493 | return $items; 494 | } 495 | 496 | /** 497 | * [private] get positions 498 | * 499 | * @param string $product_code 500 | * 501 | * @return MePosition[] 502 | * 503 | * @throws PhitFlyerClientExceptionInterface 504 | */ 505 | public function meGetPositions(string $product_code) : array 506 | { 507 | // get result from server 508 | $json = $this->client->meGetPositions($product_code); 509 | // make child order list 510 | $items = array(); 511 | foreach ($json as $item){ 512 | $items[] = MePosition::fromArray($item); 513 | } 514 | return $items; 515 | } 516 | 517 | /** 518 | * [private] get trading commission 519 | * 520 | * @param string $product_code 521 | * 522 | * @return MeCommission 523 | * 524 | * @throws PhitFlyerClientExceptionInterface 525 | */ 526 | public function meGetTradingCommission(string $product_code) : MeCommission 527 | { 528 | // get result from server 529 | $json = $this->client->meGetTradingCommission($product_code); 530 | // make comission 531 | return MeCommission::fromArray($json); 532 | } 533 | } -------------------------------------------------------------------------------- /src/PhitFlyerBenchmarkClient.php: -------------------------------------------------------------------------------- 1 | client = $flyer; 32 | $this->callback = $callback; 33 | } 34 | 35 | /** 36 | * get last request 37 | * 38 | * @return HttpRequest|null 39 | */ 40 | public function getLastRequest() : ?HttpRequest 41 | { 42 | return $this->client->getLastRequest(); 43 | } 44 | 45 | /** 46 | * add net driver change listener 47 | * 48 | * @param NetDriverChangeListenerInterface|callable $listener 49 | */ 50 | public function addNetDriverChangeListener($listener) 51 | { 52 | $this->client->addNetDriverChangeListener($listener); 53 | } 54 | 55 | /** 56 | * get net driver 57 | * 58 | * @return NetDriverInterface|null 59 | */ 60 | public function getNetDriver() : ?NetDriverInterface 61 | { 62 | return $this->client->getNetDriver(); 63 | } 64 | 65 | /** 66 | * set net driver 67 | * 68 | * @param NetDriverInterface $net_driver 69 | */ 70 | public function setNetDriver(NetDriverInterface $net_driver) 71 | { 72 | $this->client->setNetDriver($net_driver); 73 | } 74 | 75 | /** 76 | * execute benchmark with result 77 | * 78 | * @param callable $bench_func 79 | * @param array|null $args 80 | * @param int $precision 81 | * 82 | * @return array 83 | */ 84 | private static function bench(callable $bench_func, array $args = null, int $precision = 4) : array 85 | { 86 | $start = microtime(true); 87 | if ($args){ 88 | $result = call_user_func_array($bench_func, $args); 89 | } 90 | else{ 91 | $result = call_user_func($bench_func); 92 | } 93 | $end = microtime(true); 94 | $elapsed = round($end - $start, $precision); 95 | return [$result, $elapsed]; 96 | } 97 | 98 | /** 99 | * execute benchmark with no result 100 | * 101 | * @param callable $bench_func 102 | * @param array|null $args 103 | * @param int $precision 104 | * 105 | * @return float 106 | */ 107 | private static function benchNoResult(callable $bench_func, array $args = null, $precision = 4) : float 108 | { 109 | $start = microtime(true); 110 | if ($args){ 111 | call_user_func_array($bench_func, $args); 112 | } 113 | else{ 114 | call_user_func($bench_func); 115 | } 116 | $end = microtime(true); 117 | return round($end - $start, $precision); 118 | } 119 | 120 | /** 121 | * [public] get markets 122 | * 123 | * @return mixed 124 | */ 125 | public function getMarkets() 126 | { 127 | $bench_func = array( $this->client, 'getMarkets' ); 128 | list($result, $elapsed) = self::bench($bench_func); 129 | call_user_func_array($this->callback, array('getMarkets', $elapsed)); 130 | return $result; 131 | } 132 | 133 | /** 134 | * [public] get boards 135 | * 136 | * @param string|null $product_code 137 | * 138 | * @return mixed 139 | */ 140 | public function getBoard(string $product_code = null) 141 | { 142 | $bench_func = array( $this->client, 'getBoard' ); 143 | $args = array( $product_code ); 144 | list($result, $elapsed) = self::bench($bench_func, $args); 145 | call_user_func_array($this->callback, array('getBoard', $elapsed)); 146 | return $result; 147 | } 148 | 149 | /** 150 | * [public] get ticker 151 | * 152 | * @param string|null $product_code 153 | * 154 | * @return mixed 155 | */ 156 | public function getTicker(string $product_code = null) 157 | { 158 | $bench_func = array( $this->client, 'getTicker' ); 159 | $args = array( $product_code ); 160 | list($result, $elapsed) = self::bench($bench_func, $args); 161 | call_user_func_array($this->callback, array('getTicker', $elapsed)); 162 | return $result; 163 | } 164 | 165 | /** 166 | * [public] get executions 167 | * 168 | * @param string|null $product_code 169 | * @param int|null $before 170 | * @param int|null $after 171 | * @param int|null $count 172 | * 173 | * @return mixed 174 | */ 175 | public function getExecutions(string $product_code = null, int $before = null, int $after = null, int $count = null) 176 | { 177 | $bench_func = array( $this->client, 'getExecutions' ); 178 | $args = array( $product_code, $before, $after, $count ); 179 | list($result, $elapsed) = self::bench($bench_func, $args); 180 | call_user_func_array($this->callback, array('getExecutions', $elapsed)); 181 | return $result; 182 | } 183 | 184 | /** 185 | * [public] get board state 186 | * 187 | * @param string|null $product_code 188 | * 189 | * @return mixed 190 | */ 191 | public function getBoardState(string $product_code = null) 192 | { 193 | $bench_func = array( $this->client, 'getBoardState' ); 194 | $args = array( $product_code ); 195 | list($result, $elapsed) = self::bench($bench_func, $args); 196 | call_user_func_array($this->callback, array('getBoardState', $elapsed)); 197 | return $result; 198 | } 199 | 200 | /** 201 | * [public] get health 202 | * 203 | * @return mixed 204 | */ 205 | public function getHealth() 206 | { 207 | $bench_func = array( $this->client, 'getHealth' ); 208 | list($result, $elapsed) = self::bench($bench_func); 209 | call_user_func_array($this->callback, array('getHealth', $elapsed)); 210 | return $result; 211 | } 212 | 213 | /** 214 | * [public] get chats 215 | * 216 | * @param string|null $from_date 217 | * 218 | * @return mixed 219 | */ 220 | public function getChats(string $from_date = null) 221 | { 222 | $bench_func = array( $this->client, 'getChats' ); 223 | $args = array( $from_date ); 224 | list($result, $elapsed) = self::bench($bench_func, $args); 225 | call_user_func_array($this->callback, array('getChats', $elapsed)); 226 | return $result; 227 | } 228 | 229 | /** 230 | * [private] get permissions 231 | * 232 | * @return mixed 233 | */ 234 | public function meGetPermissions() 235 | { 236 | $bench_func = array( $this->client, 'meGetPermissions' ); 237 | list($result, $elapsed) = self::bench($bench_func); 238 | call_user_func_array($this->callback, array('meGetPermissions', $elapsed)); 239 | return $result; 240 | } 241 | 242 | /** 243 | * [private] get balance 244 | * 245 | * @return mixed 246 | */ 247 | public function meGetBalance() 248 | { 249 | $bench_func = array( $this->client, 'meGetBalance' ); 250 | list($result, $elapsed) = self::bench($bench_func); 251 | call_user_func_array($this->callback, array('meGetBalance', $elapsed)); 252 | return $result; 253 | } 254 | 255 | /** 256 | * [private] get collateral 257 | * 258 | * @return mixed 259 | */ 260 | public function meGetCollateral() 261 | { 262 | $bench_func = array( $this->client, 'meGetCollateral' ); 263 | list($result, $elapsed) = self::bench($bench_func); 264 | call_user_func_array($this->callback, array('meGetCollateral', $elapsed)); 265 | return $result; 266 | } 267 | 268 | /** 269 | * [private] get collateral accounts 270 | * 271 | * @return mixed 272 | */ 273 | public function meGetCollateralAccounts() 274 | { 275 | $bench_func = array( $this->client, 'meGetCollateralAccounts' ); 276 | list($result, $elapsed) = self::bench($bench_func); 277 | call_user_func_array($this->callback, array('meGetCollateralAccounts', $elapsed)); 278 | return $result; 279 | } 280 | 281 | /** 282 | * [private] get address 283 | * 284 | * @return mixed 285 | */ 286 | public function meGetAddress() 287 | { 288 | $bench_func = array( $this->client, 'meGetAddress' ); 289 | list($result, $elapsed) = self::bench($bench_func); 290 | call_user_func_array($this->callback, array('meGetAddress', $elapsed)); 291 | return $result; 292 | } 293 | 294 | /** 295 | * [private] get coin ins 296 | * 297 | * @param int|null $before 298 | * @param int|null $after 299 | * @param int|null $count 300 | * 301 | * @return mixed 302 | */ 303 | public function meGetCoinIns(int $before = null, int $after = null, int $count = null) 304 | { 305 | $bench_func = array( $this->client, 'meGetCoinIns' ); 306 | $args = array( $before, $after, $count ); 307 | list($result, $elapsed) = self::bench($bench_func, $args); 308 | call_user_func_array($this->callback, array('meGetCoinIns', $elapsed)); 309 | return $result; 310 | } 311 | 312 | /** 313 | * [private] get coin outs 314 | * 315 | * @param int|null $before 316 | * @param int|null $after 317 | * @param int|null $count 318 | * 319 | * @return mixed 320 | */ 321 | public function meGetCoinOuts(int $before = null, int $after = null, int $count = null) 322 | { 323 | $bench_func = array( $this->client, 'meGetCoinOuts' ); 324 | $args = array( $before, $after, $count ); 325 | list($result, $elapsed) = self::bench($bench_func, $args); 326 | call_user_func_array($this->callback, array('meGetCoinOuts', $elapsed)); 327 | return $result; 328 | } 329 | 330 | /** 331 | * [private] get bank accounts 332 | * 333 | * @return mixed 334 | */ 335 | public function meGetBankAccounts() 336 | { 337 | $bench_func = array( $this->client, 'meGetBankAccounts' ); 338 | list($result, $elapsed) = self::bench($bench_func); 339 | call_user_func_array($this->callback, array('meGetBankAccounts', $elapsed)); 340 | return $result; 341 | } 342 | 343 | /** 344 | * [private] get deposits 345 | * 346 | * @param int|null $before 347 | * @param int|null $after 348 | * @param int|null $count 349 | * 350 | * @return mixed 351 | */ 352 | public function meGetDeposits(int $before = null, int $after = null, int $count = null) 353 | { 354 | $bench_func = array( $this->client, 'meGetDeposits' ); 355 | $args = array( $before, $after, $count ); 356 | list($result, $elapsed) = self::bench($bench_func, $args); 357 | call_user_func_array($this->callback, array('meGetDeposits', $elapsed)); 358 | return $result; 359 | } 360 | 361 | /** 362 | * [private] withdraw 363 | * 364 | * @param string $currency_code 365 | * @param int $bank_account_id 366 | * @param int $amount 367 | * @param string|null $code 368 | * 369 | * @return mixed 370 | * @noinspection PhpUnused 371 | */ 372 | public function meWithdraw(string $currency_code, int $bank_account_id, int $amount, string $code = null) 373 | { 374 | $bench_func = array( $this->client, 'meWithdraw' ); 375 | $args = array( $currency_code, $bank_account_id, $amount, $code ); 376 | list($result, $elapsed) = self::bench($bench_func, $args); 377 | call_user_func_array($this->callback, array('meWithdraw', $elapsed)); 378 | return $result; 379 | } 380 | 381 | /** 382 | * [private] send child order 383 | * 384 | * @param string $product_code 385 | * @param string $child_order_type 386 | * @param string $side 387 | * @param int $price 388 | * @param float $size 389 | * @param int|null $minute_to_expire 390 | * @param string|null $time_in_force 391 | * 392 | * @return mixed 393 | */ 394 | public function meSendChildOrder(string $product_code, string $child_order_type, string $side, int $price, float $size, 395 | int $minute_to_expire = null, string $time_in_force = null) 396 | { 397 | $bench_func = array( $this->client, 'meSendChildOrder' ); 398 | $args = array( $product_code, $child_order_type, $side, $price, $size, $minute_to_expire, $time_in_force ); 399 | list($result, $elapsed) = self::bench($bench_func, $args); 400 | call_user_func_array($this->callback, array('meSendChildOrder', $elapsed)); 401 | return $result; 402 | } 403 | 404 | /** 405 | * [private] cancel child order 406 | * 407 | * @param string $product_code 408 | * @param string $child_order_id 409 | */ 410 | public function meCancelChildOrder(string $product_code, string $child_order_id) 411 | { 412 | $bench_func = array( $this->client, 'meCancelChildOrder' ); 413 | $args = array( $product_code, $child_order_id ); 414 | $elapsed = self::benchNoResult($bench_func, $args); 415 | call_user_func_array($this->callback, array('meCancelChildOrder', $elapsed)); 416 | } 417 | 418 | /** 419 | * [private] cancel all child orders 420 | * 421 | * @param string $product_code 422 | */ 423 | public function meCancelAllChildOrders(string $product_code) 424 | { 425 | $bench_func = array( $this->client, 'meCancelAllChildOrders' ); 426 | $args = array( $product_code, ); 427 | $elapsed = self::benchNoResult($bench_func, $args); 428 | call_user_func_array($this->callback, array('meCancelAllChildOrders', $elapsed)); 429 | } 430 | 431 | /** 432 | * [private] get child orders 433 | * 434 | * @param string $product_code 435 | * @param int|null $before 436 | * @param int|null $after 437 | * @param int|null $count 438 | * @param string|null $child_order_state 439 | * @param string|null $parent_order_id 440 | * 441 | * @return mixed 442 | */ 443 | public function meGetChildOrders(string $product_code, int $before = null, int $after = null, int $count = null, 444 | string $child_order_state = null, string $parent_order_id = null) 445 | { 446 | $bench_func = array( $this->client, 'meGetChildOrders' ); 447 | $args = array( $product_code, $before, $after, $count, $child_order_state, $parent_order_id ); 448 | list($result, $elapsed) = self::bench($bench_func, $args); 449 | call_user_func_array($this->callback, array('meGetChildOrders', $elapsed)); 450 | return $result; 451 | } 452 | 453 | /** 454 | * [private] get executions 455 | * 456 | * @param string $product_code 457 | * @param int|null $before 458 | * @param int|null $after 459 | * @param int|null $count 460 | * @param string|null $child_order_id 461 | * @param string|null $child_order_acceptance_id 462 | * 463 | * @return mixed 464 | */ 465 | public function meGetExecutions(string $product_code, int $before = null, int $after = null, int $count = null, 466 | string $child_order_id = null, string $child_order_acceptance_id = null) 467 | { 468 | $bench_func = array( $this->client, 'meGetExecutions' ); 469 | $args = array( $product_code, $before, $after, $count, $child_order_id, $child_order_acceptance_id ); 470 | list($result, $elapsed) = self::bench($bench_func, $args); 471 | call_user_func_array($this->callback, array('meGetExecutions', $elapsed)); 472 | return $result; 473 | } 474 | 475 | /** 476 | * [private] get positions 477 | * 478 | * @param string $product_code 479 | * 480 | * @return mixed 481 | */ 482 | public function meGetPositions(string $product_code) 483 | { 484 | $bench_func = array( $this->client, 'meGetPositions' ); 485 | $args = array( $product_code ); 486 | list($result, $elapsed) = self::bench($bench_func, $args); 487 | call_user_func_array($this->callback, array('meGetPositions', $elapsed)); 488 | return $result; 489 | } 490 | 491 | /** 492 | * [private] get trading commission 493 | * 494 | * @param string $product_code 495 | * 496 | * @return mixed 497 | */ 498 | public function meGetTradingCommission(string $product_code) 499 | { 500 | $bench_func = array( $this->client, 'meGetTradingCommission' ); 501 | $args = array( $product_code ); 502 | list($result, $elapsed) = self::bench($bench_func, $args); 503 | call_user_func_array($this->callback, array('meGetTradingCommission', $elapsed)); 504 | return $result; 505 | } 506 | } -------------------------------------------------------------------------------- /test/PhitFlyerBenchmarkClientTest.php: -------------------------------------------------------------------------------- 1 | assertGreaterThan(0,strlen($api_key),'Plase set environment variable(PHITFLYER_API_KEY) before running this test.'); 22 | $this->assertGreaterThan(0,strlen($api_secret),'Plase set environment variable(PHITFLYER_API_SECRET) before running this test.'); 23 | 24 | $this->flyer = new PhitFlyerClient($api_key, $api_secret); 25 | 26 | sleep(1); 27 | } 28 | 29 | public function testGetMarkets() 30 | { 31 | $method = ''; 32 | $elapsed = 0; 33 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 34 | $method = $m; 35 | $elapsed = $e; 36 | }); 37 | 38 | $markets = $flyer->getMarkets(); 39 | 40 | $this->assertInternalType( 'array', $markets ); 41 | $this->assertGreaterThanOrEqual( 0, count($markets) ); 42 | $this->assertEquals( 'getMarkets', $method ); 43 | $this->assertInternalType( 'float', $elapsed ); 44 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 45 | } 46 | 47 | public function testGetBoard() 48 | { 49 | $method = ''; 50 | $elapsed = 0; 51 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 52 | $method = $m; 53 | $elapsed = $e; 54 | }); 55 | 56 | $board = $flyer->getBoard(); 57 | 58 | $this->assertInternalType('array', $board ); 59 | $this->assertEquals( 'getBoard', $method ); 60 | $this->assertInternalType( 'float', $elapsed ); 61 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 62 | } 63 | 64 | public function testGetBoardWithProductCode() 65 | { 66 | $method = ''; 67 | $elapsed = 0; 68 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 69 | $method = $m; 70 | $elapsed = $e; 71 | }); 72 | 73 | $board = $flyer->getBoard('BTC_JPY'); 74 | 75 | $this->assertInternalType('array', $board ); 76 | $this->assertEquals( 'getBoard', $method ); 77 | $this->assertInternalType( 'float', $elapsed ); 78 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 79 | } 80 | 81 | public function testTicker() 82 | { 83 | $method = ''; 84 | $elapsed = 0; 85 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 86 | $method = $m; 87 | $elapsed = $e; 88 | }); 89 | 90 | $ticker = $flyer->getTicker(); 91 | 92 | $this->assertInternalType('array', $ticker ); 93 | $this->assertEquals( 'getTicker', $method ); 94 | $this->assertInternalType( 'float', $elapsed ); 95 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 96 | } 97 | 98 | public function testGetTickerWithProductCode() 99 | { 100 | $method = ''; 101 | $elapsed = 0; 102 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 103 | $method = $m; 104 | $elapsed = $e; 105 | }); 106 | 107 | $ticker = $flyer->getTicker('BTC_JPY'); 108 | 109 | $this->assertInternalType('array', $ticker ); 110 | $this->assertEquals( 'getTicker', $method ); 111 | $this->assertInternalType( 'float', $elapsed ); 112 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 113 | } 114 | 115 | public function testGetExecutions() 116 | { 117 | $method = ''; 118 | $elapsed = 0; 119 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 120 | $method = $m; 121 | $elapsed = $e; 122 | }); 123 | 124 | $executions = $flyer->getExecutions(); 125 | 126 | $this->assertInternalType('array', $executions ); 127 | $this->assertEquals( 'getExecutions', $method ); 128 | $this->assertInternalType( 'float', $elapsed ); 129 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 130 | } 131 | 132 | public function testGetExecutionsWithProductCode() 133 | { 134 | $method = ''; 135 | $elapsed = 0; 136 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 137 | $method = $m; 138 | $elapsed = $e; 139 | }); 140 | 141 | $executions = $flyer->getExecutions('BTC_JPY'); 142 | 143 | $this->assertInternalType('array', $executions ); 144 | $this->assertEquals( 'getExecutions', $method ); 145 | $this->assertInternalType( 'float', $elapsed ); 146 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 147 | } 148 | 149 | public function testGetBoardState() 150 | { 151 | $method = ''; 152 | $elapsed = 0; 153 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 154 | $method = $m; 155 | $elapsed = $e; 156 | }); 157 | 158 | $board_state = $flyer->getBoardState('BTC_JPY'); 159 | 160 | $this->assertInternalType('array', $board_state ); 161 | $this->assertEquals( 'getBoardState', $method ); 162 | $this->assertInternalType( 'float', $elapsed ); 163 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 164 | } 165 | 166 | public function testGetHealth() 167 | { 168 | $method = ''; 169 | $elapsed = 0; 170 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 171 | $method = $m; 172 | $elapsed = $e; 173 | }); 174 | 175 | $health = $flyer->getHealth(); 176 | 177 | $this->assertInternalType('array', $health ); 178 | $this->assertEquals( 'getHealth', $method ); 179 | $this->assertInternalType( 'float', $elapsed ); 180 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 181 | } 182 | 183 | public function testGetChats() 184 | { 185 | $method = ''; 186 | $elapsed = 0; 187 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 188 | $method = $m; 189 | $elapsed = $e; 190 | }); 191 | 192 | $from_date = date('Y-m-d\Th:i:s', strtotime('-1 min')); 193 | $chats = $flyer->getChats($from_date); 194 | 195 | $this->assertInternalType('array', $chats ); 196 | $this->assertEquals( 'getChats', $method ); 197 | $this->assertInternalType( 'float', $elapsed ); 198 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 199 | } 200 | 201 | public function testMeGetPermissions() 202 | { 203 | $method = ''; 204 | $elapsed = 0; 205 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 206 | $method = $m; 207 | $elapsed = $e; 208 | }); 209 | 210 | $permissions = $flyer->meGetPermissions(); 211 | 212 | $this->assertInternalType('array', $permissions ); 213 | $this->assertEquals( 'meGetPermissions', $method ); 214 | $this->assertInternalType( 'float', $elapsed ); 215 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 216 | } 217 | 218 | public function testMeGetBalance() 219 | { 220 | $method = ''; 221 | $elapsed = 0; 222 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 223 | $method = $m; 224 | $elapsed = $e; 225 | }); 226 | 227 | $balances = $flyer->meGetBalance(); 228 | 229 | $this->assertInternalType('array', $balances ); 230 | $this->assertEquals( 'meGetBalance', $method ); 231 | $this->assertInternalType( 'float', $elapsed ); 232 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 233 | } 234 | 235 | public function testMeGetCollateral() 236 | { 237 | $method = ''; 238 | $elapsed = 0; 239 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 240 | $method = $m; 241 | $elapsed = $e; 242 | }); 243 | 244 | $collateral = $flyer->meGetCollateral(); 245 | 246 | $this->assertInternalType('array', $collateral ); 247 | $this->assertEquals( 'meGetCollateral', $method ); 248 | $this->assertInternalType( 'float', $elapsed ); 249 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 250 | } 251 | 252 | public function testMeGetCollateralAccounts() 253 | { 254 | $method = ''; 255 | $elapsed = 0; 256 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 257 | $method = $m; 258 | $elapsed = $e; 259 | }); 260 | 261 | $accounts = $flyer->meGetCollateralAccounts(); 262 | 263 | $this->assertInternalType('array', $accounts ); 264 | $this->assertEquals( 'meGetCollateralAccounts', $method ); 265 | $this->assertInternalType( 'float', $elapsed ); 266 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 267 | } 268 | 269 | public function testMeGetAddress() 270 | { 271 | $method = ''; 272 | $elapsed = 0; 273 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 274 | $method = $m; 275 | $elapsed = $e; 276 | }); 277 | 278 | $addresses = $flyer->meGetAddress(); 279 | 280 | $this->assertInternalType('array', $addresses ); 281 | $this->assertEquals( 'meGetAddress', $method ); 282 | $this->assertInternalType( 'float', $elapsed ); 283 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 284 | } 285 | 286 | public function testMeGetCoinIns() 287 | { 288 | $method = ''; 289 | $elapsed = 0; 290 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 291 | $method = $m; 292 | $elapsed = $e; 293 | }); 294 | 295 | $coinins = $flyer->meGetCoinIns(); 296 | 297 | $this->assertInternalType('array', $coinins ); 298 | $this->assertEquals( 'meGetCoinIns', $method ); 299 | $this->assertInternalType( 'float', $elapsed ); 300 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 301 | } 302 | 303 | public function testMeGetCoinOuts() 304 | { 305 | $method = ''; 306 | $elapsed = 0; 307 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 308 | $method = $m; 309 | $elapsed = $e; 310 | }); 311 | 312 | $coinouts = $flyer->meGetCoinOuts(); 313 | 314 | $this->assertInternalType('array', $coinouts ); 315 | $this->assertEquals( 'meGetCoinOuts', $method ); 316 | $this->assertInternalType( 'float', $elapsed ); 317 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 318 | } 319 | 320 | public function testMeGetBankAccounts() 321 | { 322 | $method = ''; 323 | $elapsed = 0; 324 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 325 | $method = $m; 326 | $elapsed = $e; 327 | }); 328 | 329 | $bank_accounts = $flyer->meGetBankAccounts(); 330 | 331 | $this->assertInternalType('array', $bank_accounts ); 332 | $this->assertEquals( 'meGetBankAccounts', $method ); 333 | $this->assertInternalType( 'float', $elapsed ); 334 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 335 | } 336 | 337 | public function testMeGetDeposits() 338 | { 339 | $method = ''; 340 | $elapsed = 0; 341 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 342 | $method = $m; 343 | $elapsed = $e; 344 | }); 345 | 346 | $deposits = $flyer->meGetDeposits(); 347 | 348 | $this->assertInternalType('array', $deposits ); 349 | $this->assertEquals( 'meGetDeposits', $method ); 350 | $this->assertInternalType( 'float', $elapsed ); 351 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 352 | } 353 | 354 | public function testMeSendChildOrder() 355 | { 356 | $this->assertTrue(true); 357 | 358 | /* 359 | $method = ''; 360 | $elapsed = 0; 361 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 362 | $method = $m; 363 | $elapsed = $e; 364 | }); 365 | 366 | $result = $flyer->meSendChildOrder( 367 | 'FX_BTC_JPY', 'LIMIT', 'SELL' ,300000, 0.1 368 | ); 369 | 370 | $this->assertInternalType('object', $result ); 371 | $this->assertEquals( 'meSendChildOrder', $method ); 372 | $this->assertInternalType( 'float', $elapsed ); 373 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 374 | */ 375 | } 376 | 377 | public function testMeCancelChildOrder() 378 | { 379 | $this->assertTrue(true); 380 | 381 | /* 382 | $method = ''; 383 | $elapsed = 0; 384 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 385 | $method = $m; 386 | $elapsed = $e; 387 | }); 388 | 389 | $flyer->meCancelChildOrder('FX_BTC_JPY', 'JFX20170717-214220-952616F'); 390 | 391 | $this->assertEquals( 'meCancelChildOrder', $method ); 392 | $this->assertInternalType( 'float', $elapsed ); 393 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 394 | */ 395 | } 396 | 397 | public function testMeCancelAllChildOrders() 398 | { 399 | $method = ''; 400 | $elapsed = 0; 401 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 402 | $method = $m; 403 | $elapsed = $e; 404 | }); 405 | 406 | $flyer->meCancelAllChildOrders('FX_BTC_JPY'); 407 | 408 | $this->assertEquals( 'meCancelAllChildOrders', $method ); 409 | $this->assertInternalType( 'float', $elapsed ); 410 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 411 | } 412 | 413 | public function testMeGetChildOrders() 414 | { 415 | $method = ''; 416 | $elapsed = 0; 417 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 418 | $method = $m; 419 | $elapsed = $e; 420 | }); 421 | 422 | $child_orders = $flyer->meGetChildOrders( 423 | 'FX_BTC_JPY', null, null, null, 'ACTIVE' 424 | ); 425 | 426 | $this->assertInternalType('array', $child_orders ); 427 | $this->assertEquals( 'meGetChildOrders', $method ); 428 | $this->assertInternalType( 'float', $elapsed ); 429 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 430 | } 431 | 432 | public function testMeGetExecutions() 433 | { 434 | $method = ''; 435 | $elapsed = 0; 436 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 437 | $method = $m; 438 | $elapsed = $e; 439 | }); 440 | 441 | $executions = $flyer->meGetExecutions( 'FX_BTC_JPY', null, null, 10 ); 442 | 443 | $this->assertInternalType('array', $executions ); 444 | $this->assertEquals( 'meGetExecutions', $method ); 445 | $this->assertInternalType( 'float', $elapsed ); 446 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 447 | } 448 | 449 | public function testMeGetPositions() 450 | { 451 | $method = ''; 452 | $elapsed = 0; 453 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 454 | $method = $m; 455 | $elapsed = $e; 456 | }); 457 | 458 | $positions = $flyer->meGetPositions('FX_BTC_JPY'); 459 | 460 | $this->assertInternalType('array', $positions ); 461 | $this->assertEquals( 'meGetPositions', $method ); 462 | $this->assertInternalType( 'float', $elapsed ); 463 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 464 | } 465 | 466 | public function testMeGetTradingCommission() 467 | { 468 | $method = ''; 469 | $elapsed = 0; 470 | $flyer = new PhitFlyerBenchmarkClient($this->flyer, function ($m, $e) use(&$method, &$elapsed){ 471 | $method = $m; 472 | $elapsed = $e; 473 | }); 474 | 475 | $commissions = $flyer->meGetTradingCommission('FX_BTC_JPY'); 476 | 477 | $this->assertInternalType('array', $commissions ); 478 | $this->assertEquals( 'meGetTradingCommission', $method ); 479 | $this->assertInternalType( 'float', $elapsed ); 480 | $this->assertGreaterThanOrEqual( 0, $elapsed ); 481 | } 482 | } --------------------------------------------------------------------------------