this is repo hosts code for backend development for Liquify Trades, a trading journal which aims at improving trading perfomance
The swaggger documentation can be found at https://liquifytrades.herokuapp.com/docs
https://liquifytrades.herokuapp.com/login
Login takes email and password , then fetches user_id from the database. It then embeds user_id in the JWT token which is return.
To make a request to login route append formdata username which holds email address and also password
var formdata = new FormData();
formdata.append("username", "max@gmail.com");
formdata.append("password", "passkey");
var requestOptions = {
method: 'POST',
body: formdata,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/login", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Here is a sample output for successfull login. 200 Status code
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo0LCJleHAiOjcwNjIwMTAwNjh9.9ACMCnbTC8FWASr542oZ5UFdtg27B-6NSSm89ptdwBc",
"token_type": "bearer"
}
Incorrect email address or password returns a 403 forbidden status error.
https://liquifytrades.herokuapp.com/register
Register route takes POST request with a body containing user email and password then inserts this info in the database .
Sample Javascript code
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"email": "appmax@gmail.com",
"password": "passkey"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/register", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Here is the schema of the Body
{
"email": "app@gmail.com",
"password": "passkey"
}
Here is schema output for successful registration
{
"email": "appmax@gmail.com",
"user_id": 5
}
https://liquifytrades.herokuapp.com/journal
to create a new journal send a POST request with the following schema. Remember to attach the bearer token header in the request
{
"date": "2012-23-02"
}
A 201 status code is returned for a successsfull journal created. here is a sample reponse body.
{
"id": 23,
"date": "2012-12-34",
"user_id": 34
}
A sample request made in javascript
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5M3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"date": "2012-12-3"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/journal", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to view all users journal send a GET request to
https://liquifytrades.herokuapp.com/journal.
if the access_token header is validated , all users journals are returned with the following schema. 200 status code
[
{
"date": "sample date",
"user_id": 1,
"id": 1
},
]
to view a single journal details send a GET request to
https://liquifytrades.herokuapp.com/journal/journal_id_here
sample response
[
{
"date": "2022-09-21",
"user_id": 1,
"id": 1
},
{
"date": "2022-09-21",
"user_id": 1,
"id": 3
},
{
"date": "2012-12-03",
"user_id": 1,
"id": 6
}
]
here is a sample request to get all journals written in javascript fetch module
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/journal", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to delete a Journal send a DELETE request to
https://liquifytrades.herokuapp.com/journal/id_here
a 202 status code is returned with a null response
sample javascript code to delete a journal using javascript fetch module
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'DELETE',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/journal/6", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to get details of a single journal make a GET request to the endpoint https://liquifytrades.herokuapp.com/journal/id_here. Here is a sample response of a successful request
{
"date": "2022-09-21",
"id": 3,
"trades": [
{
"journal_id": 3,
"user_id": 1,
"open_time": "12:34:00",
"entry_price": 1.91155,
"stop_loss": 1.9115,
"notes": "EURUSD was bullish today, so took a counter trade",
"id": 2,
"symbol": "EURUSD",
"close_time": "13:32:00",
"close_price": 1.91134,
"take_profit": 2.6758
}
]
}
A sample javascript code for getting details of a single journal
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/journal/3", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to get all trades of a logged in user, send a GET request to the endpoint
https://liquifytrades.herokuapp.com/trade
Here is a sample response of successfull request with 200 status code
[
{
"open_time": "12:34:00",
"user_id": 1,
"journal_id": 2,
"entry_price": 1.91155,
"stop_loss": 1.9115,
"notes": "EURUSD was bullish today, so took a counter trade",
"id": 1,
"symbol": "EURUSD",
"close_time": "13:32:00",
"close_price": 1.91134,
"take_profit": 2.6758
},
{
"open_time": "12:34:00",
"user_id": 1,
"journal_id": 3,
"entry_price": 1.91155,
"stop_loss": 1.9115,
"notes": "EURUSD was bullish today, so took a counter trade",
"id": 2,
"symbol": "EURUSD",
"close_time": "13:32:00",
"close_price": 1.91134,
"take_profit": 2.6758
}
]
Here is sample request made with javascript fetch module
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/trade", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to create a trade make a POST request to the endpoint
https://liquifytrades.herokuapp.com/trade with the following body schema
Here is sample schema of the body to attach to the request
{
"user_id": 0,
"symbol": "string",
"open_time": "12:34",
"close_time": "23:34",
"entry_price": 0,
"close_price": 0,
"stop_loss": 0,
"take_profit": 0,
"notes": "string",
"journal_id": 0
}
A successful request returns a 202 status code with the following response body
{
"id": 3,
"symbol": "string",
"close_time": "23:34:00",
"close_price": 0,
"take_profit": 0,
"journal_id": 0,
"user_id": 0,
"open_time": "19:12:00",
"entry_price": 0,
"stop_loss": 0,
"notes": "string"
}
Here is sample javascript code for creating a trade
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"user_id": 0,
"symbol": "string",
"open_time": "19:12",
"close_time": "23:34",
"entry_price": 0,
"close_price": 0,
"stop_loss": 0,
"take_profit": 0,
"notes": "string",
"journal_id": 0
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/trade", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to get details of a single trade send a GET request to https://liquifytrades.herokuapp.com/trade/id_here Here is a sample response of successful request
{
"id": 1,
"symbol": "EURUSD",
"close_time": "13:32:00",
"close_price": 1.91134,
"take_profit": 2.6758,
"journal_id": 2,
"user_id": 1,
"open_time": "12:34:00",
"entry_price": 1.91155,
"stop_loss": 1.9115,
"notes": "EURUSD was bullish today, so took a counter trade"
}
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/trade/1", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
to edit a Trade send a PUT request to the following endpoint https://liquifytrades.herokuapp.com/trade with the following body WARNING: THIS ROUTE IS INCOMPLETE
to delete a trade send a DELETE request to the following endpoint https://liquifytrades.herokuapp.com/trade/trade_id A successful delete returns a 202 accepted status code with a null response Sample javascript code using fetch module
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHAiOjcwNjM5MzA3ODd9.uBXXYNGyKVqR1qAnu4fuEI9Embu2SdZHOIAcUMpKJg8");
var requestOptions = {
method: 'DELETE',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://liquifytrades.herokuapp.com/trade/1", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));