forked from Petersoj/alpaca-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountConfigurationEndpoint.java
63 lines (56 loc) · 2.36 KB
/
AccountConfigurationEndpoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package net.jacobpeterson.alpaca.rest.endpoint;
import net.jacobpeterson.alpaca.model.endpoint.accountconfiguration.AccountConfiguration;
import net.jacobpeterson.alpaca.rest.AlpacaClient;
import net.jacobpeterson.alpaca.rest.AlpacaClientException;
import net.jacobpeterson.alpaca.util.okhttp.JSONBodyBuilder;
import okhttp3.HttpUrl;
import okhttp3.Request;
import static com.google.common.base.Preconditions.checkNotNull;
import static net.jacobpeterson.alpaca.util.gson.GsonUtil.GSON;
/**
* {@link AlpacaEndpoint} for
* <a href="https://alpaca.markets/docs/api-documentation/api-v2/account-configuration/">Account Configuration</a>.
*/
public class AccountConfigurationEndpoint extends AlpacaEndpoint {
/**
* Instantiates a new {@link AccountConfigurationEndpoint}.
*
* @param alpacaClient the {@link AlpacaClient}
*/
public AccountConfigurationEndpoint(AlpacaClient alpacaClient) {
super(alpacaClient, "account/configurations");
}
/**
* Returns the {@link AccountConfiguration}.
*
* @return the {@link AccountConfiguration}
*
* @throws AlpacaClientException thrown for {@link AlpacaClientException}s
*/
public AccountConfiguration get() throws AlpacaClientException {
HttpUrl.Builder urlBuilder = alpacaClient.urlBuilder()
.addPathSegments(endpointPathSegment);
Request request = alpacaClient.requestBuilder(urlBuilder.build())
.get()
.build();
return alpacaClient.requestObject(request, AccountConfiguration.class);
}
/**
* Sets the {@link AccountConfiguration}.
*
* @param accountConfiguration the {@link AccountConfiguration}
*
* @return the updated {@link AccountConfiguration}
*
* @throws AlpacaClientException thrown for {@link AlpacaClientException}s
*/
public AccountConfiguration set(AccountConfiguration accountConfiguration) throws AlpacaClientException {
checkNotNull(accountConfiguration);
HttpUrl.Builder urlBuilder = alpacaClient.urlBuilder()
.addPathSegments(endpointPathSegment);
Request request = alpacaClient.requestBuilder(urlBuilder.build())
.patch(new JSONBodyBuilder(GSON.toJson(accountConfiguration)).build())
.build();
return alpacaClient.requestObject(request, AccountConfiguration.class);
}
}