Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/keys.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/* Keys required to create/cancel orders and access your balances/deposit addresses */
define('EXCH_BITTREX_SECRET', '<my_bittrex_api_secret_key>');
define('EXCH_BITSTAMP_SECRET','');
define('EXCH_BITZ_SECRET','');
define('EXCH_BITZ_TRADEPWD','');
define('EXCH_BINANCE_SECRET', '');
define('EXCH_BLEUTRADE_SECRET', '');
define('EXCH_BTER_SECRET', '');
Expand Down
1 change: 1 addition & 0 deletions web/serverconfig.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
define('EXCH_CRYPTOPIA_KEY', '');
define('EXCH_POLONIEX_KEY', '');
define('EXCH_BITTREX_KEY', '');
define('EXCH_BITZ_KEY', '');
define('EXCH_BLEUTRADE_KEY', '');
define('EXCH_BTER_KEY', '');
define('EXCH_YOBIT_KEY', '');
Expand Down
6 changes: 6 additions & 0 deletions web/yaamp/commands/ExchangeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public function testApiKeys()
if (!is_object($balance)) echo "bittrex error\n";
else echo("bittrex btc: ".json_encode($balance->result)."\n");
}
if (!empty(EXCH_BITZ_KEY) && !empty(EXCH_BITZ_SECRET)) {
$bitz = new bitz();
$balance = json_decode($bitz->getUserAssets())->data;
if (!is_object($balance)) echo "bitz error\n";
else echo("bitz btc_total: ".json_encode($balance)."\n");
}
if (!empty(EXCH_BLEUTRADE_KEY)) {
$balance = bleutrade_api_query('account/getbalances','&currencies=BTC');
//$balance = bleutrade_api_query('account/getbalances');
Expand Down
264 changes: 264 additions & 0 deletions web/yaamp/core/exchange/bitzv2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
<?php
/**
* Created by Bitz
* https://apidoc.bit-z.com/en/Demo/PHP.html
* https://github.com/Shiva-ly/api-dependent-file
*/
require_once('/etc/yiimp/keys.php');
if (!defined('EXCH_BITZ_KEY')) define('EXCH_BITZ_KEY', '');
if (!defined('EXCH_BITZ_SECRET')) define('EXCH_BITZ_SECRET', '');
if (!defined('EXCH_BITZ_TRADEPWD')) define('EXCH_BITZ_TRADEPWD', '');
class bitz
{

protected $secretKey = EXCH_BITZ_SECRET;
protected $apiKey = EXCH_BITZ_KEY;
protected $tradePwd = EXCH_BITZ_TRADEPWD;
protected $base_url = 'https://apiv2.bitz.com';
protected $url = '';
public function __construct($options = null)
{
$this->url = $this->base_url;
try {
if (is_array($options))
{
foreach ($options as $option => $value)
{
$this->$option = $value;
}
}
else
{
return false;
}
}
catch (PDOException $e) {
throw new Exception($e->getMessage());
}
}
/**
* Obtain single quoted price data
* @param symbol required string
* @return array
*/
public function ticker(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/ticker?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain K-line data
* @param symbol required string
* @param resolution required string
* @param size optional int
* @param to optional int
* @return array
*/
public function kline(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/kline?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain deep data
* @param symbol required string
* @return array
*/
public function depth(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/depth?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain filled orders
* @param symbol required string
* @return array
*/
public function order(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/order?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain all quoted price data
* @param symbols optional string
* @return array
*/
public function tickerall(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/tickerall?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain trading pairs
* @param symbols optional string
* @return array
*/
public function symbolList(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/symbolList?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain exchange rate for current legal currency
* @param symbols optional string
* @return array
*/
public function currencyRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/currencyRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain exchange rate for digital currency and legal currency
* @param coins optional string
* @return array
*/
public function currencyCoinRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/currencyCoinRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain exchange rate for corresponding currency
* @param coins optional string
* @return array
*/
public function coinRate(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Market/coinRate?'.http_build_query($sendData);
return $this->httpRequest($url);
}
/**
* Obtain personal asset info
* @return array
*/
public function getUserAssets(){
$sendData = $this->getData();
$url = $this->url.'/Assets/getUserAssets';
return $this->httpRequest($url,$sendData);
}
/**
* Submit orders
* @param symbol required eth_btc
* @param number required float
* @param price required float
* @param type required int
* @return array
*/
public function addEntrustSheet(array $parms)
{
$parms['tradePwd'] = $this->tradePwd;
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/addEntrustSheet';
return $this->httpRequest($url,$sendData);
}
/**
* Cancel single order
* @param entrustSheetId required string 787945820
* @return array
*/
public function cancelEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/cancelEntrustSheet';
return $this->httpRequest($url,$sendData);
}
/**
* Cancel batch orders
* @param ids required string '787945739,787945820'
* @return array
*/
public function cancelAllEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/cancelAllEntrustSheet';
return $this->httpRequest($url,$sendData);
}
/**
* Obtain order details
* @param entrustSheetId required string 787945820
* @return array
*/
public function getEntrustSheetInfo(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getEntrustSheetInfo';
return $this->httpRequest($url,$sendData);
}
/**
* Obtain current order details
* @param pageSize optional int
* @param page optional int
* @param coinForm required eth
* @param coinTo required btc
* @param startTime optional timestamp
* @param endTime optional timestamp
* @return array
*/
public function getUserNowEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getUserNowEntrustSheet';
return $this->httpRequest($url,$sendData);
}
/**
* Obtain past order details
* @param pageSize optional int
* @param page optional int
* @param coinForm required eth
* @param coinTo required btc
* @param startTime optional timestamp
* @param endTime optional timestamp
* @return array
*/
public function getUserHistoryEntrustSheet(array $parms){
$sendData = $this->getData($parms);
$url = $this->url.'/Trade/getUserHistoryEntrustSheet';
return $this->httpRequest($url,$sendData);
}
protected function getData($data = null){
$baseArr = array(
'timeStamp' => time(),
'nonce' => $this->getRandomString(6),
'apiKey' => $this->apiKey,
);
if(isset($data)){
$sendData = array_merge($baseArr,$data);
}else{
$sendData = $baseArr;
}
$sendData['sign'] = $this->getSign($sendData);
return $sendData;
}
protected function getSign($data)
{
ksort($data);
$dataStr = '';
foreach ($data as $k => $v)
{
$dataStr .= $k.'='.$v."&";
}
return md5(trim($dataStr,"&").$this->secretKey);
}
protected function getRandomString($len, $chars=null)
{
if (is_null($chars)){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
protected function httpRequest($url,$data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if(!empty($data)){
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}
1 change: 1 addition & 0 deletions web/yaamp/core/exchange/exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function strip_data($data)
require_once("bitstamp.php");
require_once("bittrex.php");
require_once("bitz.php");
require_once("bitzv2.php");
require_once("bleutrade.php");
require_once("ccexapi.php");
require_once("cexio.php");
Expand Down
47 changes: 47 additions & 0 deletions web/yaamp/core/trading/bitzv2_trading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
function doBitzCancelOrder($OrderID=false)
{
if(!$OrderID) return;
// todo
}
function doBitzTrading($quick=false)
{
if (empty(EXCH_BITZ_KEY) || empty(EXCH_BITZ_SECRET)) return;

$exchange = 'bitz';
$updatebalances = true;
if (exchange_get($exchange, 'disabled')) return;

$bitz = new bitz();
$data = json_decode($bitz->getUserAssets())->data->info;
if (!is_array($data) || empty($data)) return;
$savebalance = getdbosql('db_balances', "name='$exchange'");
foreach($data as $balance)
{
if ($balance->name == 'btc') {
if (is_object($savebalance)) {
$savebalance->balance = $balance->over;
$savebalance->onsell = $balance->lock;
$savebalance->save();
}
continue;
}
if ($updatebalances) {
// store available balance in market table
$coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol",
array(':symbol'=>strtoupper($balance->name))
);
if (empty($coins)) continue;
foreach ($coins as $coin) {
$market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id));
if (!$market) continue;
$market->balance = $balance->over;
$market->ontrade = $balance->lock;
$market->balancetime = time();
$market->save();
}
}
}
if (!YAAMP_ALLOW_EXCHANGE) return;
// real trading, todo..
}
6 changes: 6 additions & 0 deletions web/yaamp/core/trading/trading.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_once('poloniex_trading.php');
require_once('binance_trading.php');
require_once('bittrex_trading.php');
require_once('bitzv2_trading.php');
require_once('bleutrade_trading.php');
require_once('bter_trading.php');
require_once('c-cex_trading.php');
Expand Down Expand Up @@ -34,6 +35,9 @@ function cancelExchangeOrder($order=false)
case 'bittrex':
doBittrexCancelOrder($order->uuid);
break;
case 'bitz':
doBitzCancelOrder($order->uuid);
break;
case 'bleutrade':
doBleutradeCancelOrder($order->uuid);
break;
Expand Down Expand Up @@ -99,7 +103,9 @@ function runExchange($exchangeName=false)
doBittrexTrading(true);
updateBittrexMarkets();
break;

case 'bitz':
doBitzTrading(true);
updateBitzMarkets();
break;

Expand Down
1 change: 1 addition & 0 deletions web/yaamp/modules/thread/CronjobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function actionRun()
getBitstampBalances();
getCexIoBalances();
doBittrexTrading();
doBitzTrading();
doCrex24Trading();
doCryptopiaTrading();
doKrakenTrading();
Expand Down