# Bare Bitcoin API

API for interacting with Bare Bitcoin. Most endpoints require authentication. Create API keys [here](https://barebitcoin.no/innlogget/profil/nokler). Read about API authentication [here](https://dev.barebitcoin.no/#authentication).

Version: 0.0.1

## Servers

Prod environment
```
https://api.bb.no
```

## Security

### apiKey

Public part of your API key. Starts with `bb/public/`.

Type: apiKey
In: header
Name: x-bb-api-key

### apiNonce

Nonce value. Used to ensure correct ordering of all API requests, as well as prevent attackers from being able to replay old requests. Can be set to any value, but needs to increase for each request. Recommendation is to use the current Unix timestamp in milliseconds.

Type: apiKey
In: header
Name: x-bb-api-nonce

### apiHmac

HMAC authentication for the API request, constructed using the corresponding secret value from your API key.

Type: apiKey
In: header
Name: x-bb-api-hmac

## Download OpenAPI description

[Bare Bitcoin API](https://dev.barebitcoin.no/_bundle/api/openapi.yaml)

## BitcoinTransferService

Transfer bitcoin in and out of the platform. Fetch information about past
 bitcoin transfers.

### Fetch bitcoin deposit destinations

 - [GET /v1/deposit-destinations/bitcoin](https://dev.barebitcoin.no/api/openapi/bitcointransferservice/bitcointransferservice_depositdestinations.md): Fetches bitcoin deposit destinations. These destinations are always valid,
 and can be used for receiving arbitrary amounts. Onchain addresses are refreshed
 every time a deposit is made, but all prior generated addresses are still valid.

### Create a new Lightning invoice

 - [POST /v1/deposit-destinations/bitcoin/invoice](https://dev.barebitcoin.no/api/openapi/bitcointransferservice/bitcointransferservice_newlightninginvoice.md): Creates a new BOLT11 Lightning invoice. Lightning invoices are requests to receive a specific
 amount of bitcoin within a set amount of time. If you don't a specific amount, consider
 using the destinations returned from /v1/deposit-destinations/bitcoin.

### Fetch a Lightning invoice

 - [GET /v1/deposit-destinations/bitcoin/invoice/{id}](https://dev.barebitcoin.no/api/openapi/bitcointransferservice/bitcointransferservice_getlightninginvoice.md): Fetches a Lightning invoice.

### Initiate withdrawal

 - [POST /v1/withdrawals/bitcoin](https://dev.barebitcoin.no/api/openapi/bitcointransferservice/bitcointransferservice_sendbitcoin.md): Initiates a bitcoin withdrawal. The transaction is not completed until
 it is confirmed by the network it is sent onto. A success response from
 this endpoint means the transaction was successfully initiated, but
 does not guarantee completion.

### Fetch withdrawal

 - [GET /v1/withdrawals/bitcoin/{withdrawalId}](https://dev.barebitcoin.no/api/openapi/bitcointransferservice/bitcointransferservice_getbitcoinwithdrawal.md): Fetches a bitcoin withdrawal.

## PublicService

Public endpoints that don't require authentication

### Fetch BTCNOK

 - [GET /v1/price/nok](https://dev.barebitcoin.no/api/openapi/publicservice/publicservice_price.md): Fetches the current BTCNOK price.

### Fetch volume statistics

 - [GET /v1/volume](https://dev.barebitcoin.no/api/openapi/publicservice/publicservice_volume.md): Returns statistics about the volume of BTCNOK trades.

### Fetch historic volume statistics

 - [GET /v1/volume/historic](https://dev.barebitcoin.no/api/openapi/publicservice/publicservice_volumehistoric.md)

## TaxService

### List tax transactions

 - [GET /v1/tax/transactions](https://dev.barebitcoin.no/api/openapi/taxservice/taxservice_listtaxtransactions.md): Lists tax-relevant transactions done by the user within the Bare Bitcoin platform.
 Note that this does NOT include any of the third party transactions imported into
 the platform tax calculator.

## TradingService

Execute and cancel orders. Fetch information about past orders.

### Fetch open orders

 - [GET /v1/orders](https://dev.barebitcoin.no/api/openapi/tradingservice/tradingservice_openorders.md): Fetches all open orders for the user. Open orders are orders that are
 not yet filled, and can be cancelled.

### Place a new order

 - [POST /v1/orders](https://dev.barebitcoin.no/api/openapi/tradingservice/tradingservice_neworder.md): Places a new order. If the endpoint returns with a 200 status, the order
 is successfully placed. If you're creating a market order, a trade is
 also created, and its ID is included in the response.

### Cancel an order

 - [DELETE /v1/orders/{orderId}](https://dev.barebitcoin.no/api/openapi/tradingservice/tradingservice_cancelorder.md): Cancel a pending order. If the order is already filled, an error will
 be returned. It is not possible to cancel market orders.

## UserService

Fetch information the authenticated user and its bitcoin accounts.

### Revoke consent for a specific OAuth2 application

 - [DELETE /v1/user/applications/consent/{clientId}](https://dev.barebitcoin.no/api/openapi/userservice/userservice_revokeconsent.md): This endpoint can be called with any valid OAuth2-obtained token

### Fetch bitcoin accounts

 - [GET /v1/user/bitcoin-accounts](https://dev.barebitcoin.no/api/openapi/userservice/userservice_listbitcoinaccounts.md): Lists the bitcoin accounts for the user. Each bitcoin account has a
 separate balance. Every bitcoin transaction (withdrawal, deposit, trade,
 bonus payout) affects the balance of exactly one bitcoin account.

### Fetch user fiat information

 - [GET /v1/user/fiat-account](https://dev.barebitcoin.no/api/openapi/userservice/userservice_getfiataccount.md): Fetches the fiat account. The fiat account for a user holds their NOK
 balance. Every user has exactly one fiat account. Other sub-accounts for a user
 only pertains to bitcoin holdings.

