Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
runeksvendsen committed Nov 7, 2018
0 parents commit 3f37902
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
30 changes: 30 additions & 0 deletions LICENSE
@@ -0,0 +1,30 @@
Copyright Rune K. Svendsen (c) 2018

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Rune K. Svendsen nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
# REST API for [`crypto-depth`](https://github.com/runeksvendsen/crypto-depth) backend
20 changes: 20 additions & 0 deletions package.yaml
@@ -0,0 +1,20 @@
name: crypto-depth-backend-api
version: '0.1.0.0'
category: value
author: Rune K. Svendsen
maintainer: runesvend@gmail.com
copyright: CC0
license: BSD3
github: runeksvendsen/crypto-depth-backend-api
extra-source-files:
- README.md
library:
source-dirs: src
exposed-modules:
- CryptoDepth.Backend.Api
- CryptoDepth.Backend.Types
dependencies:
- base >=4.7 && <5
- servant
- aeson
- text
38 changes: 38 additions & 0 deletions src/CryptoDepth/Backend/Api.hs
@@ -0,0 +1,38 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
module CryptoDepth.Backend.Api where

import CryptoDepth.Backend.Types

import Servant.API
import qualified Data.Text as T


type Api = Numeraires :<|> SymSums :<|> SymPaths

-- | Which currencies can we measure volume in?
type Numeraires
= "numeraires"
:> Get '[JSON] [T.Text]

-- | Base path for sums and paths
type SymBase
= -- Which currency to measure volume in? (e.g. USD, EUR, GBP)
Capture "numeraire" T.Text
-- Slippage divisor (slippage_percent = 1/"slippage"). E.g. 100=1% slippage, 200=0.5%, 20=5% etc.
:> Capture "slippage" Word
-- Symbol in question (e.g BTC, ETH, LTC)
:> Capture "symbol" Sym

-- | Symbol sums
type SymSums
= SymBase
:> "sums"
:> Capture "page" Word
:> Get '[JSON] [SymSum]

-- | Symbol paths
type SymPaths
= SymBase
:> "paths"
:> Get '[JSON] BuySellPaths
55 changes: 55 additions & 0 deletions src/CryptoDepth/Backend/Types.hs
@@ -0,0 +1,55 @@
{-# LANGUAGE DeriveGeneric #-}
module CryptoDepth.Backend.Types where

import Data.Aeson
import GHC.Generics (Generic)
import qualified Data.Text as T
import Data.Word (Word64)
import Data.List.NonEmpty (NonEmpty)


type Venue = T.Text
type Sym = T.Text

-- |
data SymSum = SymSum
{ ssSymbol :: Sym
, ssBuyQty :: Word64
, ssSellQty :: Word64
} deriving (Show, Eq, Generic)

instance ToJSON SymSum where
toJSON = genericToJSON
defaultOptions { fieldLabelModifier = drop 2 }

instance FromJSON SymSum where
parseJSON = genericParseJSON
defaultOptions { fieldLabelModifier = drop 2 }

-- |
data SymPath = SymPath
{ spPath :: NonEmpty (Sym, Venue, Sym)
, spQty :: Word64
} deriving (Show, Eq, Generic)

instance ToJSON SymPath where
toJSON = genericToJSON
defaultOptions { fieldLabelModifier = drop 2 }

instance FromJSON SymPath where
parseJSON = genericParseJSON
defaultOptions { fieldLabelModifier = drop 2 }

-- |
data BuySellPaths = BuySellPaths
{ bspBuy :: [SymPath]
, bspSell :: [SymPath]
} deriving (Show, Eq, Generic)

instance ToJSON BuySellPaths where
toJSON = genericToJSON
defaultOptions { fieldLabelModifier = drop 3 }

instance FromJSON BuySellPaths where
parseJSON = genericParseJSON
defaultOptions { fieldLabelModifier = drop 3 }
8 changes: 8 additions & 0 deletions stack.yaml
@@ -0,0 +1,8 @@
resolver: lts-12.16

packages:
- .
- location:
git: https://github.com/runeksvendsen/crypto-depth.git
commit: 3cb03d051423dc720c8a8522ef5019e80fac8e04
extra-dep: true

0 comments on commit 3f37902

Please sign in to comment.