[Haskell-beginners] Critique My First Project - CampBX API Client
Pavan Rikhi
pavan.rikhi at gmail.com
Sat Jul 19 07:57:25 UTC 2014
Hiya, so I've spent the last 2 months or so learning Haskell. I've
finished the UPenn course, LYAH and a little bit of RWH.
I wanted to get a project going so I tried making an API client for the
CampBX Bitcoin Market[1]. I started out by following along with the
FPComplete Mailchimp API Tutorial[2].
I'm asking you beautiful people for any feedback on it so I can be sure
that I'm on the right track here, stuff like code style/idioms, project
layout, public interface, implementation, docs, ideas for new features,
anything you want to tell me, etc.:
https://github.com/prikhi/campbx-haskell
Typical usage would be something like this[3]:
main :: IO ()
main = do
cfg <- defaultCampBXConfig
_ <- runCampBX cfg $ do
totalAskVolume <- calculateAskVolume <$> getDepth
liftIO . putStrLn $ "Total Ask Volume: " ++ show totalAskVolume
return ()
calculateAskVolume :: Depth -> BTCAmount
calculateAskVolume depthList = sum . map askPrice . asks $ depthList
where askPrice (Ask (_, q)) = q
There are still some things I want to work on:
* Define Asks and Bids[4] using Record Syntax. The JSON[5] for a Bid/Ask
comes back as a 2 item Array but the generically derived instance[6]
expects an object. I haven't completely wrapped my head around Aeson's
Array parsing...
* Write tests. I'm imagining they would be more "given this JSON, make
sure the data structure is created correctly" instead of
property-based testing.
* Use something other than Doubles to represent Amounts + Prices. Is
there a standard library for accurate math with decimals(I need up to
8 decimal places)? I suppose I could always just use Integers to
represent Satoshis(the smallest subunit of bitcoins).
Also I tried adding "default-extensions: OverloadedStrings" to the
.cabal file and removing the pragmas from the source files, but the
package wouldn't build :(
[1] https://campbx.com/api.php
[2] https://www.fpcomplete.com/school/to-infinity-and-beyond/competition-winners/interfacing-with-restful-json-apis
[3] https://github.com/prikhi/campbx-haskell/blob/master/bin/CampBXMain.hs
[4] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L71
[5] http://sleepanarchy.com/p/K1wuSm
[6] https://github.com/prikhi/campbx-haskell/blob/master/src/Web/CampBX/Types.hs#L188
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: GnuPG Digital Signature
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140719/558b97cb/attachment.sig>
More information about the Beginners
mailing list