|
1 | 1 | package net.qtsurfer.api.sdk; |
2 | 2 |
|
3 | 3 | import net.qtsurfer.api.client.api.BacktestingApi; |
| 4 | +import net.qtsurfer.api.client.api.ExchangeApi; |
4 | 5 | import net.qtsurfer.api.client.binary.ExchangeBinaryDownloads; |
5 | 6 | import net.qtsurfer.api.client.invoker.ApiClient; |
6 | 7 | import net.qtsurfer.api.client.invoker.ApiException; |
| 8 | +import net.qtsurfer.api.client.model.Exchange; |
| 9 | +import net.qtsurfer.api.client.model.InstrumentDetail; |
7 | 10 | import net.qtsurfer.api.client.model.ResultMap; |
8 | 11 | import net.qtsurfer.api.sdk.errors.QTSDownloadError; |
| 12 | +import net.qtsurfer.api.sdk.errors.QTSError; |
9 | 13 | import net.qtsurfer.api.sdk.internal.HttpStrategyCompileClient; |
10 | 14 | import net.qtsurfer.api.sdk.workflows.BacktestWorkflow; |
11 | 15 |
|
12 | 16 | import java.io.InputStream; |
| 17 | +import java.util.List; |
13 | 18 | import java.util.Objects; |
14 | 19 | import java.util.concurrent.CompletableFuture; |
15 | 20 | import java.util.concurrent.ExecutorService; |
@@ -40,11 +45,14 @@ public final class QTSurfer { |
40 | 45 | private final QTSurferOptions options; |
41 | 46 | private final BacktestWorkflow backtestWorkflow; |
42 | 47 | private final ExchangeBinaryDownloads downloads; |
| 48 | + private final ExchangeApi exchangeApi; |
43 | 49 |
|
44 | | - private QTSurfer(QTSurferOptions options, BacktestWorkflow backtestWorkflow, ExchangeBinaryDownloads downloads) { |
| 50 | + private QTSurfer(QTSurferOptions options, BacktestWorkflow backtestWorkflow, |
| 51 | + ExchangeBinaryDownloads downloads, ExchangeApi exchangeApi) { |
45 | 52 | this.options = options; |
46 | 53 | this.backtestWorkflow = backtestWorkflow; |
47 | 54 | this.downloads = downloads; |
| 55 | + this.exchangeApi = exchangeApi; |
48 | 56 | } |
49 | 57 |
|
50 | 58 | public QTSurferOptions options() { return options; } |
@@ -84,6 +92,35 @@ public CompletableFuture<ResultMap> backtest(BacktestRequest request, BacktestOp |
84 | 92 | return backtestWorkflow.runFull(request, options); |
85 | 93 | } |
86 | 94 |
|
| 95 | + /** |
| 96 | + * List available exchanges on the platform. |
| 97 | + * |
| 98 | + * @throws QTSError on HTTP 4xx/5xx or transport failure |
| 99 | + */ |
| 100 | + public List<Exchange> exchanges() { |
| 101 | + try { |
| 102 | + return exchangeApi.getExchanges(); |
| 103 | + } catch (ApiException e) { |
| 104 | + throw new QTSError("exchanges call failed: " + describe(e), e); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * List instruments available on the given exchange, including data availability |
| 110 | + * and market info. |
| 111 | + * |
| 112 | + * @param exchangeId exchange identifier (e.g. {@code "binance"}) |
| 113 | + * @throws QTSError on HTTP 4xx/5xx or transport failure |
| 114 | + */ |
| 115 | + public List<InstrumentDetail> instruments(String exchangeId) { |
| 116 | + Objects.requireNonNull(exchangeId, "exchangeId"); |
| 117 | + try { |
| 118 | + return exchangeApi.getInstruments(exchangeId); |
| 119 | + } catch (ApiException e) { |
| 120 | + throw new QTSError("instruments call failed: " + describe(e), e); |
| 121 | + } |
| 122 | + } |
| 123 | + |
87 | 124 | /** |
88 | 125 | * Download one hour of raw tickers for an instrument as a streaming |
89 | 126 | * {@link InputStream}. Defaults to {@link DownloadFormat#LASTRA}; pass |
@@ -159,7 +196,8 @@ public QTSurfer build() { |
159 | 196 | ExecutorService exec = opts.executor() != null ? opts.executor() : ForkJoinPool.commonPool(); |
160 | 197 | BacktestWorkflow workflow = new BacktestWorkflow( |
161 | 198 | new HttpStrategyCompileClient(apiClient), backtestingApi, exec); |
162 | | - return new QTSurfer(opts, workflow, new ExchangeBinaryDownloads(apiClient)); |
| 199 | + return new QTSurfer(opts, workflow, new ExchangeBinaryDownloads(apiClient), |
| 200 | + new ExchangeApi(apiClient)); |
163 | 201 | } |
164 | 202 | } |
165 | 203 | } |
0 commit comments