diff --git a/docs/rapport_Anthonioz_Benjamin.docx b/docs/rapport_Anthonioz_Benjamin.docx deleted file mode 100644 index 88775984b60cc4047619f64b1d6371fdc2a52f65..0000000000000000000000000000000000000000 Binary files a/docs/rapport_Anthonioz_Benjamin.docx and /dev/null differ diff --git a/testApi/media/image1.jpg b/testApi/media/image1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d885c710084a2a1e79d08fe32170a848c446e3a1 Binary files /dev/null and b/testApi/media/image1.jpg differ diff --git a/testApi/media/image10.png b/testApi/media/image10.png new file mode 100644 index 0000000000000000000000000000000000000000..c54e9f12095393c11f695b235c86175b69b3af6f Binary files /dev/null and b/testApi/media/image10.png differ diff --git a/testApi/media/image2.wmf b/testApi/media/image2.wmf new file mode 100644 index 0000000000000000000000000000000000000000..16c24b590748ed1a212df1aadbc92f2eeaa320a5 Binary files /dev/null and b/testApi/media/image2.wmf differ diff --git a/testApi/media/image3.png b/testApi/media/image3.png new file mode 100644 index 0000000000000000000000000000000000000000..331f1e224714b9b82ad1c6984de64678b062efa5 Binary files /dev/null and b/testApi/media/image3.png differ diff --git a/testApi/media/image4.png b/testApi/media/image4.png new file mode 100644 index 0000000000000000000000000000000000000000..4704574503c2b32f5ea521b440c026ebb3c71627 Binary files /dev/null and b/testApi/media/image4.png differ diff --git a/testApi/media/image5.png b/testApi/media/image5.png new file mode 100644 index 0000000000000000000000000000000000000000..fbd67bcb405cf15ca37eb6e478738bf9cb2df1cb Binary files /dev/null and b/testApi/media/image5.png differ diff --git a/testApi/media/image6.png b/testApi/media/image6.png new file mode 100644 index 0000000000000000000000000000000000000000..535276c9ea2071ffff645569c5e00efd1b5b0e1e Binary files /dev/null and b/testApi/media/image6.png differ diff --git a/testApi/media/image7.png b/testApi/media/image7.png new file mode 100644 index 0000000000000000000000000000000000000000..e26195bb6743334cd3c85088ff1f2beef6630566 Binary files /dev/null and b/testApi/media/image7.png differ diff --git a/testApi/media/image8.png b/testApi/media/image8.png new file mode 100644 index 0000000000000000000000000000000000000000..4df4cb81c89d0cb2dfdd2404206e9a1ce654c2e7 Binary files /dev/null and b/testApi/media/image8.png differ diff --git a/testApi/media/image9.png b/testApi/media/image9.png new file mode 100644 index 0000000000000000000000000000000000000000..b7debc9506d88fe03b1362ab1d612bc633cf3ea2 Binary files /dev/null and b/testApi/media/image9.png differ diff --git a/testApi/src/main/java/com/example/testapi/controller/ApiController.java b/testApi/src/main/java/com/example/testapi/controller/ApiController.java index 403533c93f25419aeddd8b33efed1ba34df0ea97..e1076ec32155f34545c616f75b51943d3e48b594 100644 --- a/testApi/src/main/java/com/example/testapi/controller/ApiController.java +++ b/testApi/src/main/java/com/example/testapi/controller/ApiController.java @@ -44,6 +44,7 @@ public class ApiController { @PostMapping("/sendDates") public Map<String, Object> sendDates(@RequestBody DateRange json) throws InterruptedException, com.fasterxml.jackson.core.JsonProcessingException { + System.out.println("POST /sendDates"); System.out.println("Dates received: " + json.getStartDate() + " - " + json.getEndDate()); this.dateRange = new DateRange(json.getStartDate(), json.getEndDate()); return Collections.emptyMap(); diff --git a/testApi/src/main/java/com/example/testapi/model/Candle.java b/testApi/src/main/java/com/example/testapi/model/Candle.java index 58aba428e8767014aff7ee475a9d2d8c37a93b91..68d67887303ba1a44ebd45385b51f11f2ef4d0d3 100644 --- a/testApi/src/main/java/com/example/testapi/model/Candle.java +++ b/testApi/src/main/java/com/example/testapi/model/Candle.java @@ -1,14 +1,13 @@ package com.example.testapi.model; public class Candle { - + private final long time; private final double open; private final double high; private final double low; private final double close; - -// private final long closeTime; + private final long closeTime; // private double volume; // private double assetVolume; // private int nbTrades; @@ -22,7 +21,7 @@ public class Candle { this.high = highPrice; this.low = lowPrice; this.close = closePrice; -// this.closeTime = closeTime; + this.closeTime = closeTime/1000; } public long getTime() { @@ -45,7 +44,19 @@ public class Candle { return close; } -// public long getCloseTime() { -// return closeTime; -// } + public long getCloseTime() { + return closeTime; + } + + public double checkprice(double price) { + if (price > this.getHigh()) { + return this.getHigh(); + } + else if (price < this.getLow()) { + return this.getLow(); + } + else { + return price; + } + } } diff --git a/testApi/src/main/java/com/example/testapi/model/DateRange.java b/testApi/src/main/java/com/example/testapi/model/DateRange.java index eed3030967e61765c81daecf43822672a3ea0d72..e43e0323e28895ec54012db3f72a8cdc199a8ccc 100644 --- a/testApi/src/main/java/com/example/testapi/model/DateRange.java +++ b/testApi/src/main/java/com/example/testapi/model/DateRange.java @@ -30,6 +30,7 @@ public class DateRange { this.endDate = endDate; } + public long getTimestampStartDate() { return this.dateToTimestamp(this.startDate); } @@ -38,8 +39,17 @@ public class DateRange { return this.dateToTimestamp(this.endDate); } - public long dateToTimestamp(String date) { + public long getTimestampEndDateInSeconds() { + return this.dateToTimestampInSec(this.endDate); + } + + private long dateToTimestamp(String date) { LocalDate localDate = LocalDate.parse(date); return localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(); } + + private long dateToTimestampInSec(String date) { + return this.dateToTimestamp(date) / 1000; + } + } diff --git a/testApi/src/main/java/com/example/testapi/model/Interval.java b/testApi/src/main/java/com/example/testapi/model/Interval.java index 0200a8daf0e46319f1942eaada4141ba9f51ad0d..4a96e5ca1e5493727981e6487b447aee315f067d 100644 --- a/testApi/src/main/java/com/example/testapi/model/Interval.java +++ b/testApi/src/main/java/com/example/testapi/model/Interval.java @@ -21,19 +21,9 @@ public class Interval { } public void nextSecond() { - this.deltaTime += 1000; + this.deltaTime += 1; } - public double checkprice(double price) { - if (price > this.currentCandle.getHigh()) { - return this.currentCandle.getHigh(); - } - else if (price < this.currentCandle.getLow()) { - return this.currentCandle.getLow(); - } - else { - return price; - } - } + } diff --git a/testApi/src/main/java/com/example/testapi/service/ApiService.java b/testApi/src/main/java/com/example/testapi/service/ApiService.java index ddb2ea7ec5d15787c07d5675567349f04e406929..b39c8fea49c05a6c9dd90295cc77f21eb71bbc2c 100644 --- a/testApi/src/main/java/com/example/testapi/service/ApiService.java +++ b/testApi/src/main/java/com/example/testapi/service/ApiService.java @@ -48,7 +48,9 @@ public class ApiService { System.out.println("La date de fin ne peut pas être avant la date de début"); return Optional.empty(); } + System.out.println("in"); try { + System.out.println("in try"); List<List<Object>> jsonCandles = null; while (startTime < endTime) { @@ -63,6 +65,7 @@ public class ApiService { .queryParam("limit", 1000) .toUriString(); String response = restTemplate.getForObject(url, String.class); + System.out.println("reponse binance : " + response); ObjectMapper objectMapper = new ObjectMapper(); jsonCandles = objectMapper.readValue(response, new TypeReference<List<List<Object>>>() {}); @@ -107,8 +110,10 @@ public class ApiService { List<List<Object>> jsonCandles = optJsonCandles.orElse(null); if (jsonCandles != null) { this.simulateurService.setCandles(deserializeCandles(jsonCandles)); + System.out.println("init list candles sim"); } else { + System.out.println("null json candles"); return null; } } @@ -118,6 +123,7 @@ public class ApiService { // } // this.initCandles(startDate, endDate); // this.candlesJson = objectMapper.writeValueAsString(this.simulateurService.getCandles()); + System.out.println("return list"); return this.simulateurService.getCandles(); } diff --git a/testApi/src/main/java/com/example/testapi/service/SimulateurService.java b/testApi/src/main/java/com/example/testapi/service/SimulateurService.java index 96f180ceebba62229613c69d10b7336d513bda5c..3226dd06cce7142aeeb22a1f98f47611c4dce6ef 100644 --- a/testApi/src/main/java/com/example/testapi/service/SimulateurService.java +++ b/testApi/src/main/java/com/example/testapi/service/SimulateurService.java @@ -75,6 +75,11 @@ public class SimulateurService { value += tmp; } System.out.println("x : " + x); + for (int i = 0; i < x_tab.length; i++) { + System.out.print(i + " : " + x_tab[i]); + } + System.out.println(); +// System.out.println("x tab : { " + x_tab[0] + ", " + x_tab[1] + ", " + x_tab[2] + ", " + x_tab[3] + "}"); System.out.println("res approx : " + value); return new Price(x, value); } @@ -86,7 +91,7 @@ public class SimulateurService { * priceOHLC valeur de OHLC * @param interval */ - public void taskEachSec(Interval interval) { + public void taskEachSec(Interval interval, long[] timestamps, double[] priceOHLC) { // long x = interval.getCurrentCandle().getTime() + this.interval.getDeltaTime(); // long[] x_tab = {}; // float[] y = {}; @@ -95,32 +100,64 @@ public class SimulateurService { // System.out.println("delta time : " + x); Candle currentCandle = interval.getCurrentCandle(); long currentTimestamp = currentCandle.getTime() + interval.getDeltaTime(); - long[] timestamps = generateRandomTimstamps(4, currentCandle.getTime(), currentCandle.getTime() + 15 * 60 * 1000 - 1); - double[] priceOHLC = randomPositionsOHLC(currentCandle); - this.prices.add(this.approximatePrice(timestamps, priceOHLC, currentTimestamp)); + Price tmpPrice = this.approximatePrice(timestamps, priceOHLC, currentTimestamp); + this.prices.add(new Price(tmpPrice.getTime(), interval.getCurrentCandle().checkprice(tmpPrice.getValue()))); interval.nextSecond(); - System.out.println("delta time : " + currentTimestamp); +// System.out.println("delta time : " + currentTimestamp); } public double[] randomPositionsOHLC(Candle currentCandle) { - double[] priceOHLC = new double[4]; - priceOHLC[0] = currentCandle.getOpen(); - if (this.rnd.nextBoolean()) { - priceOHLC[1] = currentCandle.getHigh(); - priceOHLC[2] = currentCandle.getLow(); + double[] priceOHLC; + if (currentCandle.getLow() == currentCandle.getOpen() && currentCandle.getHigh() == currentCandle.getClose() || currentCandle.getHigh() == currentCandle.getOpen() && currentCandle.getLow() == currentCandle.getClose()) { + priceOHLC = new double[] {currentCandle.getOpen(), currentCandle.getClose()}; + } + else if (currentCandle.getLow() == currentCandle.getOpen() || currentCandle.getLow() == currentCandle.getClose()) { + priceOHLC = new double[] {currentCandle.getOpen(), currentCandle.getHigh(), currentCandle.getClose()}; + } + else if (currentCandle.getHigh() == currentCandle.getOpen() || currentCandle.getHigh() == currentCandle.getClose()) { + priceOHLC = new double[] {currentCandle.getOpen(), currentCandle.getLow(), currentCandle.getClose()}; } else { - priceOHLC[1] = currentCandle.getLow(); - priceOHLC[2] = currentCandle.getHigh(); + priceOHLC = new double[4]; + priceOHLC[0] = currentCandle.getOpen(); + if (this.rnd.nextBoolean()) { + priceOHLC[1] = currentCandle.getHigh(); + priceOHLC[2] = currentCandle.getLow(); + } + else { + priceOHLC[1] = currentCandle.getLow(); + priceOHLC[2] = currentCandle.getHigh(); + } + priceOHLC[3] = currentCandle.getClose(); } - priceOHLC[3] = currentCandle.getClose(); return priceOHLC; } - public long[] generateRandomTimstamps(int nbTimestampToGenerate, long startTimestamp, long endTimestamp) { - long[] timestamps = new long[nbTimestampToGenerate]; - for (int i = 0; i < nbTimestampToGenerate; i++) { - timestamps[i] = generateRandomTimstamp(startTimestamp, endTimestamp); + public long[] generateRandomTimstamps(long startTimestamp, long endTimestamp, Candle currentCandle) { + int nbTimestamps; + if (currentCandle.getLow() == currentCandle.getOpen() && currentCandle.getHigh() == currentCandle.getClose() || currentCandle.getHigh() == currentCandle.getOpen() && currentCandle.getLow() == currentCandle.getClose()) { + nbTimestamps = 2; + } + else if (currentCandle.getLow() == currentCandle.getOpen() || currentCandle.getHigh() == currentCandle.getOpen() || currentCandle.getHigh() == currentCandle.getClose() || currentCandle.getLow() == currentCandle.getClose()) { + nbTimestamps = 3; + } + else { + nbTimestamps = 4; + } + long rndTimestamp1 = generateRandomTimstamp(startTimestamp, endTimestamp-2); + long rndTimestamp2 = generateRandomTimstamp(rndTimestamp1, endTimestamp-1); + long[] timestamps; + if (nbTimestamps == 2) { + timestamps = new long[]{startTimestamp, endTimestamp}; + } + else if (nbTimestamps == 3) { + timestamps = new long[]{startTimestamp, rndTimestamp1, endTimestamp}; + } + else if (rndTimestamp2 == endTimestamp) { + timestamps = new long[]{startTimestamp, rndTimestamp1, endTimestamp}; + } + else { + timestamps = new long[]{startTimestamp, rndTimestamp1, rndTimestamp2, endTimestamp}; } return timestamps; } @@ -131,19 +168,30 @@ public class SimulateurService { public List<Price> getPricesForPeriod(DateRange period) { final int nbTimestamp15Min = 15 * 60; - long endTime = period.getTimestampEndDate(); + long endTime = period.getTimestampEndDateInSeconds(); int indexCurrentCandle = 0; Candle currentCandle = candles.get(indexCurrentCandle); Interval interval = new Interval(currentCandle); + long[] timestamps = generateRandomTimstamps(currentCandle.getTime(), currentCandle.getCloseTime(), currentCandle); + double[] priceOHLC = randomPositionsOHLC(currentCandle); while (interval.getCurrentCandle().getTime() < endTime) { // Boucle qui simule 15 min for (int i = 0; i < nbTimestamp15Min; i++) { - taskEachSec(interval); + taskEachSec(interval, timestamps, priceOHLC); } indexCurrentCandle++; +// System.out.println("indexCurrentCandle : " + indexCurrentCandle); +// System.out.println("endTime : " + endTime); +// System.out.println("current time : " + interval.getCurrentCandle().getTime()); +// System.out.println("len candles : "+ candles.size()); +// System.out.println(); currentCandle = candles.get(indexCurrentCandle); interval = new Interval(currentCandle); + timestamps = generateRandomTimstamps(currentCandle.getTime(), currentCandle.getCloseTime(), currentCandle); + priceOHLC = randomPositionsOHLC(currentCandle); } +// System.out.println("len prices : " + prices.size()); +// System.out.println("return prices"); return this.prices; } } diff --git a/testApi/src/main/resources/application.properties b/testApi/src/main/resources/application.properties index b1be6e462ceb1e7d19874b5497687b654d6ac4fe..3d260fd75701d49fb75e989a2d3a167fb7aed9d4 100644 --- a/testApi/src/main/resources/application.properties +++ b/testApi/src/main/resources/application.properties @@ -4,3 +4,4 @@ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSou simulateur.ApproximationPeriod=1 +server.tomcat.max-http-form-post-size=10000000 \ No newline at end of file diff --git a/testApi/src/main/resources/static/js/api.js b/testApi/src/main/resources/static/js/api.js index cacc9351197d6569c235a461d42b7ca62d0a3f3f..664ecc472b945a8c5c4b6b89bfe35027425b734a 100644 --- a/testApi/src/main/resources/static/js/api.js +++ b/testApi/src/main/resources/static/js/api.js @@ -5,7 +5,7 @@ const API_URL = BASE_URL + "api"; export function callApi(route, method = "GET", data = null) { - let options = { + let options = { method: method, headers: { "Accept": "application/json", @@ -27,11 +27,14 @@ export function callApi(route, method = "GET", data = null) // }); console.log("ok"); + // console.log(data); displayChart(data); break; case "/prices": console.log("ok prices"); + console.log(data); + console.log("data affichées"); displayPriceChart(data); break; diff --git a/testApi/src/main/resources/static/js/graph.js b/testApi/src/main/resources/static/js/graph.js index fc32aae62f84825044106056dc06e4dabaf57d28..54b72ace7869912b677c2f855b6bfa9f0587aee9 100644 --- a/testApi/src/main/resources/static/js/graph.js +++ b/testApi/src/main/resources/static/js/graph.js @@ -7,7 +7,7 @@ import { callApi } from './api.js'; window.onload = async function() { await callApi("/btcusdt"); - // await callApi("/prices"); + await callApi("/prices"); }; export function displayChart(data) { @@ -23,30 +23,37 @@ export function displayChart(data) { }); console.log(data); candlestickSeries.setData(data); - + chart.timeScale().applyOptions({ + timeVisible: true, + secondsVisible: true, + fixLeftEdge: true, + fixRightEdge: true, + }); chart.timeScale().fitContent(); } -export function displayPriceChart() { +export function displayPriceChart(data) { const chartOptions = { layout: { textColor: 'black', background: { type: 'solid', color: 'white' } } }; - console.log(data); + // console.log(data); const chart = createChart(document.getElementById('container'), chartOptions); const areaSeries = chart.addSeries(AreaSeries, { upColor: '#26a69a', downColor: '#ef5350', borderVisible: false, wickUpColor: '#26a69a', wickDownColor: '#ef5350', }); - areaSeries.setData([ - { time: '2024-12-22', value: 94000 }, - { time: '2024-12-23', value: 95000 }, - { time: '2024-12-24', value: 96000 }, - { time: '2024-12-25', value: 97000 }, - { time: '2024-12-26', value: 98000 }, - { time: '2024-12-27', value: 99000 }, - { time: '2024-12-28', value: 100000 }, - { time: '2024-12-29', value: 102000 }, - { time: '2024-12-30', value: 101000 }, - { time: '2024-12-31', value: 110000 }, - ]); + areaSeries.setData(data); + chart.timeScale().applyOptions({ + timeVisible: true, + secondsVisible: true, + fixLeftEdge: true, + fixRightEdge: true, + }); chart.timeScale().fitContent(); } +function initChart() { + const chartOptions = { + // width: 800, + // height: 400, + layout: { textColor: 'black', background: { type: 'solid', color: 'white' } } }; + chart = createChart(document.getElementById('container'), chartOptions); +}