Skip to main content

Utility Classes of the SDK

DowntimeTradeSignal

class DowntimeTradeSignal
Allows you to detect downtime in trading. It’s useful for detecting when a trading pair is not trading for a certain period (i.e. exchange maintenance, end of trading day, etc.).
// following parameters are available
$this->registerIntParam("pastStartIndex", 1, 0, null, "Start Index");
$this->registerIntParam("pastEntryCount", 15, 1, null, "Length");
$this->registerIntParam("zeroTradesInRow", 3, 1, null, "Zero Trades In Row");

DowntimeTradeSignal example class

class DowntimeTradeSignalExample extends UserTradeSignalBase
{
	private DowntimeTradeSignal $_downtimeSignal;

	protected function init(?ParamValues $params = null)
	{
		$downtimeTradeSignalParams = $params?->getChildParams("downtimeSignal");
		// you can also set the parameters manually
		//$downtimeTradeSignalParams->setParam("pastStartIndex", 1);
		//$downtimeTradeSignalParams->setParam("pastEntryCount", 15);
		//$downtimeTradeSignalParams->setParam("zeroTradesInRow", 5);
		$this->_downtimeSignal = new DowntimeTradeSignal($downtimeTradeSignalParams);

		$this->registerSignal($this->_downtimeSignal);

		$this->registerDefinitionClass("downtimeSignal", $this->_downtimeSignal, "Downtime");
	}

	function getSignalInfo(TradeContext $tradeContext):TradeSignalInfo
	{
		$ohlcEntry = $tradeContext->ohlcEntry;

		if ($this->_downtimeSignal->getSignalInfo($tradeContext))
		{
			// we have a downtime signal, so stop trading
			return null;
		}

		...
	}
}

VolumeTradeSignal

class VolumeTradeSignal
Allows you to set a minimum volume that you want to trade. It’s useful for detecting when the volume of a trading pair is below a certain threshold.
// following parameters are available
$this->registerIntParam("pastStartIndex", 1, 0, null, "Start Index");
$this->registerIntParam("pastEntryCount", 15, 0, null, "Length");
$this->registerFloatParam("minVolume", 0, 0, null, "Min Volume");
$this->registerEnumParam("calcType", OHLCDataEntryValueType::class, OHLCDataEntryValueType::WeightedAvg, "Calc Type");

VolumeTradeSignal example class

class VolumeTradeSignalExample extends UserTradeSignalBase
{
	private VolumeTradeSignal $_volumeSignal;

	protected function init(?ParamValues $params = null)
	{
		$volumeTradeSignalParams = $params?->getChildParams("volumeSignal");
		// you can also set the parameters manually
		//$volumeTradeSignalParams->setParam("pastStartIndex", 1);
		//$volumeTradeSignalParams->setParam("pastEntryCount", 15);
		//$volumeTradeSignalParams->setParam("minVolume", 5000);
		//$volumeTradeSignalParams->setParam("calcType", 5, OHLCDataEntryValueType::WeightedAvg);
		$this->_volumeSignal = new VolumeTradeSignal($volumeTradeSignalParams);

		$this->registerSignal($this->_volumeSignal);

		$this->registerDefinitionClass("volumeSignal", $this->_volumeSignal, "Volume");
	}

	function getSignalInfo(TradeContext $tradeContext):TradeSignalInfo
	{
		$ohlcEntry = $tradeContext->ohlcEntry;

		if (!$this->_volumeSignal->getSignalInfo($tradeContext))
		{
			// we have no volume signal (not enough volume for the configured time), so stop trading
			return null;
		}

		...
	}
}

IndicatorCrossTradeSignal

class IndicatorCrossTradeSignal
Allows you to detect when two indicators cross each other (Up, Down, Over). It’s useful for detecting when a trading pair is in a certain state (i.e. bullish, bearish, etc.).
// following parameters are available
$this->registerEnumParam("crossType", IndicatorCrossType::class, null, "Cross Type");
$this->registerClassParam("indicator1", IndicatorBase::class, "Indicator #1");
$this->registerStringParam("indicator1Key", "", "Indicator #1 Key");
$this->registerClassParam("indicator2", IndicatorBase::class, "Indicator #2");
$this->registerStringParam("indicator2Key", "", "Indicator #2 Key");

IndicatorCrossTradeSignal example class

class IndicatorCrossTradeSignalExample extends UserTradeSignalBase
{
	private IndicatorCrossTradeSignal $_indicatorCrossSignal;

	protected function init(?ParamValues $params = null)
	{
		// NOTE: you could also set the parameters via $params
		$indicator1 = new IndicatorSMA(ParamValues::fromArray(array("ohlcKey" => $params->getParam("sma1OHLCKey", OHLCKeyType::Close), "timePeriod" => $params->getParam("sma1Period", 9))));
		$indicator2 = new IndicatorSMA(ParamValues::fromArray(array("ohlcKey" => $params->getParam("sma2OHLCKey", OHLCKeyType::Close), "timePeriod" => $params->getParam("sma2Period", 21))));

		$indicatorCrossTradeSignalParams = new ParamValues();
		$indicatorCrossTradeSignalParams->setParam("crossType", $params->getParam("crossType", IndicatorCrossType::Up));
		$indicatorCrossTradeSignalParams->setParam("indicator1", $indicator1);
		$indicatorCrossTradeSignalParams->setParam("indicator2", $indicator2);

		$this->_indicatorCrossSignal = new IndicatorCrossTradeSignal($indicatorCrossTradeSignalParams);

		$this->registerSignal($this->_indicatorCrossSignal);

		$this->registerDefinitionClass("indicatorCrossSignal", $this->_indicatorCrossSignal, "IndicatorCross");
	}

	function getSignalInfo(TradeContext $tradeContext):TradeSignalInfo
	{
		$ohlcEntry = $tradeContext->ohlcEntry;

		if ($this->_indicatorCrossSignal->getSignalInfo($tradeContext))
		{
			// we have a signal that the 2 SMA indicators have crossed UP
			// do somthing here
			...
		}

		...
	}
}

Utility functions of the SDK

  • Arc Cosine
  • Arc Sine
  • Arc Tangent
  • Highest Value
  • Index of Highest Value
  • MidPoint over Period
  • Midpoint Price over Period
  • Lowest Value
  • Index of Lowest Value
  • Lowest and Highest Values
  • Indexes of Lowest and Highest Values
  • Summation

Vector Functions

  • Vector Addition
  • Vector Ceil
  • Vector Cosine
  • Vector Cosh
  • Vector Division
  • Vector Exponential
  • Vector Floor
  • Vector Natural Logarithm
  • Vector Base-10 Logarithm
  • Vector Multiplication
  • Vector Sine
  • Vector Sinh
  • Vector Square Root
  • Vector Subtraction
  • Vector Tangent
  • Vector Tanh

SDK Functions

/**
 * Calculates the arc cosine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_acos(array $real):array
/**
 * Highest value over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_max(array $real, int $timePeriod = null):array
/**
 * Index of highest value over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_maxindex(array $real, int $timePeriod = null):array
/**
 * MidPoint over period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 14] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_midpoint(array $real, int $timePeriod = null):array
/**
 * Midpoint Price over period
 *
 * @param array $high       High price, array of real values.
 * @param array $low        Low price, array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 14] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_midprice(array $high, array $low, int $timePeriod = null):array
/**
 * Lowest value over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_min(array $real, int $timePeriod = null):array
/**
 * Index of lowest value over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_minindex(array $real, int $timePeriod = null):array
/**
 * Lowest and highest values over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_minmax(array $real, int $timePeriod = null):array
/**
 * Indexes of lowest and highest values over a specified period
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_minmaxindex(array $real, int $timePeriod = null):array
/**
 * Summation
 *
 * @param array $real       Array of real values.
 * @param ?int   $timePeriod [OPTIONAL] [DEFAULT 30] Number of period. Valid range from 2 to 100000.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_sum(array $real, int $timePeriod = null):array
/**
 * Calculates the vector addition of real0 to real1 and returns the resulting vector.
 *
 * @param array $real0 Array of real values.
 * @param array $real1 Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_add(array $real0, array $real1):array
/**
 * Vector Trigonometric ASin
 * Calculates the arc sine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_asin(array $real):array
/**
 * Vector Trigonometric ATan
 * Calculates the arc tangent for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_atan(array $real):array
/**
 * Vector Ceil
 * Calculates the next highest integer for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_ceil(array $real):array
/**
 * Vector Trigonometric Cos
 * Calculates the cosine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_cos(array $real):array
/**
 * Vector Trigonometric Cosh
 * Calculates the hyperbolic cosine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_cosh(array $real):array
/**
 * Vector Arithmetic Div
 * Divides each value from real0 by the corresponding value from real1 and returns the resulting array.
 *
 * @param array $real0 Array of real values.
 * @param array $real1 Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_div(array $real0, array $real1):array
/**
 * Vector Arithmetic Exp
 * Calculates e raised to the power of each value in real. Returns an array with the calculated data.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_exp(array $real):array
/**
 * Vector Floor
 * Calculates the next lowest integer for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_floor(array $real):array
/**
 * Vector Log Natural
 * Calculates the natural logarithm for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_ln(array $real):array
/**
 * Vector Log10
 * Calculates the base-10 logarithm for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_log10(array $real):array
/**
 * Vector Arithmetic Mult
 * Calculates the vector dot product of real0 with real1 and returns the resulting vector.
 *
 * @param array $real0 Array of real values.
 * @param array $real1 Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_mult(array $real0, array $real1):array
/**
 * Vector Trigonometric Sin
 * Calculates the sine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_sin(array $real):array
/**
 * Vector Trigonometric Sinh
 * Calculates the hyperbolic sine for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_sinh(array $real):array
/**
 * Vector Square Root
 * Calculates the square root of each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_sqrt(array $real):array
/**
 * Vector Arithmetic Subtraction
 * Calculates the vector subtraction of real1 from real0 and returns the resulting vector.
 *
 * @param array $real0 Array of real values.
 * @param array $real1 Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_sub(array $real0, array $real1):array
/**
 * Vector Trigonometric Tan
 * Calculates the tangent for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_tan(array $real):array
/**
 * Vector Trigonometric Tanh
 * Calculates the hyperbolic tangent for each value in real and returns the resulting array.
 *
 * @param array $real Array of real values.
 *
 * @return array Returns an array with calculated data or false on failure.
 * @throws Exception
 */
bb_tanh(array $real):array