Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3f37902
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# REST API for [`crypto-depth`](https://github.com/runeksvendsen/crypto-depth) backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resolver: lts-12.16 | ||
|
||
packages: | ||
- . | ||
- location: | ||
git: https://github.com/runeksvendsen/crypto-depth.git | ||
commit: 3cb03d051423dc720c8a8522ef5019e80fac8e04 | ||
extra-dep: true |