bitcoin-atm
bitcoin atm for pyc inc.
git clone https://9o.is/git/bitcoin-atm.git
commit a747e02eb5d6efe7f8ab3a8937c9ec56c5213797 parent 836d7b251c9e4bc41d01b6aecd8141ee570703dc Author: Jul <jul@9o.is> Date: Thu, 7 Aug 2014 08:01:34 -0700 set a percentage profit for the priceticker Diffstat:
| M | src/main/scala/inc/pyc/chimera/bitcoin/PriceTicker.scala | | | 22 | ++++++++++++++++++++-- |
| M | src/main/scala/inc/pyc/chimera/lycia/Lycia.scala | | | 4 | ++++ |
| M | src/main/scala/inc/pyc/chimera/snippet/PriceTicker.scala | | | 2 | ++ |
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/main/scala/inc/pyc/chimera/bitcoin/PriceTicker.scala b/src/main/scala/inc/pyc/chimera/bitcoin/PriceTicker.scala @@ -59,6 +59,12 @@ object PriceTicker { * Command to send a unicast of the buy price. */ case object GetPrice + + /** + * Command to set a percentage price over market. + * If price over market is 5%, send 5, not 0.05, as the profit value. + */ + case class Percentage(profit: Double) /** * Command to update the price per bitcoin. @@ -94,16 +100,22 @@ class PriceTicker extends Actor with ActorLogging { /** Price per bitcoin */ private var price: String = "0.00" + + /** Percentage price over market */ + private var percentage: Double = 0 def receive = { case Tick => service ! Tick case GetPrice => - sender ! Price(price) + sender ! Price(priceWithPercentage) case GossipPrice => - self ! Price(price) + self ! Price(priceWithPercentage) + + case Percentage(profit) => + percentage = profit case Price(newPrice) => price = newPrice @@ -119,6 +131,12 @@ class PriceTicker extends Actor with ActorLogging { log.warning("Received Unknown Message") } + private def priceWithPercentage: String = { + val p = price.toDouble + val withPercentage = p + (p * (percentage * 0.01)) + Price(withPercentage toString) format + } + private def createServiceActor(service: BitcoinService.Value): ActorRef = { context.actorOf(getPriceTicker(service), service.toString) } diff --git a/src/main/scala/inc/pyc/chimera/lycia/Lycia.scala b/src/main/scala/inc/pyc/chimera/lycia/Lycia.scala @@ -31,6 +31,10 @@ object Lycia { 500 } + def percentProfit: Double = { + 5.0 + } + def servicePriceTicker: BitcoinService.Value = { // TODO get service configured BitcoinService.BitStamp diff --git a/src/main/scala/inc/pyc/chimera/snippet/PriceTicker.scala b/src/main/scala/inc/pyc/chimera/snippet/PriceTicker.scala @@ -1,6 +1,7 @@ package inc.pyc.chimera package snippet +import lycia._ import bitcoin._ import PriceTicker.commands._ import xml._ @@ -21,6 +22,7 @@ class PriceTickerComet extends EventRegister { def initPriceTicker() = /*TraceRecorder.withNewTraceContext("priceticker")*/ { + PriceTicker ! Percentage(Lycia.percentProfit) PriceTicker ! GossipPrice }