MCPcopy Index your code
hub / github.com/ccxt/ccxt / fetchOHLCV

Method fetchOHLCV

java/lib/src/main/java/io/github/ccxt/exchanges/OkxCore.java:2770–2893  ·  view source on GitHub ↗

@method @name okx#fetchOHLCV @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesticks @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesti

(Object symbol, Object... optionalArgs)

Source from the content-addressed store, hash-verified

2768 * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
2769 */
2770 public java.util.concurrent.CompletableFuture<Object> fetchOHLCV(Object symbol, Object... optionalArgs)
2771 {
2772
2773 return java.util.concurrent.CompletableFuture.supplyAsync(() -> {
2774
2775 Object timeframe = Helpers.getArg(optionalArgs, 0, "1m");
2776 Object since = Helpers.getArg(optionalArgs, 1, null);
2777 Object limit = Helpers.getArg(optionalArgs, 2, null);
2778 Object parameters = Helpers.getArg(optionalArgs, 3, new java.util.HashMap<String, Object>() {{}});
2779 (this.loadMarkets()).join();
2780 Object market = this.market(symbol);
2781 Object paginate = false;
2782 var paginateparametersVariable = this.handleOptionAndParams(parameters, "fetchOHLCV", "paginate");
2783 paginate = ((java.util.List<Object>) paginateparametersVariable).get(0);
2784 parameters = ((java.util.List<Object>) paginateparametersVariable).get(1);
2785 if (Helpers.isTrue(paginate))
2786 {
2787 return (this.fetchPaginatedCallDeterministic("fetchOHLCV", symbol, since, limit, timeframe, parameters, 200)).join();
2788 }
2789 Object priceType = this.safeString(parameters, "price");
2790 Object isMarkOrIndex = this.inArray(priceType, new java.util.ArrayList<Object>(java.util.Arrays.asList("mark", "index")));
2791 parameters = this.omit(parameters, "price");
2792 Object options = this.safeDict(this.options, "fetchOHLCV", new java.util.HashMap<String, Object>() {{}});
2793 Object timezone = this.safeString(options, "timezone", "UTC");
2794 Object limitIsUndefined = (Helpers.isEqual(limit, null));
2795 if (Helpers.isTrue(Helpers.isEqual(limit, null)))
2796 {
2797 limit = 100; // default 100, max 300
2798 } else
2799 {
2800 Object maxLimit = ((Helpers.isTrue(isMarkOrIndex))) ? 100 : 300; // default 300, only 100 if 'mark' or 'index'
2801 limit = Helpers.mathMin(limit, maxLimit);
2802 }
2803 Object duration = this.parseTimeframe(timeframe);
2804 Object bar = this.safeString(this.timeframes, timeframe, timeframe);
2805 if (Helpers.isTrue(Helpers.isTrue((Helpers.isEqual(timezone, "UTC"))) && Helpers.isTrue((Helpers.isGreaterThanOrEqual(duration, 21600)))))
2806 {
2807 bar = Helpers.add(bar, ((String)timezone).toLowerCase());
2808 }
2809 final Object finalBar = bar;
2810 final Object finalLimit = limit;
2811 Object request = new java.util.HashMap<String, Object>() {{
2812 put( "instId", Helpers.GetValue(market, "id") );
2813 put( "bar", finalBar );
2814 put( "limit", finalLimit );
2815 }};
2816 Object defaultType = "Candles";
2817 if (Helpers.isTrue(!Helpers.isEqual(since, null)))
2818 {
2819 Object now = this.milliseconds();
2820 Object durationInMilliseconds = Helpers.multiply(duration, 1000);
2821 // switch to history candles if since is past the cutoff for current candles
2822 Object historyBorder = Helpers.subtract(now, (Helpers.multiply((Helpers.subtract(1440, 1)), durationInMilliseconds)));
2823 if (Helpers.isTrue(Helpers.isLessThan(since, historyBorder)))
2824 {
2825 defaultType = "HistoryCandles";
2826 Object maxLimit = ((Helpers.isTrue(isMarkOrIndex))) ? 100 : 300;
2827 limit = Helpers.mathMin(limit, maxLimit);

Callers

nothing calls this directly

Calls 15

getArgMethod · 0.95
isTrueMethod · 0.95
isEqualMethod · 0.95
mathMinMethod · 0.95
isGreaterThanOrEqualMethod · 0.95
addMethod · 0.95
GetValueMethod · 0.95
multiplyMethod · 0.95
subtractMethod · 0.95
isLessThanMethod · 0.95
mathMaxMethod · 0.95
addElementToObjectMethod · 0.95

Tested by

no test coverage detected