This API is part of a crypto trading application that aggregates prices from different exchanges and stores the best price for each symbol.
- Java
- SQL
- Spring Boot
- Maven
To run this project, you need to have Java and Maven installed on your machine.
- Clone the repository:
git clone https://github.com/bchooxg/cryptoTrading.git
- Navigate to the project directory:
cd cryptoTrading
- Build the project:
mvn clean install
- Run the application:
mvn spring-boot:run
Fetches the latest price for a given currency pair.
symbol
: The currency pair for which to fetch the latest price. This should be a string like "BTCUSDT" or "ETHUSDT".
Returns a JSON object with the latest price information for the specified currency pair. The object has the following properties:
symbol
: The currency pair.bidPrice
: The highest price that a buyer is willing to pay for an asset.askPrice
: The lowest price that a seller is willing to accept for an asset.exchange
: The exchange where the best price was found.timestamp
: The time when the price was fetched.
Response:
{
"symbol": "BTCUSDT",
"bidPrice": 45000.00,
"askPrice": 45010.00,
"exchange": "Binance",
"timestamp": "2022-03-01T10:00:00"
}
Fetches all trades.
Returns a JSON array with all the trades. Each object in the array has the following properties:
id
: The unique identifier of the trade.username
: The username of the user who made the trade.symbol
: The currency pair that was traded.quantity
: The quantity of the currency that was traded.price
: The price at which the trade was made.timestamp
: The time when the trade was made.
Request:
GET /trades
Response:
[
{
"id": 1,
"username": "bchooxg",
"symbol": "BTCUSDT",
"quantity": 0.1,
"price": 45000.00,
"timestamp": "2022-03-01T10:00:00"
},
...
]
Fetches all trades made by a specific user.
username
: The username of the user whose trades you want to fetch.
Returns a JSON array with all the trades made by the specified user. Each object in the array has the same properties as described in the GET /trades
endpoint.
Request:
GET /trades/bchooxg
Response:
[
{
"id": 1,
"username": "bchooxg",
"symbol": "BTCUSDT",
"quantity": 0.1,
"price": 45000.00,
"timestamp": "2022-03-01T10:00:00"
},
...
]
Creates a new trade.
The request body should be a JSON object with the following properties:
username
: The username of the user who is making the trade.symbol
: The currency pair that is being traded.quantity
: The quantity of the currency that is being traded.
Returns a JSON object with the details of the trade that was created. The object has the same properties as described in the GET /trades
endpoint.
Request:
POST /trades
Content-Type: application/json
{
"username": "bchooxg",
"symbol": "BTCUSDT",
"quantity": 0.1,
}
Response:
{
"id": 2,
"username": "bchooxg",
"symbol": "BTCUSDT",
"quantity": 0.1,
"price": 45000.00, -- Will take the current best price available
"timestamp": "2022-03-01T10:05:00"
}
Fetches all wallets associated with a specific user.
userName
: The username of the user whose wallets you want to fetch.
Returns a JSON array with all the wallets associated with the specified user. Each object in the array has the following properties:
id
: The unique identifier of the wallet.username
: The username of the user who owns the wallet.currency
: The type of currency stored in the wallet.balance
: The balance of the wallet.
Request:
GET /wallets/bchooxg
Response:
[
{
"id": 1,
"username": "bchooxg",
"currency": "BTC",
"balance": 0.5
},
{
"id": 2,
"username": "bchooxg",
"currency": "ETH",
"balance": 10
},
...
]
Fetches user information by username.
username
: The username of the user whose information you want to fetch.
Returns a JSON object with the user's information. The object has the following properties:
id
: The unique identifier of the user.username
: The username of the user.email
: The email of the user.registeredAt
: The date and time when the user registered.
Request:
GET /users/bchooxg
Response:
{
"id": 1,
"username": "bchooxg",
"email": "bchooxg@example.com",
"registeredAt": "2022-01-01T00:00:00"
}
The application runs a scheduled task every 10 seconds to fetch prices from Binance and Huobi, determine the best price for each symbol, and store it in the database.
The application uses a SQL database to store the best prices. The database configuration can be found in the application.properties
file.
Remember to replace the placeholder text with the actual information about your project.