Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class KrakenTradeSet{
- protected $buyRate;
- protected $initialBuyRate;
- protected $margin;
- protected $bitcoins;
- protected $buySell;
- protected $placeOrderAtAnyRate;
- protected $processing;
- protected $txid;
- protected $sellAt;
- protected $volumeExecuted;
- protected $index;
- protected $numberOfBuys;
- protected $numberOfSells;
- public function __construct($buyRate, $margin, $bitcoins, $buySell, $index, $placeOrderAtAnyRate = false){
- $this->buyRate = $buyRate;
- $this->initialBuyRate = $buyRate;
- $this->margin = $margin;
- $this->bitcoins = $bitcoins;
- $this->buySell = $buySell;
- $this->placeOrderAtAnyRate = $placeOrderAtAnyRate;
- $this->processing = false;
- $this->txid = null;
- $this->index = $index;
- $this->numberOfBuys = 0;
- $this->numberOfSells = 0;
- $this->validateMargin($margin);
- $this->validateBitcoins($bitcoins);
- $this->validateBuySell($buySell);
- }
- public function getBuyRate(){
- return $this->buyRate;
- }
- public function getInitialBuyRate(){
- return $this->initialBuyRate;
- }
- public function getMargin(){
- return $this->margin;
- }
- public function getBitcoins(){
- return $this->bitcoins;
- }
- public function getBuySell(){
- return $this->buySell;
- }
- public function isProcessing(){
- return $this->processing;
- }
- public function getTxid(){
- return $this->txid;
- }
- public function getSellAt(){
- return $this->sellAt;
- }
- public function getVolumeExecuted(){
- return $this->volumeExecuted;
- }
- public function getNumberOfBuys(){
- return $this->numberOfBuys;
- }
- public function getNumberOfSells(){
- return $this->numberOfSells;
- }
- public function getPlaceOrderAtAnyRate(){
- return $this->placeOrderAtAnyRate;
- }
- public function setBuyRate($buyRate){
- $this->buyRate = $buyRate;
- }
- public function setMargin($margin){
- $this->validateMargin($margin);
- $this->margin = $margin;
- }
- public function setBitcoins($bitcoins){
- $this->validateBitcoins($bitcoins);
- $this->bitcoins = $bitcoins;
- }
- public function setBuySell($buySell){
- $this->validateBuySell($buySell);
- $this->buySell = $buySell;
- }
- public function setProcessing($processing){
- $this->processing = $processing;
- }
- public function setTxid($txid){
- $this->txid = $txid;
- }
- public function setSellAt($sellAt){
- $this->sellAt = $sellAt;
- }
- public function setVolumeExecuted($volume){
- $this->volumeExecuted = $volume;
- }
- public function getIndex(){
- return $this->index;
- }
- public function addSell(){
- $this->numberOfSells++;
- }
- public function addBuy(){
- $this->numberOfBuys++;
- }
- /**
- * Validate margin
- * Should be higher then double the fee
- *
- * @param mixed $margin (1 = 1%, 10 = 10%, 0.5 = 0.5%)
- */
- protected function validateMargin($margin){
- if (floatval($margin) == 0 || $margin <= 0 || $margin > 100){
- throw new InvalidArgumentException('margin should be a percentage between 0 - 100');
- }
- if ($margin <= (KrakenTrader::getFee(100) * 2)){
- throw new InvalidArgumentException('Margin is lower then the current fee x 2. Profit will be negative.');
- }
- return true;
- }
- /**
- * Validate amount of bitcoins. 0.01 is minimum
- *
- * @param float $bitcoins
- */
- protected function validateBitcoins($bitcoins){
- if ($bitcoins < 0.01){
- throw new InvalidArgumentException('Not a valid trade amount (minimum = 0.01)');
- }
- }
- protected function validateBuySell($buySell){
- if (!in_array($buySell, array(KrakenTrader::BUY, KrakenTrader::SELL))){
- throw new InvalidArgumentException('buySell should be one of buy|sell');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment