Online broker API - ptal/online-broker GitHub Wiki

API

Here we describe the API of the online-broker app.

Errors

An error is always of the form:

{
  "status": "KO",
  "name": "malformed-request",
  "description": "Last request you sent was malformed."
}

Subscribe

  • HTTP Request type: POST
  • Address: localhost:9000/signup
  • Note: Handled by the securesocial API at the HTTP level (a cookie is used to trace the user).

Authenticate

  • HTTP Request type: POST
  • Address: localhost:9000/authenticate/:provider
  • Note: Handled by the securesocial API at the HTTP level (a cookie is used to trace the user).

Currencies' names and acronyms

  • HTTP Request type: GET
  • Address: localhost:9000/api/currencies/names
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "currencies":[
    {"acronym":"AED","fullName":"United Arab Emirates Dirham"},
    {"acronym":"AFN","fullName":"Afghan Afghani"},
    ...
  ]
}
  • Errors:
    • see generic errors.

Currencies' rates

  • HTTP Request type: GET
  • Address: localhost:9000/api/currencies
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "rates":[
    {"currency":"AED","rate":"3.67266"},
    {"currency":"AFN","rate":"56.164975"},
    ...
  ]
}
  • Errors:
    • see generic errors.

Money transfer

  • HTTP Request type: POST
  • Address: localhost:9000/api/transfer?id_token=IDTOKEN88762994
  • Request type: JSON
  • Request:
{
  "amount": 10.25
  "from": "USD",
  "to": "EUR"
}
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "from": {
    "currency": "USD",
    "amount": 40.5
  },
  "to": {
    "currency": "EUR",
    "amount": 10.25
  }
}
  • Errors:
    • see generic errors.
    • Not enough money:
  • Notes:
    • The request amount is in the "from" currency.
{
  "status": "KO",
  "name": "not-enough-money",
  "from": "USD",
  "from-amount": 5.3,
  "transfer-amount": 10.0
}

Accounts

  • HTTP Request type: GET
  • Address: localhost:9000/api/accounts
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "accounts": [
    {"currency":"USD","amount":"900.0"},
    {"currency":"EUR","amount":"100.0"},
    ...
  ]
}
  • Errors:
    • see generic errors.
  • Notes:
    • Accounts not listed are empty.

Open an account

  • HTTP Request type: POST
  • Address: localhost:9000/api/accounts/open
  • Request type: JSON
  • Request:
{
  "account-to-open": "EUR",
  "pay-with-account": "USD"
}
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "payWithAccount": {
    "currency": "USD",
    "amount": 40.5
  },
  "accountOpened": {
    "currency": "EUR",
    "amount": 0
  }
}
  • Errors:
    • see generic errors.
    • Not enough money to pay.
    • Account already opened.

Historic of a currency rate

  • HTTP Request type: GET
  • Address: localhost:9000/api/historic/rates/<currency-acronym>
  • Response type: JSON
  • Response:
{
  "status": "OK",
  "historic": [
    {"timestamp": 321564853, "rate": "150.5"},
    {"timestamp": 321564851, "rate": "150.2"},
    ...
  ]
}
  • Errors:
    • see generic errors.
    • Unknown acronym.