Skip to content

Instantly share code, notes, and snippets.

@Kycermann
Last active April 29, 2021 21:18
Show Gist options
  • Save Kycermann/e55814364e9ff7c34df2642e5b44095a to your computer and use it in GitHub Desktop.
Save Kycermann/e55814364e9ff7c34df2642e5b44095a to your computer and use it in GitHub Desktop.

Authenticate

1. Link to /auth/discord

Redirects the client to the Discord OAuth flow.

This will redirect the user to /?session=

2. ?session=<SESSION>

If the session query parameter is supplied to any client page:

  1. Save the value in localStorage
  2. Remove session=<SESSION> from the URL

3. Supply ?session=<SESSION> to all API URLs

If this isn't supplied, the API will return status code 403.

For instance, you'd log out by calling GET /logout?session=<SESSION>

GET /logout

Invalidates the value.

Assets

GET /assets

Response

{
  valueCurrencyCode: string, # E.g. USD, GBP, EUR
  totalValue: string,

  currencies: [
    {
      name: string, # E.g. "United States Dollar", "Bitcoin"
      code: string, # E.g. USD, BTC,
      freeBalance: string,
      lockedBalance: string,
      totalBalance: string,
      totalValue: string, # E.g. 5 (currency determined by valueCurrencyCode)
    },
    ...
  ]
}

When viewing all assets, call this endpoint every 10 seconds to update the data. Show an indicator in the corner: countdown from 10 when waiting, or loading icon when fetching data.

GET /asset/<CURRENCY_CODE>

Response

{
  name: string, # E.g. "United States Dollar", "Bitcoin"
  freeBalance: string,
  lockedBalance: string,
  totalBalance: string,
  valueCurrencyCode: string, # E.g. USD, GBP, EUR
  totalValue: string, # E.g. 5 (currency determined by valueCurrencyCode),

  orders: [
    {
      id: string,
      type: "buy" | "sell",
      amount: string,
      rate: string | "market"
    }
  ]
}

When viewing a particular asset, call this endpoint every 10 seconds to update the data. Show an indicator in the corner: countdown from 10 when waiting, or loading icon when fetching data.

POST /order

Request

{
  type: "BUY" | "SELL"
  currency: string, # E.g. "BTC"
  amount: string,
  rate: string | "market"
}

Response

{
  orderId: string,
  message: "Order placed (or not, it depends)"
}

Once you get the response:

  1. Display the message as a toast
  2. Call GET /asset/<CURRENCY_CODE> to update the orders

DELETE /order/<ORDER_ID>

Response

{
  orderId: string,
  message: "Order placed (or not, it depends)"
}

GET /deposit/<CURRENCY_CODE>

Response

{
  address: string # Crypto address to send crypto currency to
}

GET /withdraw/<CURRENCY_CODE>

Request

{
  address: string # Crypto address to withdraw crypto currency to
  amount: string # How much to send, e.g. "12.345"
}

Response

{
  message: "Withdrawn, or not, depends really, just display this & refresh data"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment