Skip to content

Commit 62609a2

Browse files
committed
Initial commit.
0 parents  commit 62609a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+4906
-0
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.*.swp
2+
dist
3+
.cabal-sandbox
4+
cabal.sandbox.config
5+
.ghci
6+
*.o
7+
*.hi
8+
*.chi
9+
*.chs.h
10+
.virthualenv
11+
log
12+
node_modules
13+
.tmp
14+
static/bower_components
15+
16+
# Project specifics
17+
users.json
18+
site_key.txt
19+
codex.tags
20+
tags
21+
fabfile.pyc
22+
*.tpl
23+
24+
*.cfg
25+
26+
# p2p picks
27+
guardian_linux
28+
PT_Prosper*

LICENSE

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'PeerTrader' is a trademark of Deck Technologies, Inc.
2+
3+
Copyright (c) 2015, Matthew Wraith
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright
11+
notice, this list of conditions and the following disclaimer.
12+
13+
* Redistributions in binary form must reproduce the above
14+
copyright notice, this list of conditions and the following
15+
disclaimer in the documentation and/or other materials provided
16+
with the distribution.
17+
18+
* Neither the name of Matthew Wraith nor the names of other
19+
contributors may be used to endorse or promote products derived
20+
from this software without specific prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
PeerTrader
2+
----------
3+
4+
To get PeerTrader up and runnging:
5+
6+
### Clone peertrader, notescript, and groundhog-utils repositories
7+
8+
```
9+
$ git clone [email protected]:WraithM/notescript.git
10+
$ git clone [email protected]:WraithM/peertrader-backend.git
11+
$ git clone [email protected]:Soostone/groundhog-utils.git
12+
$ git clone [email protected]:ocharles/snaplet-ekg.git
13+
```
14+
15+
### Create a cabal sandbox in notescript
16+
17+
```
18+
$ cd notescript
19+
$ cabal sandbox init
20+
```
21+
22+
23+
### Create a sandbox in peertrader, link up notescript, and build
24+
25+
```
26+
$ cd ../peertrader
27+
$ cabal sandbox init
28+
$ cabal sandbox add-source ../notescript
29+
$ cabal sandbox add-source ../groundhog-utils
30+
$ cabal sandbox add-source ../snaplet-ekg
31+
$ cabal install -j
32+
```
33+
34+
(hint: It might be helpful to install Snap first. `cabal install snap -j`)
35+
36+
### Assuming that building was successful, create a peertrader database and load the schema.
37+
38+
Run peertrader (`.cabal-sandbox/bin/peertrader`), and the program will probably
39+
fail with various postgres errors. Allow peertrader to connect to postgres, and
40+
create the `snap_auth_user` table.
41+
42+
```
43+
$ createdb peertrader
44+
$ createuser -s -U postgres --interactive
45+
$ psql -d peertrader -U postgres < sql/createtables.sql
46+
```
47+
48+
### Configure your market data account
49+
50+
Open prosper.cfg:
51+
52+
```
53+
prosper {
54+
apiurl = "api.prosper.com"
55+
username = "[email protected]"
56+
password = "ProsperAPIPassword"
57+
58+
log {
59+
logger = "MarketData"
60+
enabled = false # You can enable market data to be logged to a file
61+
location = "log/prosper.log"
62+
level = "DEBUG"
63+
}
64+
}
65+
```
66+
67+
Open devel.cfg:
68+
69+
```
70+
groundhog {
71+
host = "localhost"
72+
name = "peertrader"
73+
user = "postgres"
74+
}
75+
76+
p2ppicks {
77+
apikey = "YourAPIKey"
78+
apisecret = "YourAPISecret"
79+
email = "yourp2ppicksemail"
80+
password = "p2ppickspassword"
81+
}
82+
```
83+
84+
### You're ready to run PeerTrader!
85+
86+
```
87+
$ .cabal-sandbox/bin/peertraderOps
88+
$ .cabal-sandbox/bin/peertrader -p 8000 +RTS -N
89+
```
90+
91+
92+
### Trademark notice
93+
94+
'PeerTrader' is a trademark of Deck Technologies, Inc.

Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

bench/RunBench.hs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
module Main where
2+
3+
import Criterion.Main
4+
5+
import Control.Exception as X
6+
import Control.Exception.Enclosed
7+
import Control.Monad.Reader
8+
9+
import Prosper
10+
import Prosper.Monad
11+
12+
someException :: SomeException -> IO ()
13+
someException _ = putStrLn "Caught some exception..."
14+
15+
someException' :: SomeException -> Prosper ()
16+
someException' _ = liftIO $ putStrLn "Caught some exception..."
17+
18+
noExceptions :: ProsperState -> IO ()
19+
noExceptions = runReaderT updateAllListings
20+
21+
oldExceptions :: ProsperState -> IO ()
22+
oldExceptions ps = runReaderT updateAllListings ps `X.catch` someException
23+
24+
enclosedExceptionsInside :: ProsperState -> IO ()
25+
enclosedExceptionsInside = runReaderT (updateAllListings `catchAny` someException')
26+
27+
enclosedExceptionsOutside :: ProsperState -> IO ()
28+
enclosedExceptionsOutside ps = runReaderT updateAllListings ps `catchAny` someException
29+
30+
foreverExceptions :: ProsperState -> IO ()
31+
foreverExceptions ps = replicateM_ 10 $ enclosedExceptionsOutside ps
32+
33+
-- | This uses recursion to handle an exception, it starts a new loop.
34+
exceptionLoop :: Int -> ProsperState -> IO ()
35+
exceptionLoop 0 _ = return ()
36+
exceptionLoop n ps = do
37+
runReaderT updateAllListings ps `catchAny` handleExceptionLoop
38+
exceptionLoop (n - 1) ps
39+
where
40+
handleExceptionLoop :: SomeException -> IO ()
41+
handleExceptionLoop _ = do
42+
putStrLn "Caught some exception..."
43+
exceptionLoop (n - 1) ps
44+
45+
main :: IO ()
46+
main = do
47+
ps <- initializeProsper "prosper.cfg"
48+
defaultMain
49+
[ bgroup "update"
50+
[ bench "Update" (replicateM_ 10 $ noExceptions ps)
51+
]
52+
, bgroup "exceptions"
53+
[ bench "No exception handling" (noExceptions ps)
54+
, bench "Old exception handling" (oldExceptions ps)
55+
, bench "Enclosed exceptions: forever inside" (enclosedExceptionsInside ps)
56+
, bench "Enclosed exceptions: forever outside" (enclosedExceptionsOutside ps)
57+
]
58+
, bgroup "loop"
59+
[ bench "Forever" (foreverExceptions ps)
60+
, bench "Exception loop" (exceptionLoop 10 ps)
61+
]
62+
]

0 commit comments

Comments
 (0)