Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
Improvements by Chikashi-Kato and dmzoneill
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Mar 18, 2018
2 parents fa75d1a + e47f0d2 commit e2e54f6
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 37 deletions.
4 changes: 3 additions & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
src_dir: .
service_name: travis-ci
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
25 changes: 20 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,24 @@ php:
- 7.0

before_script:
- cd tests
- bash prep.sh

- mkdir -vp ~/.config/jaggedsoft/
- mkdir -vp build/logs
- COMPOSER=composer-test.json composer -vvv install --no-interaction --no-suggest
- wget -c -nc --retry-connrefused --tries=0 https://github.com/php-coveralls/php-coveralls/releases/download/v2.0.0/php-coveralls.phar -O coveralls.phar
- chmod +x coveralls.phar
- php coveralls.phar --version

script:
- mkdir -p build/logs
- bash run.sh
- ./vendor/bin/phpunit --verbose --debug --coverage-clover build/logs/clover.xml --bootstrap vendor/autoload.php php-binance-api-test

after_success:
- travis_retry php coveralls.phar -v
- bash <(curl -s https://codecov.io/bash)

branches:
only: master

cache:
directories:
- vendor
- $HOME/.cache/composer
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![GitHub last commit](https://img.shields.io/github/last-commit/jaggedsoft/php-binance-api.svg)](#)
[![Packagist Downloads](https://img.shields.io/packagist/dt/jaggedsoft/php-binance-api.svg)](https://packagist.org/packages/jaggedsoft/php-binance-api) [![Build Status](https://travis-ci.org/jaggedsoft/php-binance-api.svg?branch=master)](https://travis-ci.org/jaggedsoft/php-binance-api) [![Coverage Status](https://coveralls.io/repos/github/jaggedsoft/php-binance-api/badge.svg?branch=master)](https://coveralls.io/github/jaggedsoft/php-binance-api)
[![Packagist Downloads](https://img.shields.io/packagist/dt/jaggedsoft/php-binance-api.svg)](https://packagist.org/packages/jaggedsoft/php-binance-api) [![Build Status](https://travis-ci.org/jaggedsoft/php-binance-api.svg?branch=master)](https://travis-ci.org/jaggedsoft/php-binance-api) [![Coverage Status](https://coveralls.io/repos/github/jaggedsoft/php-binance-api/badge.svg?branch=master)](https://coveralls.io/github/jaggedsoft/php-binance-api) [![CodeCov](https://codecov.io/gh/jaggedsoft/php-binance-api/branch/master/graph/badge.svg)](https://codecov.io/github/jaggedsoft/php-binance-api/)

# PHP Binance API
This project is designed to help you make your own projects that interact with the [Binance API](https://github.com/binance-exchange/binance-official-api-docs). You can stream candlestick chart data, market depth, or use other advanced features such as setting stop losses and iceberg orders. This project seeks to have complete API coverage including WebSockets.
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion tests/BinanceTest.php → php-binance-api-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

declare(strict_types=1);

require '../php-binance-api.php';
require 'php-binance-api.php';

file_put_contents( getenv("HOME") . "/.config/jaggedsoft/php-binance-api.json" ,
"{ \"api-key\": \"z5RQZ9n8JcS3HLDQmPpfLQIGGQN6TTs5pCP5CTnn4nYk2ImFcew49v4ZrmP3MGl5\",
\"api-secret\": \"ZqePF1DcLb6Oa0CfcLWH0Tva59y8qBBIqu789JEY27jq0RkOKXpNl9992By1PN9Z\" }");

use PHPUnit\Framework\TestCase;

Expand Down
31 changes: 17 additions & 14 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ public function sell($symbol, $quantity, $price, $type = "LIMIT", $flags = []) {
public function sellTest($symbol, $quantity, $price, $type = "LIMIT", $flags = []) {
return $this->orderTest("SELL", $symbol, $quantity, $price, $type, $flags);
}
public function marketBuy($symbol, $quantity) {
return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags = []);
public function marketBuy($symbol, $quantity, $flags = []) {
return $this->order("BUY", $symbol, $quantity, 0, "MARKET", $flags);
}
public function marketBuyTest($symbol, $quantity) {
return $this->orderTest("BUY", $symbol, $quantity, 0, "MARKET", $flags = []);
public function marketBuyTest($symbol, $quantity, $flags = []) {
return $this->orderTest("BUY", $symbol, $quantity, 0, "MARKET", $flags);
}
public function marketSell($symbol, $quantity) {
return $this->order("SELL", $symbol, $quantity, 0, "MARKET", $flags = []);
public function marketSell($symbol, $quantity, $flags = []) {
return $this->order("SELL", $symbol, $quantity, 0, "MARKET");
}
public function marketSellTest($symbol, $quantity) {
return $this->orderTest("SELL", $symbol, $quantity, 0, "MARKET", $flags = []);
public function marketSellTest($symbol, $quantity, $flags = []) {
return $this->orderTest("SELL", $symbol, $quantity, 0, "MARKET", $flags);
}
public function cancel($symbol, $orderid) {
return $this->httpRequest("v3/order", "DELETE", ["symbol"=>$symbol, "orderId"=>$orderid], true);
Expand Down Expand Up @@ -588,7 +588,7 @@ public function depthCache($symbols, $callback) {
if ( !isset($this->depthQueue[$symbol]) ) $this->depthQueue[$symbol] = [];
if ( !isset($this->depthCache[$symbol]) ) $this->depthCache[$symbol] = ["bids" => [], "asks" => []];
$this->info[$symbol]['firstUpdate'] = 0;
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@depth')->then(function($ws) use($callback, $symbol) {
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@depth')->then(function($ws) use($callback, $symbol, $loop) {
$ws->on('message', function($data) use($ws, $callback) {
$json = json_decode($data, true);
$symbol = $json['s'];
Expand All @@ -599,8 +599,9 @@ public function depthCache($symbols, $callback) {
$this->depthHandler($json);
call_user_func($callback, $this, $symbol, $this->depthCache[$symbol]);
});
$ws->on('close', function($code = null, $reason = null) use($symbol) {
$ws->on('close', function($code = null, $reason = null) use($symbol, $loop) {
echo "depthCache({$symbol}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL;
$loop->stop();
});
}, function($e) use($loop) {
echo "depthCache({$symbol})) Could not connect: {$e->getMessage()}".PHP_EOL;
Expand All @@ -625,7 +626,7 @@ public function trades($symbols, $callback) {
foreach ( $symbols as $symbol ) {
if ( !isset($this->info[$symbol]) ) $this->info[$symbol] = [];
//$this->info[$symbol]['tradesCallback'] = $callback;
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@aggTrade')->then(function($ws) use($callback, $symbol) {
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@aggTrade')->then(function($ws) use($callback, $symbol, $loop) {
$ws->on('message', function($data) use($ws, $callback) {
$json = json_decode($data, true);
$symbol = $json['s'];
Expand All @@ -637,8 +638,9 @@ public function trades($symbols, $callback) {
//$this->info[$symbol]['tradesCallback']($this, $symbol, $trades);
call_user_func($callback, $this, $symbol, $trades);
});
$ws->on('close', function($code = null, $reason = null) use($symbol) {
$ws->on('close', function($code = null, $reason = null) use($symbol, $loop) {
echo "trades({$symbol}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL;
$loop->stop();
});
}, function($e) use($loop) {
echo "trades({$symbol}) Could not connect: {$e->getMessage()}".PHP_EOL;
Expand Down Expand Up @@ -687,7 +689,7 @@ public function chart($symbols, $interval = "30m", $callback) {
$this->chartQueue[$symbol][$interval] = [];
$this->info[$symbol][$interval]['firstOpen'] = 0;
//$this->info[$symbol]['chartCallback'.$interval] = $callback;
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@kline_'.$interval)->then(function($ws) use($callback, $symbol) {
$connector('wss://stream.binance.com:9443/ws/'.strtolower($symbol).'@kline_'.$interval)->then(function($ws) use($callback, $symbol, $loop) {
$ws->on('message', function($data) use($ws, $callback) {
$json = json_decode($data);
$chart = $json->k;
Expand All @@ -697,8 +699,9 @@ public function chart($symbols, $interval = "30m", $callback) {
//$this->info[$symbol]['chartCallback'.$interval]($this, $symbol, $this->charts[$symbol][$interval]);
call_user_func($callback, $this, $symbol, $this->charts[$symbol][$interval]);
});
$ws->on('close', function($code = null, $reason = null) use($symbol) {
$ws->on('close', function($code = null, $reason = null) use($symbol, $loop) {
echo "chart({$symbol},{$interval}) WebSocket Connection closed! ({$code} - {$reason})".PHP_EOL;
$loop->stop();
});
}, function($e) use($loop) {
echo "chart({$symbol},{$interval})) Could not connect: {$e->getMessage()}".PHP_EOL;
Expand Down
15 changes: 15 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="true" colors="true" stopOnFailure="false">
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./examples</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<testsuite name="PHP Binance Api">
<directory suffix=".php">./</directory>
</testsuite>
</phpunit>
10 changes: 0 additions & 10 deletions tests/prep.sh

This file was deleted.

5 changes: 0 additions & 5 deletions tests/run.sh

This file was deleted.

0 comments on commit e2e54f6

Please sign in to comment.