Skip to content

Wraecca/cinch-server

Repository files navigation

cinch-server

API

Type

  • All decimal type and Uint256 Solidity type are represented as string in JSON.
  • All date type are in ISO 8601 format. EX: 2018-07-16T06:23:59.281Z
  • Errors will result in HTTP errors.

Paging

  • Some of the list APIs support paging. When paging is enabled, two more parameters are added in Request to control paging:

    Param Description
    exclusiveStartKey (optional) Start sequence string. This is exclusive and can be retrieved in response header.
    limit (optional) The size of this page request. Default is 100.
  • After receiving the sesponse of a paging request, two more HTTP Header are added to be used in next request.

    HTTP Header Description
    Paging-Last-Evaluated-Key Key can be used as next startKey. Not set if there is no more pages after.
    Paging-Count Count of items in this page.

Rest API Reference

GET /account/getBalance

Get trader's balance in Exchange

Param Description
address Trader's wallet address
tokenAddress Token's address in request
  • Result example:
"1.32132"

POST /account/withdraw

Withdraw from exchange. The request is a jSON object in request body and must be signed by ECDSA signature.

Param Description
exchangeContract Exchange contract's address.
address Trader's wallet address.
token Token address in request.
amount Token amount in request. In Solidity Uint256 and with 18 decimals.
nonce A Uint256 nonce number. Must be larger than last nonce submitted by this trader.
ecSignature A JSON object of ECDSA signature by signing hash. the hash is: keccak256(abi.encodePacked(exchangeContract, address, token, amount, nonce))
  • Request example:
{
    "exchangeContract": "0x48bacb9266a570d521063ef5dd96e61686dbe788",
    "address": "0x6d28fdd8f0295692eee024f53e42b6458f3f55f5",
    "token": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
    "amount": "10000000000000000000",
    "nonce": "1224714082993123",
    "ecSignature": { 
        "v": 28,
        "r": "0xd7c50ccb441d8379fb4a623be782f1b7068259a2ebdda52cb27b5ad561b9abad",
        "s": "0x64ad6ae62b7504dd24e2bd363c6763ad96a53a79009070a46fbf7a5c88864b0e"
    }
}

GET /market/listTrades

List all the trades for this token pair. This API supports paging and the list are sorted by time in descending order.

Param Description
baseTokenAddress Base token's address
quoteTokenAddress Quote token's address
  • Result example:
[{
    "time": "2018-07-16T06:23:59.281Z",
    "seq": "6IBUOavDxyKem5Bfn3zlEx",
    "price": "10",
    "size": "0.01",
    "side": "BUY"
}]

GET /market/getOrderbook

Get the orderbook for this token pair. The bids are sorted by price in descending order, and the asks are sorted by price in ascending order.

Param Description
baseTokenAddress Base token's address
quoteTokenAddress Quote token's address
  • Result example:
{
    "seq": "6IBUOavDxyKem5Bfn3zlEx",
    "bids": [
        [ "295.96", "4.39088265", 2 ] // price, amount, orders
        [ "295.94", "2", 1 ]
    ],
    "asks": [
        [ "295.97", "25.23542881", 12 ]
    ]
}

GET /order/listOrders

List trader's orders. This API supports paging and the list are sorted by time in descending order.

Param Description
address Trader's wallet address
  • Result example:
[{
    "maker": "0x6d28fdd8f0295692eee024f53e42b6458f3f55f5",
    "makerToken": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
    "makerTokenAmount": "10",
    "taker": "0xa944bd4b25c9f186a846fd5668941aa3d3b8425f",
    "takerToken": "0xd0a1e359811322d97991e03f863a0c30c2cf029c",
    "takerTokenAmount": "20",
    "expires": "2018-08-16T06:23:59.281Z",
    "orderHash": "0x90fe2af704b34e0224bf2299c838e04d4dcf1364",
    "created": "2018-07-16T06:23:59.281Z",
    "fillMakerTokenAmount": "0",
    "fillTakerTokenAmount": "0"
}]

GET /order/getOrder

Get trader's order. Return empty list if the order doesn't exist.

Param Description
orderHash Order hash.
  • Result example:
[{
    "maker": "0x6d28fdd8f0295692eee024f53e42b6458f3f55f5",
    "makerToken": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
    "makerTokenAmount": "10",
    "taker": "0xa944bd4b25c9f186a846fd5668941aa3d3b8425f",
    "takerToken": "0xd0a1e359811322d97991e03f863a0c30c2cf029c",
    "takerTokenAmount": "20",
    "expires": "2018-08-16T06:23:59.281Z",
    "orderHash": "0x90fe2af704b34e0224bf2299c838e04d4dcf1364",
    "created": "2018-07-16T06:23:59.281Z",
    "fillMakerTokenAmount": "0",
    "fillTakerTokenAmount": "0"
}]

POST /order/addOrder

Submit an order to exchange. The request is a jSON object in request body and must be signed by ECDSA signature.

Param Description
exchangeContract Exchange contract's address.
maker Trader's wallet address.
makerToken Token address in offer.
makerTokenAmount Token amount in offer. In Solidity Uint256 and with 18 decimals.
taker Must be "0" for now.
takerToken Token address in request.
takerTokenAmount Token amount in request. In Solidity Uint256 and with 18 decimals.
nonce A Uint256 nonce number. Must be larger than last nonce submitted by this trader.
expires Order expiration in Epoch time.
ecSignature A JSON object of ECDSA signature by signing hash. the hash is: keccak256(abi.encodePacked(exchangeContract, maker, taker, makerToken, takerToken, makerTokenAmount, takerTokenAmount, expires, nonce))
  • Request example:
{
    "exchangeContract": "0x48bacb9266a570d521063ef5dd96e61686dbe788",
    "maker": "0x6d28fdd8f0295692eee024f53e42b6458f3f55f5",
    "makerToken": "0xc4375b7de8af5a38a93548eb8453a498222c4ff2",
    "makerTokenAmount": "10000000000000000000",
    "taker": "0xa944bd4b25c9f186a846fd5668941aa3d3b8425f",
    "takerToken": "0xd0a1e359811322d97991e03f863a0c30c2cf029c",
    "takerTokenAmount": "20000000000000000000",
    "nonce": "1224714082993123",
    "expires": 1524714082993,
    "ecSignature": { 
        "v": 28,
        "r": "0xd7c50ccb441d8379fb4a623be782f1b7068259a2ebdda52cb27b5ad561b9abad",
        "s": "0x64ad6ae62b7504dd24e2bd363c6763ad96a53a79009070a46fbf7a5c88864b0e"
    }
}

POST /order/cancelOrder

Cancel an order in exchange. The request is a jSON object in request body and must be signed by ECDSA signature.

Param Description
orderHash Order hash.
address Trader's wallet address.
nonce A Uint256 nonce number. Must be larger than last nonce submitted by this trader.
ecSignature A JSON object of ECDSA signature by signing hash. the hash is: keccak256(abi.encodePacked(orderHash, address, nonce))
  • Request example:
{
    "orderHash": "0x48bacb9266a570d521063ef5dd96e61686dbe78848bacb9266a570d521063ef5",
    "address": "0x6d28fdd8f0295692eee024f53e42b6458f3f55f5",
    "nonce": "1224714082993123",
    "ecSignature": { 
        "v": 28,
        "r": "0xd7c50ccb441d8379fb4a623be782f1b7068259a2ebdda52cb27b5ad561b9abad",
        "s": "0x64ad6ae62b7504dd24e2bd363c6763ad96a53a79009070a46fbf7a5c88864b0e"
    }
}

POST /contract/create

Create scheduled spreads and options. The expiration time will be set at tomorrow 5pm PST. (only in DEV Environment)

POST /contract/settle

Settle spreads and options that have already expired today. (only in DEV Environment)

Websocket API Reference

API endpoint

DEV: ws://localhost:5000/websocket

Subscription

Send a Subscribe command to subscribe any channel.

{
    "type": "subscribe",
    "channels": "trade.0xa212E8e15eC1545200feAfEe9870F2Bf48D49FEE.0x6Bc3d8281c4DE70455dcC5F5E71B5b51d8b378E3,orderbook.0xa212E8e15eC1545200feAfEe9870F2Bf48D49FEE.0x6Bc3d8281c4DE70455dcC5F5E71B5b51d8b378E3"
}

Channel: Trades

Real time trade update.

Channel: trade.$targetToken.$baseToken

Message:

{
    "channel": "trade.0xa212E8e15eC1545200feAfEe9870F2Bf48D49FEE.0x6Bc3d8281c4DE70455dcC5F5E71B5b51d8b378E3",
    "data": {
        "seq": "6IBUOavDxyKem5Bfn3zlEx",
        "time": "2018-07-16T06:23:59.281Z",
        "price": "1.2",
        "size": "0.5",
        "side": "BUY"
    }
}

Channel: Orderbook

Real time orderbook update.

Channel: orderbook.$targetToken.$baseToken

Message:

{
    "channel": "orderbook.0xa212E8e15eC1545200feAfEe9870F2Bf48D49FEE.0x6Bc3d8281c4DE70455dcC5F5E71B5b51d8b378E3",
    "data": {
        "seq": "6IBUOavDxyKem5Bfn3zlEx",
        "asks": [],
        "bids": ["0.6","0.3",1] // price, amount, orders
    }
}

If the amount and orders are 0, this orderbookEntry is marked as deleted.

Configuration

In ~/.gradle/gradle.properties

#cinch
cinch.production.cinchPrivateKey=
cinch.production.marketMakerPrivateKey=
cinch.staging.cinchPrivateKey=
cinch.staging.marketMakerPrivateKey=
cinch.test.cinchPrivateKey=
cinch.test.marketMakerPrivateKey=

Run dev server

  1. Start local dynamoDB (in another shell)

    cd dynamodb_local_2016-05-17/
    sh start-dev.sh
  2. Start ganache-cli (in another shell)

    cd ../cinch-contract/
    sh start-ganache-dev.sh
    sh copy-relayer.sh (in another shell)
  3. Run redis server (in another shell)

    brew install redis (only once)
    redis-server
  4. Run local server

    sh start-dev DEV
  5. Initialize DB

    > curl -X POST http://localhost:5000/dynamoDB/migrate 
  6. Create Spreads & Options

    > curl -X POST http://localhost:5000/contract/create 
  7. Start auto orders

    > curl -X POST http://localhost:5000/marketmaker/start
  8. Stop auto orders

    > curl -X POST http://localhost:5000/marketmaker/stop
  9. List orderbook

    > curl http://localhost:5000/market/getOrderbook?baseTokenAddress=0xE8B00Cce394eeEB4E1b31b4471205BE5BeFfBdC6&quoteTokenAddress=0x83846Fef969bd2AD61FD5EcBF97bF6D8dd2ee0E5

Run Unit Tests

  1. Start local dynamoDB

    cd dynamodb_local_2016-05-17/
    sh start-test.sh
  2. Start ganache-cli

    cd ../cinch-contract/
    sh start-ganache-test.sh
    sh copy-relayer.sh (in another commant line environment)
  3. Run unit tests

    ../gradlew test

Staging server

http://cinch-relayer-dev2.us-east-1.elasticbeanstalk.com/account/getBalance?address=0x6d28fdd8f0295692eee024f53e42b6458f3f55f5&tokenAddress=0xc4375b7de8af5a38a93548eb8453a498222c4ff2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages