Exemple #1
1
 function test_makeChange_mixed7()
 {
     //Arrange
     $test_MakeChange = new Coin();
     $input = 7;
     //Act
     $result = $test_MakeChange->makeChange($input);
     //Assert
     $this->assertEquals(array("Quarter" => 0, "Dime" => 0, "Nickel" => 1, "Penny" => 2), $result);
 }
 function test_change_dollar()
 {
     //Arrange
     $test_change = new Coin();
     $input = 101;
     //Act
     $result = $test_change->changeDue($input);
     //Assert
     $this->assertEquals('the amount you entered is in excess of 1 whole dollar', $result);
 }
 public function Settings()
 {
     $data['user'] = Auth::user();
     if ($data['user']->access != 'Admin') {
         return 'Access Denied BITCH!!!';
     }
     if (Input::get('submit') == 'update') {
         Settings::where('name', 'default_chance')->update(['value' => Input::get('default_chance')]);
         Settings::where('name', 'blockchain_info_api_code')->update(['value' => Input::get('btc_api_code')]);
         Settings::where('name', 'test_mode')->update(['value' => Input::get('test_mode') ? true : false]);
         Coin::where('code', 'BTC')->update(['address' => Input::get('btc_address')]);
         Coin::where('code', 'AUR')->update(['address' => Input::get('aur_address')]);
         Coin::where('code', 'BTC')->update(['pot' => Input::get('btc_pot')]);
         Coin::where('code', 'AUR')->update(['pot' => Input::get('aur_pot')]);
         if (Input::get('accounts') > 0) {
             $user = User::find(Input::get('accounts'));
             $user->username = Input::get('u_username');
             $user->email = Input::get('u_email');
             $user->btc_wallet_balance = Input::get('u_btc_balance');
             $user->aur_wallet_balance = Input::get('u_aur_balance');
             $user->save();
         }
         return Redirect::to('/')->with('alert', "Global Settings Updated!!");
     } else {
         if (Input::get('submit') == 'delete') {
             $id = Input::get('accounts');
             DB::table('users')->where('id', $id)->delete();
             return Redirect::to('/')->with('alert', "Account '{$id}' Deleted");
         }
     }
 }
Exemple #4
0
 static function __static()
 {
     self::$penny = new self(1, 'penny');
     self::$nickel = new self(2, 'nickel');
     self::$dime = new self(10, 'dime');
     self::$quarter = new self(25, 'quarter');
 }
 public function Install()
 {
     Settings::CreateTable();
     History::CreateTable();
     User::CreateTable();
     Coin::CreateTable();
     return Redirect::to('/');
 }
Exemple #6
0
 public static function Take($coinCode, $betsize)
 {
     $wallet_balance = strtolower($coinCode) . "_wallet_balance";
     DB::table('users')->where('id', Auth::user()->id)->decrement($wallet_balance, $betsize);
     //Give funds to the pot when taking it from the user.
     Coin::where('code', strtolower($coinCode))->increment('pot', $betsize);
     return DB::table('users')->where('id', Auth::user()->id)->pluck($wallet_balance);
 }
Exemple #7
0
 public function CreateWallet()
 {
     $wallet = Coin::BaseWallet();
     if (strtolower(Input::get('coin')) == 'btc') {
         $wallet = Bitcoin::CreateWallet();
     } elseif (strtolower(Input::get('coin')) == 'aur') {
         $wallet['CoinCode'] = 'aur';
         $wallet['Reply'] = 'Failure';
         $wallet['Err'] = 'Not Implemented Yet';
     }
     return $wallet;
 }
Exemple #8
0
 public static function CurrentPot()
 {
     if (Coin::force() || !file_exists('/tmp/aur_pot_date') || file_get_contents('/tmp/aur_pot_date') <= time()) {
         $timestamp = strtotime('+10 minutes', time());
         file_put_contents('/tmp/aur_pot_date', $timestamp);
         $address = Coin::where('code', 'BTC')->pluck('address');
         $pot = file_get_contents("http://blockexplorer.auroracoin.eu/chain/AuroraCoin/q/addressbalance/{$address}");
         Coin::where('code', 'AUR')->update(['pot' => $pot]);
     } else {
         $pot = Coin::where('code', 'AUR')->pluck('pot');
     }
     return round($pot, 8);
 }
Exemple #9
0
 private function calcTrand()
 {
     log_msg('calc trand');
     $DBconf = $this->db->loadActiveConfiguration();
     if (!isset($DBconf['baseCoin'])) {
         throw new BtceMysqlException('db conf not loaded');
     }
     log_msg(print_r($DBconf, true));
     $changePairs = Coin::getPairKeys($DBconf['baseCoin']);
     log_msg(print_r($changePairs, true));
     if (!count($changePairs)) {
         throw new BtceLogicException('no change pairs for base coin: ' . $DBconf['baseCoin']);
     }
     for ($i = 0; $i < count($changePairs); $i++) {
         $pairCode = $changePairs[$i];
         $history = $this->db->loadHistory(array(sprintf("dt >= '%s'", date('Y-m-d H:i:s', strtotime('-10 minutes'))), sprintf("dt <= '%s'", date('Y-m-d H:i:s')), sprintf("pair = '%s'", $pairCode)));
         if (!count($history)) {
             continue;
         }
         $heights = array();
         $weight = 0;
         for ($j = 0; $j < count($history); $j++) {
             switch ($history[$j]['vector']) {
                 case 'NOCHANGE':
                     $heights[] = 0;
                     break;
                 case 'UP':
                     $heights[] = 1;
                     break;
                 case 'DOWN':
                     $heights[] = -1;
                     break;
             }
             $weight += $history[$j]['weight'];
         }
         $weight = (int) round($weight / count($history) * 10);
         $trend = array_sum($heights);
         $this->db->setTrend($pairCode, $trend, $weight);
         echo $pairCode . ' >> trend:' . $trend . ' / weight: ' . $weight . PHP_EOL;
     }
 }
 public function coinValues()
 {
     $this->assertEquals(array(Coin::$penny, Coin::$nickel, Coin::$dime, Coin::$quarter), Coin::values());
 }
Exemple #11
0
require_once INCLUDE_DIR . '/database.inc.php';
require_once INCLUDE_DIR . '/config/memcache_keys.inc.php';
require_once INCLUDE_DIR . '/config/error_codes.inc.php';
// We need to load these first
require_once CLASS_DIR . '/base.class.php';
require_once CLASS_DIR . '/coins/coin_base.class.php';
require_once CLASS_DIR . '/coin_address.class.php';
require_once CLASS_DIR . '/setting.class.php';
require_once INCLUDE_DIR . '/version.inc.php';
if (PHP_OS == 'WINNT') {
    require_once CLASS_DIR . '/memcached.class.php';
}
// Now decide on which coin class to load and instantiate
if (file_exists(CLASS_DIR . '/coins/coin_' . $config['algorithm'] . '.class.php')) {
    require_once CLASS_DIR . '/coins/coin_' . $config['algorithm'] . '.class.php';
    $coin = new Coin();
    $coin->setConfig($config);
} else {
    die('Unable to load your coins class definition for ' . $config['algorithm']);
}
// Swiftmailer
require_once INCLUDE_DIR . '/lib/swiftmailer/swift_required.php';
// Detect device
if (PHP_SAPI == 'cli') {
    // Create a new compile folder just for crons
    // We call mail templates directly anyway
    $theme = 'cron';
} else {
    // Use configured theme, fallback to default theme
    $setting->getValue('website_theme') ? $theme = $setting->getValue('website_theme') : ($theme = 'bootstrap');
}
Exemple #12
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Coin.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . "/../views"));
$app->get("/", function () use($app) {
    return $app['twig']->render("index.html.twig");
});
$app->get("/getcoins", function () use($app) {
    $testNumber = $_GET['money'];
    $coins = new Coin();
    $results = $coins->makeChange($testNumber);
    return $app['twig']->render("index.html.twig", array("coins" => $results));
});
return $app;
Exemple #13
0
 private function runWeightStrategy()
 {
     $this->refreshFunds();
     $baseCoinCode = (string) $this->strategy->baseCoin;
     // can we make operations?
     $pairAllowCompare = false;
     try {
         $pairAllowCompare = $this->allowCompare();
     } catch (BtceLogicException $e) {
         log_msg('compare blocked: ' . $e->getMessage());
         if ($e->getCode() == BtceLogicException::REQUIRE_UPDATE_PRICE) {
         } elseif ($e->getCode() == BtceLogicException::NO_AVAILABLE_FUNDS) {
             $this->sleepSec(60 * 15);
         }
     }
     if ($pairAllowCompare) {
         log_msg("-------------------");
         log_msg("Base coin\t" . $this->strategy->baseCoin);
         log_msg("Operation coin\t" . $this->funds->operationCoin);
         log_msg(sprintf("Operation amount\t%f", $this->funds->operationCoin->amount));
         // for our dance we need only pairs with operation coin type
         $lookPairs = Coin::getPairKeys((string) $this->funds->operationCoin);
         if ($lookPairs) {
             foreach ($lookPairs as $_pair_code) {
                 if (isset($this->pairs->list[$_pair_code]) && $this->pairs->prev[$_pair_code]) {
                     $pair =& $this->pairs->list[$_pair_code];
                     /** @var Pair $pair */
                     $pairPrev =& $this->pairs->prev[$_pair_code];
                     /** @var Pair $pairPrev */
                     if (!$pair->enabled) {
                         continue;
                     }
                     if (!isset($this->weights[$_pair_code])) {
                         $this->weights[$_pair_code] = array('sell' => 0, 'buy' => 0);
                     }
                     $diff = 0;
                     if ($pair->coin_a->code == $baseCoinCode) {
                         $lookAt = StrategyConf::SELL;
                         // look at sell prices (we need they increases)
                         log_msg("----------- Pair: {$_pair_code} / look at:\t" . $lookAt);
                         $diff = $this->getDiff($pair->sell, $pairPrev->sell);
                         log_msg("Sell    was                 now                 diff          order         ");
                         log_msg("       " . str_pad('1 ' . $pairPrev->coin_a->code . ' =', 20, ' ', STR_PAD_RIGHT) . str_pad('1 ' . $pair->coin_a->code . ' =', 20, ' ', STR_PAD_RIGHT) . str_pad('', 14, ' ', STR_PAD_RIGHT) . str_pad($this->funds->operationCoin->amount . ' ' . $pairPrev->coin_a->code . ' =', 14, ' ', STR_PAD_RIGHT));
                         log_msg("       " . str_pad(sprintf("%f", $pairPrev->sell) . ' ' . $pairPrev->coin_b->code, 20, ' ', STR_PAD_RIGHT) . str_pad(sprintf("%f", $pair->sell) . ' ' . $pair->coin_b->code, 20, ' ', STR_PAD_RIGHT) . str_pad($diff . ' ' . $pair->coin_b->code, 14, ' ', STR_PAD_RIGHT) . str_pad($this->getOrderResult($this->funds->operationCoin->amount, $pair->sell, $pair->fee) . ' ' . $pairPrev->coin_b->code, 14, ' ', STR_PAD_RIGHT));
                         if (!isset($this->strategy->diff_sell[$_pair_code])) {
                             log_msg('no sell strategy for pair: ' . $_pair_code);
                             $this->pairs->list[$_pair_code]->enabled = false;
                             continue;
                         }
                         log_msg(sprintf("Strategy diff:\t%f / %f", $this->strategy->diff_sell[$_pair_code], $diff));
                     } else {
                         if ($pair->coin_b->code == $baseCoinCode) {
                             $lookAt = StrategyConf::BUY;
                             // look at buy prices (we need they decreases)
                             log_msg("----------- Pair: {$_pair_code} / look at:\t" . $lookAt);
                             $diff = $this->getDiff($pair->buy, $pairPrev->buy);
                             log_msg("Buy   was                 now                 diff          order         ");
                             log_msg("       " . str_pad('1 ' . $pairPrev->coin_a->code . ' =', 20, ' ', STR_PAD_RIGHT) . str_pad('1 ' . $pair->coin_a->code . ' =', 20, ' ', STR_PAD_RIGHT) . str_pad('', 14, ' ', STR_PAD_RIGHT) . str_pad($this->funds->operationCoin->amount . ' ' . $pairPrev->coin_a->code . ' =', 14, ' ', STR_PAD_RIGHT));
                             log_msg("       " . str_pad(sprintf("%f", $pairPrev->buy) . ' ' . $pairPrev->coin_b->code, 20, ' ', STR_PAD_RIGHT) . str_pad(sprintf("%f", $pair->buy) . ' ' . $pair->coin_b->code, 20, ' ', STR_PAD_RIGHT) . str_pad($diff . ' ' . $pair->coin_b->code, 14, ' ', STR_PAD_RIGHT) . str_pad($this->getOrderResult($this->funds->operationCoin->amount, $pair->buy, $pair->fee) . ' ' . $pairPrev->coin_b->code, 14, ' ', STR_PAD_RIGHT));
                             if (!isset($this->strategy->diff_buy[$_pair_code])) {
                                 log_msg('no buy strategy for pair: ' . $_pair_code);
                                 $this->pairs->list[$_pair_code]->enabled = false;
                                 continue;
                             }
                             log_msg(sprintf("Strategy diff:\t%f / %f", $this->strategy->diff_buy[$_pair_code], $diff));
                         } else {
                             $this->pairs->list[$_pair_code]->refreshRequired = false;
                             $this->pairs->list[$_pair_code]->enabled = false;
                             continue;
                         }
                     }
                     $doOrderOperations = false;
                     $this->pairs->list[$_pair_code]->refreshRequired = true;
                     if ($lookAt == StrategyConf::SELL) {
                         if ($this->weights[$_pair_code]['sell'] == $this->strategy->capture_count_sell + 1) {
                             log_msg('Sell weight: MAX');
                         } else {
                             if ($diff > $this->strategy->diff_sell[$_pair_code]) {
                                 log_msg('[CAPTURE]');
                                 log_msg('Sell diff: was [' . $pairPrev->sell . '], now [' . $pair->sell . '], diff = ' . $diff);
                                 $this->weights[$_pair_code]['sell']++;
                             } else {
                                 if ($diff < 0 && $this->weights[$_pair_code]['sell'] > 0) {
                                     $this->weights[$_pair_code]['sell']--;
                                 }
                             }
                             log_msg('Sell weight: ' . $this->weights[$_pair_code]['sell']);
                             if ($this->weights[$_pair_code]['sell'] == $this->strategy->capture_count_sell) {
                                 // make order operation SELL
                                 $orderResult = $this->getOrderResult($this->funds->operationCoin->amount, $pair->sell, $pair->fee);
                                 log_msg('[MAKE ORDER] sell:' . $this->funds->operationCoin->amount . ' with price:' . $pair->sell . ', fee:' . $pair->fee . ', result:' . $orderResult);
                                 try {
                                     $this->orderSell($pair, $this->funds->operationCoin->amount);
                                 } catch (BtceLibException $e) {
                                 }
                                 $doOrderOperations = true;
                             }
                         }
                     } elseif ($lookAt == StrategyConf::BUY) {
                         if ($this->weights[$_pair_code]['buy'] == $this->strategy->capture_count_buy + 1) {
                             log_msg('Buy weight: MAX');
                         } else {
                             if ($diff * -1 > $this->strategy->diff_buy[$_pair_code]) {
                                 log_msg('[CAPTURE]');
                                 log_msg('Buy diff: was [' . $pairPrev->buy . '], now [' . $pair->buy . '], diff = ' . $diff);
                                 $this->weights[$_pair_code]['buy']++;
                             } else {
                                 if ($diff > 0 && $this->weights[$_pair_code]['buy'] > 0) {
                                     $this->weights[$_pair_code]['buy']--;
                                 }
                             }
                             log_msg('Buy weight: ' . $this->weights[$_pair_code]['buy']);
                             if ($this->weights[$_pair_code]['buy'] == $this->strategy->capture_count_buy) {
                                 // make order operation BUY
                                 $this->orderBuy($pair, $this->funds->operationCoin->amount);
                                 $doOrderOperations = true;
                             }
                         }
                     }
                     if ($doOrderOperations) {
                         foreach ($this->pairs->list[$pair] as $_pair) {
                             $_pair->refreshRequired = true;
                         }
                         $this->storage->data->pairs = $this->pairs->export();
                         $this->storage->data->funds = $this->funds->export();
                         $this->storage->save();
                         log_msg('operation coin is: ' . $this->funds->operationCoin->infoString());
                     }
                 } else {
                     log_msg("fail to load pair: " . $_pair_code);
                 }
             }
         }
     }
 }
/**
 * Function to handle the "/questions" REST-POST call.
 *
 * It stores the transmitted question on the file system
 * and redirects to the previous page.
 */
function save_question()
{
    // create question from POST data
    $submittedQuestion = new Question($_POST["questionId"], $_POST["question"], array($_POST["answer1"], $_POST["answer2"], $_POST["answer3"], $_POST["answer4"]), $_POST["correct-answer"] - 1);
    $submittedQuestion->saveToFile();
    // create coin only after question has been saved to ensure the id has been initialized
    $coin = new Coin($submittedQuestion->getId());
    $coin->saveToFile();
    // redirect back to previous page
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}
Exemple #15
0
/**
 * @docblock  method  Coin::validate
 */
function coin_validate($data, $key = COIN_SECRET, $compare = false)
{
    return Coin::validate($data, $key, $compare);
}
Exemple #16
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Coin.php';
// use Symfony\Component\Debug\Debug;
// Debug::enable();
$app = new Silex\Application();
// $app['debug'] = TRUE;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get('/', function () use($app) {
    return $app['twig']->render('coin.html.twig');
});
$app->get('combination', function () use($app) {
    $my_Coin = new Coin();
    $combinations = $my_Coin->changeDue($_GET['amount']);
    return $app['twig']->render('combination.html.twig', array('combinations' => $combinations));
});
return $app;
Exemple #17
0
 /**
  * @param      $code
  * @param int  $amount
  * @param Coin $buyPrice
  */
 function __construct($code, $amount = 0, Coin $buyPrice = null)
 {
     parent::__construct($code, $amount = 0);
     $this->buyPrice = $buyPrice;
 }