Skip to content

Instantly share code, notes, and snippets.

@ekam230
Created April 23, 2018 18:59
Show Gist options
  • Save ekam230/e82607195d687ed60cd249eddbea0129 to your computer and use it in GitHub Desktop.
Save ekam230/e82607195d687ed60cd249eddbea0129 to your computer and use it in GitHub Desktop.
protection against losses
////защита от потерь
if ((($price-$buyPrice>$limitloss) && ($position=='short'))||(($buyPrice-$price>$limitloss) && ($position=='long'))){
var_dump($buyPrice);
var_dump($price);
var_dump($limitloss);
var_dump($position);
$log->emergency("$name Loss over 100 contracts");
$log->warning("$name Закрываю позиции");
//проверяю открытые позиции
$openpos=$bitmex2->getOpenPositions();
if ($openpos != Array()) {
message("You have open position. I try close it. Wait...");
//если бай то закрываюсь селом
if ($openpos[0]["currentQty"] > 0){
message("You have Buy Open Position");
$orderNow = array();
while ($orderNow != TRUE){
$priceNow = FALSE;
while ($priceNow != TRUE){
$priceNow=$bitmex2->getTicker("XBTUSD");
usleep(510);
}
message("Price received");
$orderNow=$bitmex2->createOrderMarket("Sell",$quantityusd);
usleep(510);
}
message("Market Order Comleted");
} //end if $openpos[0]["currentQty"
else {
message("You have Sell Open Position");
$orderNow = array();
while ($orderNow != TRUE){
while ($priceNow != TRUE){
$priceNow=$bitmex2->getTicker("XBTUSD");
usleep(510);
}
message("Price received");
$orderNow=$bitmex2->createOrderMarket("Buy",$quantityusd);
usleep(510);
}
message("Market Order Comleted");
} //end else
}//end if ($openpos != Array()
OrderMessage($orderNow);
message ("Open Position Closed.");
$log->error("$name Позиции закрыты. Давайте сделаем паузу в торговле");
die("Loss over 100 contracts");
}
//конец защиты от потерь
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment