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
141 changes: 141 additions & 0 deletions app/maker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

use ccxt\bitmex;

$root = dirname(dirname(__FILE__));

include $root . '/ccxt.php';

date_default_timezone_set ('UTC');

$exchange = new bitmex([
'apiKey' => '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;
}
224 changes: 9 additions & 215 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -226,7 +18,7 @@
}
},
"require": {
"php": ">=5.3.0",
"php": ">=7.2",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-iconv": "*",
Expand All @@ -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": [
Expand Down
Loading