|
1 | | -package com.binance.api.client; |
2 | | - |
3 | | -import com.binance.api.client.impl.*; |
4 | | -import com.binance.api.client.config.BinanceApiConfig; |
5 | | -import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; |
6 | | - |
7 | | -/** |
8 | | - * A factory for creating BinanceApi client objects. |
9 | | - */ |
10 | | -public class BinanceApiClientFactory { |
11 | | - |
12 | | - /** |
13 | | - * API Key |
14 | | - */ |
15 | | - private String apiKey; |
16 | | - |
17 | | - /** |
18 | | - * Secret. |
19 | | - */ |
20 | | - private String secret; |
21 | | - |
22 | | - /** |
23 | | - * Instantiates a new binance api client factory. |
24 | | - * |
25 | | - * @param apiKey the API key |
26 | | - * @param secret the Secret |
27 | | - */ |
28 | | - private BinanceApiClientFactory(String apiKey, String secret) { |
29 | | - this.apiKey = apiKey; |
30 | | - this.secret = secret; |
31 | | - BinanceApiConfig.useTestnet = false; |
32 | | - BinanceApiConfig.useTestnetStreaming = false; |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * Instantiates a new binance api client factory. |
37 | | - * |
38 | | - * @param apiKey the API key |
39 | | - * @param secret the Secret |
40 | | - * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
41 | | - * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
42 | | - */ |
43 | | - private BinanceApiClientFactory(String apiKey, String secret, boolean useTestnet, boolean useTestnetStreaming) { |
44 | | - this(apiKey, secret); |
45 | | - if (useTestnet) { |
46 | | - BinanceApiConfig.useTestnet = true; |
47 | | - BinanceApiConfig.useTestnetStreaming = useTestnetStreaming; } |
48 | | - } |
49 | | - |
50 | | - /** |
51 | | - * New instance. |
52 | | - * |
53 | | - * @param apiKey the API key |
54 | | - * @param secret the Secret |
55 | | - * |
56 | | - * @return the binance api client factory |
57 | | - */ |
58 | | - public static BinanceApiClientFactory newInstance(String apiKey, String secret) { |
59 | | - return new BinanceApiClientFactory(apiKey, secret); |
60 | | - } |
61 | | - |
62 | | - /** |
63 | | - * New instance with optional Spot Test Network endpoint. |
64 | | - * |
65 | | - * @param apiKey the API key |
66 | | - * @param secret the Secret |
67 | | - * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
68 | | - * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
69 | | - * |
70 | | - * @return the binance api client factory. |
71 | | - */ |
72 | | - public static BinanceApiClientFactory newInstance(String apiKey, String secret, boolean useTestnet, boolean useTestnetStreaming) { |
73 | | - return new BinanceApiClientFactory(apiKey, secret, useTestnet, useTestnetStreaming); |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * New instance without authentication. |
78 | | - * |
79 | | - * @return the binance api client factory |
80 | | - */ |
81 | | - public static BinanceApiClientFactory newInstance() { |
82 | | - return new BinanceApiClientFactory(null, null); |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * New instance without authentication and with optional Spot Test Network endpoint. |
87 | | - * |
88 | | - * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
89 | | - * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
90 | | - * |
91 | | - * @return the binance api client factory. |
92 | | - */ |
93 | | - public static BinanceApiClientFactory newInstance(boolean useTestnet, boolean useTestnetStreaming) { |
94 | | - return new BinanceApiClientFactory(null, null, useTestnet, useTestnetStreaming); |
95 | | - } |
96 | | - |
97 | | - /** |
98 | | - * Creates a new synchronous/blocking REST client. |
99 | | - */ |
100 | | - public BinanceApiRestClient newRestClient() { |
101 | | - return new BinanceApiRestClientImpl(apiKey, secret); |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * Creates a new asynchronous/non-blocking REST client. |
106 | | - */ |
107 | | - public BinanceApiAsyncRestClient newAsyncRestClient() { |
108 | | - return new BinanceApiAsyncRestClientImpl(apiKey, secret); |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * Creates a new asynchronous/non-blocking Margin REST client. |
113 | | - */ |
114 | | - public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() { |
115 | | - return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret); |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Creates a new synchronous/blocking Margin REST client. |
120 | | - */ |
121 | | - public BinanceApiMarginRestClient newMarginRestClient() { |
122 | | - return new BinanceApiMarginRestClientImpl(apiKey, secret); |
123 | | - } |
124 | | - |
125 | | - /** |
126 | | - * Creates a new web socket client used for handling data streams. |
127 | | - */ |
128 | | - public BinanceApiWebSocketClient newWebSocketClient() { |
129 | | - return new BinanceApiWebSocketClientImpl(getSharedClient()); |
130 | | - } |
131 | | - |
132 | | - /** |
133 | | - * Creates a new synchronous/blocking Swap REST client. |
134 | | - */ |
135 | | - public BinanceApiSwapRestClient newSwapRestClient() { |
136 | | - return new BinanceApiSwapRestClientImpl(apiKey, secret); |
137 | | - } |
138 | | -} |
| 1 | +package com.binance.api.client; |
| 2 | + |
| 3 | +import com.binance.api.client.impl.*; |
| 4 | +import com.binance.api.client.config.BinanceApiConfig; |
| 5 | +import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; |
| 6 | + |
| 7 | +/** |
| 8 | + * A factory for creating BinanceApi client objects. |
| 9 | + */ |
| 10 | +public class BinanceApiClientFactory { |
| 11 | + |
| 12 | + /** |
| 13 | + * API Key |
| 14 | + */ |
| 15 | + private String apiKey; |
| 16 | + |
| 17 | + /** |
| 18 | + * Secret. |
| 19 | + */ |
| 20 | + private String secret; |
| 21 | + |
| 22 | + /** |
| 23 | + * Instantiates a new binance api client factory. |
| 24 | + * |
| 25 | + * @param apiKey the API key |
| 26 | + * @param secret the Secret |
| 27 | + */ |
| 28 | + private BinanceApiClientFactory(String apiKey, String secret) { |
| 29 | + this.apiKey = apiKey; |
| 30 | + this.secret = secret; |
| 31 | + BinanceApiConfig.useTestnet = false; |
| 32 | + BinanceApiConfig.useTestnetStreaming = false; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Instantiates a new binance api client factory. |
| 37 | + * |
| 38 | + * @param apiKey the API key |
| 39 | + * @param secret the Secret |
| 40 | + * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
| 41 | + * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
| 42 | + */ |
| 43 | + private BinanceApiClientFactory(String apiKey, String secret, boolean useTestnet, boolean useTestnetStreaming) { |
| 44 | + this(apiKey, secret); |
| 45 | + if (useTestnet) { |
| 46 | + BinanceApiConfig.useTestnet = true; |
| 47 | + BinanceApiConfig.useTestnetStreaming = useTestnetStreaming; } |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * New instance. |
| 52 | + * |
| 53 | + * @param apiKey the API key |
| 54 | + * @param secret the Secret |
| 55 | + * |
| 56 | + * @return the binance api client factory |
| 57 | + */ |
| 58 | + public static BinanceApiClientFactory newInstance(String apiKey, String secret) { |
| 59 | + return new BinanceApiClientFactory(apiKey, secret); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * New instance with optional Spot Test Network endpoint. |
| 64 | + * |
| 65 | + * @param apiKey the API key |
| 66 | + * @param secret the Secret |
| 67 | + * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
| 68 | + * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
| 69 | + * |
| 70 | + * @return the binance api client factory. |
| 71 | + */ |
| 72 | + public static BinanceApiClientFactory newInstance(String apiKey, String secret, boolean useTestnet, boolean useTestnetStreaming) { |
| 73 | + return new BinanceApiClientFactory(apiKey, secret, useTestnet, useTestnetStreaming); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * New instance without authentication. |
| 78 | + * |
| 79 | + * @return the binance api client factory |
| 80 | + */ |
| 81 | + public static BinanceApiClientFactory newInstance() { |
| 82 | + return new BinanceApiClientFactory(null, null); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * New instance without authentication and with optional Spot Test Network endpoint. |
| 87 | + * |
| 88 | + * @param useTestnet true if endpoint is spot test network URL; false if endpoint is production spot API URL. |
| 89 | + * @param useTestnetStreaming true for spot test network websocket streaming; false for no streaming. |
| 90 | + * |
| 91 | + * @return the binance api client factory. |
| 92 | + */ |
| 93 | + public static BinanceApiClientFactory newInstance(boolean useTestnet, boolean useTestnetStreaming) { |
| 94 | + return new BinanceApiClientFactory(null, null, useTestnet, useTestnetStreaming); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Creates a new synchronous/blocking REST client. |
| 99 | + */ |
| 100 | + public BinanceApiRestClient newRestClient() { |
| 101 | + return new BinanceApiRestClientImpl(apiKey, secret); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Creates a new asynchronous/non-blocking REST client. |
| 106 | + */ |
| 107 | + public BinanceApiAsyncRestClient newAsyncRestClient() { |
| 108 | + return new BinanceApiAsyncRestClientImpl(apiKey, secret); |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Creates a new asynchronous/non-blocking Margin REST client. |
| 113 | + */ |
| 114 | + public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() { |
| 115 | + return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Creates a new synchronous/blocking Margin REST client. |
| 120 | + */ |
| 121 | + public BinanceApiMarginRestClient newMarginRestClient() { |
| 122 | + return new BinanceApiMarginRestClientImpl(apiKey, secret); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Creates a new web socket client used for handling data streams. |
| 127 | + */ |
| 128 | + public BinanceApiWebSocketClient newWebSocketClient() { |
| 129 | + return new BinanceApiWebSocketClientImpl(getSharedClient()); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Creates a new synchronous/blocking Swap REST client. |
| 134 | + */ |
| 135 | + public BinanceApiSwapRestClient newSwapRestClient() { |
| 136 | + return new BinanceApiSwapRestClientImpl(apiKey, secret); |
| 137 | + } |
| 138 | +} |
0 commit comments