From 4fc45057ef6a91ecac7884535f73ba044b138f01 Mon Sep 17 00:00:00 2001 From: Tim Makarios Date: Mon, 10 Mar 2014 18:15:18 +1300 Subject: [PATCH] Helper to make all the OfferCreate Transactions --- rootstock.hs | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/rootstock.hs b/rootstock.hs index f429637..e6900de 100644 --- a/rootstock.hs +++ b/rootstock.hs @@ -116,12 +116,6 @@ share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| warning Text time UTCTime |] -data OldLink = OldLink - { leftFund :: Fund - , rightFund :: Fund - , halfSpread :: Double - , logFileName :: FilePath - } type NodeEntity = Entity Node type ValueSimplexND = ValueSimplex NodeEntity Double @@ -255,25 +249,9 @@ fee = 10 tfSell = 0x00080000 reserve = 200000000 -generosity :: Double +generosity, halfSpread :: Double generosity = 1000000 - -xrpbtc, usdcny :: OldLink -xrpbtc = OldLink - { leftFund = XRP - , rightFund = btcBitstamp - , halfSpread = 1.02 - , logFileName = "XRPBTClog.csv" - } -usdcny = OldLink - { leftFund = usdBitstamp - , rightFund = cnyRippleCN - , halfSpread = 1.006 - , logFileName = "USDCNYlog.csv" - } - -oldLinks :: [OldLink] -oldLinks = [xrpbtc, usdcny] +halfSpread = 1.01 lookupXRP :: AccountInfo -> Amount lookupXRP acInfo = Drops $ dropsBalance acInfo - reserve @@ -334,6 +312,11 @@ fund :: Amount -> Fund fund (Drops _) = XRP fund (IOU iou) = IOUFund $ iouLine iou +amount :: NodeEntity -> Double -> Amount +amount x q = case nodeFund $ entityVal x of + XRP -> Drops $ round q + IOUFund line -> IOU $ IOUAmount {iouLine = line, iouQuantity = q} + lookupOffer :: Offers -> Fund -> Fund -> Maybe Offer lookupOffer (Offers offers) toSell toBuy = find (\offer -> fund (takerGets offer) == toSell && @@ -358,6 +341,16 @@ updatedValueSimplex :: ValueSimplexND -> AccountInfo -> AccountLines -> ValueSimplexND updatedValueSimplex = updatedValueSimplexWithGenerosity 0 +makeTransactions :: + ValueSimplexND -> (NodeEntity -> Double) -> AccountInfo -> [Transaction] +makeTransactions vs trf acInfo = + flip + (flip zipWith $ Set.toList $ distinctPairs $ nodes vs) + [currentSequence acInfo ..] + $ \(x0, x1) curSeq -> + let (q0, q1) = linkOptimumAtPrice vs x0 x1 $ halfSpread * price vs x0 x1 in + OfferCreate (amount x0 $ -q0 / trf x0) (amount x1 q1) curSeq Nothing + -------------------------------------------------------------------------------- signTransaction :: Transaction -> RootstockIO String signTransaction tx = do -- 2.11.4.GIT