diff --git a/app/maker.php b/app/maker.php new file mode 100644 index 0000000..9ad8e84 --- /dev/null +++ b/app/maker.php @@ -0,0 +1,141 @@ + 'iNuEcSOdC7F735D65sI6PH3C', + 'secret' => 'A5kS-mBKf-GlBLATTkGekuYVD6nH2hp16P4YGM9Q-osfZTB9', + 'enableRateLimit' => true, +]); + +$symbol = 'BTC/USD'; +$orderBookWidth = 3; +$orderBookPosition = $orderBookWidth - 1; +$fee = 0.025 / 100; +$amount = 100; // USD + +$orderBook = $exchange->fetchOrderBook($symbol, $orderBookWidth); + +$longPrice = $orderBook['bids'][2][0]; +$shortPrice = $orderBook['asks'][2][0]; + +$longSL = $exchange->fixPrice($longPrice - $longPrice * $fee, 0.5); +$shortSL = $exchange->fixPrice($shortPrice + $shortPrice * $fee, -0.5); +$longTP = $exchange->fixPrice($longPrice + $longPrice * 0.01, 0.5); +$shortTP = $exchange->fixPrice($shortPrice - $shortPrice * 0.01, -0.5); + +$paramsLongStopLoss = [ + 'execInst' => 'Close,LastPrice,ParticipateDoNotInitiate', + 'leavesQty' => $amount, + 'ordStatus' => 'New', + 'ordType' => 'StopLimit', + 'orderQty' => $amount, + 'side' => 'Sell', +// 'price' => 6000, //$longSL + 'price' => $longSL, +// 'stopPx' => 6000, //$longSL + 'stopPx' => $longSL, + 'symbol' => 'XBTUSD', + 'timeInForce' => 'GoodTillCancel', +]; + +$paramsLongLimitOrder = [ + 'execInst' => 'ParticipateDoNotInitiate', + 'leavesQty' => $amount, + 'ordType' => 'Limit', + 'orderQty' => $amount, +// 'price' => 6500, //$longPrice + 'price' => $longPrice, + 'ordStatus' => 'New', + 'side' => 'Buy', + 'symbol' => 'XBTUSD', + 'timeInForce' => 'GoodTillCancel', +]; + +$paramsLongTakeProfit = [ + 'execInst' => 'Close,LastPrice,ParticipateDoNotInitiate', + 'leavesQty' => $amount, + 'ordStatus' => 'New', + 'ordType' => 'LimitIfTouched', + 'orderQty' => $amount, + 'side' => 'Sell', +// 'price' => 6999, // $lognTP + 'price' => $longTP, +// 'stopPx' => 7000, //$lognTP + 'stopPx' => $longTP, + 'symbol' => 'XBTUSD', + 'timeInForce' => 'GoodTillCancel' +]; + +$stopLossId = null; +$takeProfitId = null; +$orderPositionId = null; + +$params = [ + 'orders' => [ + $paramsLongStopLoss, + $paramsLongTakeProfit, + $paramsLongLimitOrder + ] +]; + +echo 'Set order: ' . $longPrice . "\n"; +echo 'Set TP: ' . $longTP . "\n"; +echo 'Set SL: ' . $longSL . "\n"; + +$result = $exchange->createOrderBulk($params); + +echo 'Bulk orders: ' . "\n"; +echo json_encode($result) . "\n"; + +if (!isset($result) || !count($result) == 3) { + if (count($result) > 0) { + $exchange->deleteAllOrders(['symbol' => 'XBTUSD']); + } + + echo "Wrong orders!\n"; + die(); +} + +$stopLossId = $result[0]['orderID']; +$takeProfitId = $result[0]['orderID']; +$orderPositionId = $result[0]['orderID']; + +$orderStopLoss = $exchange->fetch_order($stopLossId, $symbol); +$orderTakeProfit = $exchange->fetch_order($takeProfitId, $symbol); + +if (!isOrderAndStopsApplied($symbol, $orderPositionId, $stopLossId, $takeProfitId)) { + echo 'All orders canceled' . "\n"; + die(); +} + +echo 'Orders set' . "\n"; + +function isOrderAndStopsApplied($symbol, $orderPositionId, $stopLossId, $takeProfitId) { + global $exchange; + + echo "Check losses status...\n"; + + $orderStopLoss = $exchange->fetch_order($stopLossId, $symbol); + $orderTakeProfit = $exchange->fetch_order($takeProfitId, $symbol); + + if ((empty($orderStopLoss) || !isset($orderStopLoss['info']['ordStatus'])) && + (empty($orderTakeProfit) || !isset($orderTakeProfit['info']['ordStatus']))) { + echo "Orders are not processed...\n"; + return isOrderAndStopsApplied($symbol, $orderPositionId, $stopLossId, $takeProfitId); + } + + if ($orderStopLoss['info']['ordStatus'] == 'Canceled' && $orderTakeProfit['info']['ordStatus'] == 'Canceled') { + echo "Orders are canceled...\n"; + + return false; + } + + return true; +} \ No newline at end of file diff --git a/composer.json b/composer.json index 63bd9f5..7dbc24a 100644 --- a/composer.json +++ b/composer.json @@ -1,223 +1,15 @@ { - "name": "ccxt/ccxt", + "name": "bot/bot", "type": "library", - "description": "A JavaScript / Python / PHP cryptocurrency trading library with support for more than 90 bitcoin/altcoin exchanges", + "description": "Bot", "keywords": [ - "algorithmic", - "algotrading", - "altcoin", - "altcoins", - "api", - "arbitrage", - "backtest", - "backtesting", - "bitcoin", - "bot", - "btc", - "cny", - "coin", - "coins", - "crypto", - "cryptocurrency", - "crypto currency", - "crypto market", - "currency", - "currencies", - "darkcoin", - "dash", - "digital currency", - "doge", - "dogecoin", - "e-commerce", - "etc", - "eth", - "ether", - "ethereum", - "exchange", - "exchanges", - "eur", - "framework", - "invest", - "investing", - "investor", - "library", - "light", - "litecoin", - "ltc", - "market", - "market data", - "markets", - "merchandise", - "merchant", - "minimal", - "order", - "orderbook", - "order book", - "price", - "price data", - "pricefeed", - "private", - "public", - "ripple", - "strategy", - "toolkit", - "trade", - "trader", - "trading", - "usd", - "volume", - "xbt", - "xrp", - "zec", - "zerocoin", - "1Broker", - "1BTCXE", - "ACX", - "acx.io", - "ANX", - "ANXPro", - "Binance", - "binance.com", - "bit2c.co.il", - "Bit2C", - "BitBay", - "BitBays", - "bitcoincoid", - "Bitcoin.co.id", - "Bitfinex", - "bitFLyer", - "bitflyer.jp", - "bithumb", - "bithumb.com", - "bitlish", - "BitMarket", - "BitMEX", - "Bitso", - "Bitstamp", - "Bittrex", - "BL3P", - "Bleutrade", - "bleutrade.com", - "BlinkTrade", - "BtcBox", - "btcbox.co.jp", - "BTCC", - "BTCChina", - "BTC-e", - "BTCe", - "BTCExchange", - "btcexchange.ph", - "BTC Markets", - "btcmarkets", - "btcmarkets.net", - "BTCTrader", - "btctrader.com", - "btc-trade.com.ua", - "BTC Trade UA", - "BTCTurk", - "btcturk.com", - "BTCX", - "btc-x", - "bter", - "Bter.com", - "BX.in.th", - "ccex", - "C-CEX", - "cex", - "CEX.IO", - "CHBTC", - "ChileBit", - "chilebit.net", - "coincheck", - "coingi", - "coingi.com", - "CoinMarketCap", - "CoinMate", - "Coinsecure", - "CoinSpot", - "coinspot.com.au", - "Crypto Capital", - "cryptocapital.co", - "Cryptopia", - "cryptopia.co.nz", - "DSX", - "dsx.uk", - "EXMO", - "flowBTC", - "flowbtc.com", - "FoxBit", - "foxbit.exchange", - "FYB-SE", - "FYB-SG", - "Gatecoin", - "GDAX", - "Gemini", - "HitBTC", - "Huobi", - "HuobiPRO", - "huobi.pro", - "Independent Reserve", - "independentreserve.com", - "itBit", - "jubi.com", - "Kraken", - "LakeBTC", - "lakebtc.com", - "LiveCoin", - "Liqui", - "liqui.io", - "luno", - "mercado", - "MercadoBitcoin", - "mercadobitcoin.br", - "mixcoins", - "mixcoins.com", - "nova", - "novaexchange", - "novaexchange.com", - "OKCoin", - "OKCoin.com", - "OKCoin.cn", - "OKEX", - "okex.com", - "Paymium", - "Poloniex", - "QuadrigaCX", - "Qryptos", - "QUOINE", - "Southxchange", - "SurBitcoin", - "surbitcoin.com", - "Tidex", - "tidex.com", - "TheRockTrading", - "UrduBit", - "urdubit.com", - "Vaultoro", - "VBTC", - "vbtc.exchange", - "vbtc.vn", - "VirWoX", - "WEX", - "wex.nz", - "xBTCe", - "xbtce.com", - "YoBit", - "yobit.net", - "YUNBI", - "Zaif" ], "homepage": "https://github.com/ccxt/ccxt", "license": "MIT", "authors": [{ - "name": "Igor Kroitor", - "email": "igor.kroitor@gmail.com", - "homepage": "https://github.com/kroitor", - "role": "Developer" - }, { - "name": "Vitaly Gordon", - "email": "rocket.mind@gmail.com", - "homepage": "https://github.com/xpl", + "name": "Ivan Kuznetsov", + "email": "ivankia01@gmail.com", + "homepage": "https://github.com/ivankia", "role": "Developer" }], "autoload": { @@ -226,7 +18,7 @@ } }, "require": { - "php": ">=5.3.0", + "php": ">=7.2", "ext-bcmath": "*", "ext-curl": "*", "ext-iconv": "*", @@ -236,7 +28,9 @@ "symfony/polyfill-mbstring": "^1.7", "kornrunner/ethereum-util": "0.0.3", "kornrunner/solidity": "0.1.2", - "pear/console_table": "1.3.1" + "pear/console_table": "1.3.1", + "guzzlehttp/guzzle": "~6.0", + "ext-json": "*" }, "archive": { "exclude": [ diff --git a/composer.lock b/composer.lock index 9d13fa1..26c6e6a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4582ddfa7dc9a25bcfab1cfda9338f39", + "content-hash": "c725bb9cce3633ad1d1b8bf66771408c", "packages": [ { "name": "fgrosse/phpasn1", @@ -75,6 +75,187 @@ ], "time": "2017-12-17T10:21:51+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "6.3.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.3-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2018-04-22T15:46:56+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, { "name": "kornrunner/ethereum-util", "version": "0.0.3", @@ -120,24 +301,25 @@ }, { "name": "kornrunner/keccak", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/kornrunner/php-keccak.git", - "reference": "b3cd83ded1acff7af40b4ca5b8ea76b164ed0c34" + "reference": "ad761f528f4d1e3ce378b8a0841e5f82c9973535" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/kornrunner/php-keccak/zipball/b3cd83ded1acff7af40b4ca5b8ea76b164ed0c34", - "reference": "b3cd83ded1acff7af40b4ca5b8ea76b164ed0c34", + "url": "https://api.github.com/repos/kornrunner/php-keccak/zipball/ad761f528f4d1e3ce378b8a0841e5f82c9973535", + "reference": "ad761f528f4d1e3ce378b8a0841e5f82c9973535", "shasum": "" }, "require": { - "php": ">=7.1.0" + "php": ">=7.1.0", + "symfony/polyfill-mbstring": "^1.8" }, "require-dev": { - "phpunit/phpunit": "~7", - "satooshi/php-coveralls": "~2" + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "~7" }, "type": "library", "autoload": { @@ -158,9 +340,10 @@ "description": "Pure PHP implementation of Keccak", "keywords": [ "keccak", - "sha-3" + "sha-3", + "sha3-256" ], - "time": "2018-03-05T10:32:01+00:00" + "time": "2018-07-30T22:16:23+00:00" }, { "name": "kornrunner/secp256k1", @@ -379,6 +562,56 @@ ], "time": "2018-01-25T20:47:17+00:00" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, { "name": "simplito/bigint-wrapper-php", "version": "1.0.0", @@ -455,16 +688,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", + "version": "v1.9.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -476,7 +709,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -510,7 +743,7 @@ "portable", "shim" ], - "time": "2018-04-26T10:06:28+00:00" + "time": "2018-08-06T14:22:27+00:00" } ], "packages-dev": [ @@ -872,16 +1105,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.6", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712", - "reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { @@ -893,12 +1126,12 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -931,7 +1164,7 @@ "spy", "stub" ], - "time": "2018-04-18T13:57:24+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1184,16 +1417,16 @@ }, { "name": "phpunit/phpunit", - "version": "6.5.9", + "version": "6.5.13", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "093ca5508174cd8ab8efe44fd1dde447adfdec8f" + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/093ca5508174cd8ab8efe44fd1dde447adfdec8f", - "reference": "093ca5508174cd8ab8efe44fd1dde447adfdec8f", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0973426fb012359b2f18d3bd1e90ef1172839693", + "reference": "0973426fb012359b2f18d3bd1e90ef1172839693", "shasum": "" }, "require": { @@ -1211,7 +1444,7 @@ "phpunit/php-file-iterator": "^1.4.3", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^1.0.9", - "phpunit/phpunit-mock-objects": "^5.0.5", + "phpunit/phpunit-mock-objects": "^5.0.9", "sebastian/comparator": "^2.1", "sebastian/diff": "^2.0", "sebastian/environment": "^3.1", @@ -1264,20 +1497,20 @@ "testing", "xunit" ], - "time": "2018-07-03T06:40:40+00:00" + "time": "2018-09-08T15:10:43+00:00" }, { "name": "phpunit/phpunit-mock-objects", - "version": "5.0.8", + "version": "5.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f" + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f", - "reference": "6f9a3c8bf34188a2b53ce2ae7a126089c53e0a9f", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/cd1cf05c553ecfec36b170070573e540b67d3f1f", + "reference": "cd1cf05c553ecfec36b170070573e540b67d3f1f", "shasum": "" }, "require": { @@ -1290,7 +1523,7 @@ "phpunit/phpunit": "<6.0" }, "require-dev": { - "phpunit/phpunit": "^6.5" + "phpunit/phpunit": "^6.5.11" }, "suggest": { "ext-soap": "*" @@ -1323,7 +1556,7 @@ "mock", "xunit" ], - "time": "2018-07-13T03:27:23+00:00" + "time": "2018-08-09T05:50:03+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -1981,12 +2214,13 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.0", + "php": ">=7.2", "ext-bcmath": "*", "ext-curl": "*", "ext-iconv": "*", "ext-pcre": "*", - "ext-gmp": "*" + "ext-gmp": "*", + "ext-json": "*" }, "platform-dev": [] } diff --git a/php/Exchange.php b/php/Exchange.php index 6e5d466..c2dceb7 100644 --- a/php/Exchange.php +++ b/php/Exchange.php @@ -1009,12 +1009,13 @@ public function handle_errors ($code, $reason, $url, $method, $headers, $body) { // it's a stub function, does nothing in base code } - public function fetch ($url, $method = 'GET', $headers = null, $body = null) { - + public function fetch ($url, $method = 'GET', $headers = [], $body = null) { if ($this->enableRateLimit) $this->throttle (); - $headers = array_merge ($this->headers, $headers ? $headers : array ()); + if (is_array($headers) || is_object($headers)) { + $headers = array_merge($this->headers, $headers ? $headers : array()); + } if (strlen ($this->proxy)) $headers['Origin'] = $this->origin; diff --git a/php/bitmex.php b/php/bitmex.php index a302bcc..14965c7 100644 --- a/php/bitmex.php +++ b/php/bitmex.php @@ -36,7 +36,7 @@ public function describe () { 'urls' => array ( 'test' => 'https://testnet.bitmex.com', 'logo' => 'https://user-images.githubusercontent.com/1294454/27766319-f653c6e6-5ed4-11e7-933d-f0bc3699ae8f.jpg', - 'api' => 'https://www.bitmex.com', + 'api' => 'https://testnet.bitmex.com', 'www' => 'https://www.bitmex.com', 'doc' => array ( 'https://www.bitmex.com/app/apiOverview', @@ -602,14 +602,14 @@ public function sign ($path, $api = 'public', $method = 'GET', $params = array ( $this->check_required_credentials(); $nonce = (string) $this->nonce (); $auth = $method . $query . $nonce; - if ($method === 'POST' || $method === 'PUT') { + if ($method === 'POST' || $method === 'PUT' || $method == 'DELETE') { if ($params) { $body = $this->json ($params); $auth .= $body; } } $headers = array ( - 'Content-Type' => 'application/json', + 'Content-Type' => isset($headers['Content-Type']) ? $headers['Content-Type'] : 'application/json', 'api-nonce' => $nonce, 'api-key' => $this->apiKey, 'api-signature' => $this->hmac ($this->encode ($auth), $this->encode ($this->secret)), @@ -617,4 +617,31 @@ public function sign ($path, $api = 'public', $method = 'GET', $params = array ( } return array ( 'url' => $url, 'method' => $method, 'body' => $body, 'headers' => $headers ); } + + public function createOrderBulk($params) { + $result = $this->request('order/bulk', 'private', 'POST', $params, []); + + return $result; + } + + public function deleteAllOrders($params) { + $result = $this->request('order/all', 'private', 'DELETE', $params, []); + + return $result; + } + + public function checkExecution($params) { + $result = $this->request('execution', 'private', 'GET', $params, []); + + return $result; + } + + public function fixPrice($value, $appendix = 0.5) { + if ($value - round($value)) { + return round($value) + $appendix; + } + + return $value; + } } +