Skip to content

Commit 19b24f0

Browse files
authored
Merge pull request #12 from coinbase-samples/jc-sdk-dev
update activities and orders support
2 parents 8138391 + 4a4088b commit 19b24f0

8 files changed

Lines changed: 316 additions & 0 deletions

src/main/java/com/coinbase/prime/activities/ActivitiesService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public interface ActivitiesService {
2525
ListActivitiesResponse listActivities(ListActivitiesRequest request) throws CoinbaseClientException, CoinbasePrimeException;
2626
GetActivityByActivityIdResponse getActivityByActivityId(GetActivityByActivityIdRequest request) throws CoinbaseClientException, CoinbasePrimeException;
2727
ListEntityActivitiesResponse listEntityActivities(ListEntityActivitiesRequest request) throws CoinbaseClientException, CoinbasePrimeException;
28+
GetEntityActivityByActivityIdResponse getEntityActivityByActivityId(GetEntityActivityByActivityIdRequest request) throws CoinbaseClientException, CoinbasePrimeException;
2829
}

src/main/java/com/coinbase/prime/activities/ActivitiesServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public GetActivityByActivityIdResponse getActivityByActivityId(GetActivityByActi
5050
new TypeReference<GetActivityByActivityIdResponse>() {});
5151
}
5252

53+
@Override
54+
public GetEntityActivityByActivityIdResponse getEntityActivityByActivityId(GetEntityActivityByActivityIdRequest request) throws CoinbasePrimeException {
55+
return this.request(
56+
HttpMethod.GET,
57+
String.format("/activities/%s", request.getActivityId()),
58+
null,
59+
List.of(200),
60+
new TypeReference<GetEntityActivityByActivityIdResponse>() {});
61+
}
62+
5363
@Override
5464
public ListEntityActivitiesResponse listEntityActivities(ListEntityActivitiesRequest request) throws CoinbasePrimeException {
5565
return this.request(
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.prime.model.activities;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
21+
public class GetEntityActivityByActivityIdRequest {
22+
@JsonProperty(required = true, value = "activity_id")
23+
private String activityId;
24+
25+
private GetEntityActivityByActivityIdRequest(Builder builder) {
26+
this.activityId = builder.activityId;
27+
}
28+
29+
public String getActivityId() {
30+
return activityId;
31+
}
32+
33+
public void setActivityId(String activityId) {
34+
this.activityId = activityId;
35+
}
36+
37+
public static class Builder {
38+
private String activityId;
39+
40+
public Builder activityId(String activityId) {
41+
this.activityId = activityId;
42+
return this;
43+
}
44+
45+
public GetEntityActivityByActivityIdRequest build() {
46+
return new GetEntityActivityByActivityIdRequest(this);
47+
}
48+
}
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.prime.model.activities;
18+
19+
public class GetEntityActivityByActivityIdResponse {
20+
private Activity activity;
21+
22+
public GetEntityActivityByActivityIdResponse() {
23+
}
24+
25+
public GetEntityActivityByActivityIdResponse(Builder builder) {
26+
this.activity = builder.activity;
27+
}
28+
29+
public Activity getActivity() {
30+
return activity;
31+
}
32+
33+
public void setActivity(Activity activity) {
34+
this.activity = activity;
35+
}
36+
37+
public static class Builder {
38+
private Activity activity;
39+
40+
public Builder activity(Activity activity) {
41+
this.activity = activity;
42+
return this;
43+
}
44+
45+
public GetEntityActivityByActivityIdResponse build() {
46+
return new GetEntityActivityByActivityIdResponse(this);
47+
}
48+
}
49+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.prime.model.orders;
18+
19+
import com.coinbase.core.errors.CoinbaseClientException;
20+
import com.coinbase.prime.common.PrimeListRequest;
21+
import com.coinbase.prime.model.common.Pagination;
22+
import com.fasterxml.jackson.annotation.JsonIgnore;
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
25+
import static com.coinbase.core.utils.Utils.isNullOrEmpty;
26+
27+
public class ListPortfolioFillsRequest extends PrimeListRequest {
28+
@JsonProperty("portfolio_id")
29+
@JsonIgnore
30+
private String portfolioId;
31+
32+
@JsonProperty("start_date")
33+
@JsonIgnore
34+
private String startDate;
35+
36+
@JsonProperty("end_date")
37+
@JsonIgnore
38+
private String endDate;
39+
40+
public ListPortfolioFillsRequest() {
41+
}
42+
43+
public ListPortfolioFillsRequest(Builder builder) {
44+
super(builder.cursor, builder.sortDirection, builder.limit);
45+
this.portfolioId = builder.portfolioId;
46+
this.startDate = builder.startDate;
47+
this.endDate = builder.endDate;
48+
}
49+
50+
public String getPortfolioId() {
51+
return portfolioId;
52+
}
53+
54+
public void setPortfolioId(String portfolioId) {
55+
this.portfolioId = portfolioId;
56+
}
57+
58+
public String getStartDate() {
59+
return startDate;
60+
}
61+
62+
public void setStartDate(String startDate) {
63+
this.startDate = startDate;
64+
}
65+
66+
public String getEndDate() {
67+
return endDate;
68+
}
69+
70+
public void setEndDate(String endDate) {
71+
this.endDate = endDate;
72+
}
73+
74+
public static class Builder {
75+
private String portfolioId;
76+
private String startDate;
77+
private String endDate;
78+
private String cursor;
79+
private String sortDirection;
80+
private Integer limit;
81+
82+
public Builder() {
83+
}
84+
85+
public Builder portfolioId(String portfolioId) {
86+
this.portfolioId = portfolioId;
87+
return this;
88+
}
89+
90+
public Builder startDate(String startDate) {
91+
this.startDate = startDate;
92+
return this;
93+
}
94+
95+
public Builder endDate(String endDate) {
96+
this.endDate = endDate;
97+
return this;
98+
}
99+
100+
public Builder pagination(Pagination pagination) {
101+
this.cursor = pagination.getNextCursor();
102+
this.sortDirection = pagination.getSortDirection();
103+
return this;
104+
}
105+
106+
public Builder limit(Integer limit) {
107+
this.limit = limit;
108+
return this;
109+
}
110+
111+
public ListPortfolioFillsRequest build() throws CoinbaseClientException {
112+
this.validate();
113+
return new ListPortfolioFillsRequest(this);
114+
}
115+
116+
public void validate() {
117+
if (isNullOrEmpty(this.portfolioId)) {
118+
throw new CoinbaseClientException("PortfolioId is required");
119+
}
120+
if (isNullOrEmpty(this.startDate)) {
121+
throw new CoinbaseClientException("StartDate is required");
122+
}
123+
124+
}
125+
}
126+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2025-present Coinbase Global, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.coinbase.prime.model.orders;
18+
19+
import com.coinbase.prime.model.common.Pagination;
20+
21+
public class ListPortfolioFillsResponse {
22+
private OrderFill[] fills;
23+
private Pagination pagination;
24+
25+
public ListPortfolioFillsResponse() {
26+
}
27+
28+
public ListPortfolioFillsResponse(Builder builder) {
29+
this.fills = builder.fills;
30+
this.pagination = builder.pagination;
31+
}
32+
33+
public OrderFill[] getFills() {
34+
return fills;
35+
}
36+
37+
public void setFills(OrderFill[] fills) {
38+
this.fills = fills;
39+
}
40+
41+
public Pagination getPagination() {
42+
return pagination;
43+
}
44+
45+
public void setPagination(Pagination pagination) {
46+
this.pagination = pagination;
47+
}
48+
49+
public static class Builder {
50+
private OrderFill[] fills;
51+
private Pagination pagination;
52+
53+
public Builder() {
54+
}
55+
56+
public Builder fills(OrderFill[] fills) {
57+
this.fills = fills;
58+
return this;
59+
}
60+
61+
public Builder pagination(Pagination pagination) {
62+
this.pagination = pagination;
63+
return this;
64+
}
65+
66+
public ListPortfolioFillsResponse build() {
67+
return new ListPortfolioFillsResponse(this);
68+
}
69+
}
70+
}

src/main/java/com/coinbase/prime/orders/OrdersService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public interface OrdersService {
2929
GetOrderByOrderIdResponse getOrderByOrderId(GetOrderByOrderIdRequest request) throws CoinbaseClientException, CoinbasePrimeException;
3030
CancelOrderResponse cancelOrder(CancelOrderRequest request) throws CoinbaseClientException, CoinbasePrimeException;
3131
ListOrderFillsResponse listOrderFills(ListOrderFillsRequest request) throws CoinbaseClientException, CoinbasePrimeException;
32+
ListPortfolioFillsResponse listPortfolioFills(ListPortfolioFillsRequest request) throws CoinbaseClientException, CoinbasePrimeException;
3233
}

src/main/java/com/coinbase/prime/orders/OrdersServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,14 @@ public ListOrderFillsResponse listOrderFills(ListOrderFillsRequest request) thro
9999
List.of(200),
100100
new TypeReference<ListOrderFillsResponse>() {});
101101
}
102+
103+
@Override
104+
public ListPortfolioFillsResponse listPortfolioFills(ListPortfolioFillsRequest request) throws CoinbasePrimeException {
105+
return this.request(
106+
HttpMethod.GET,
107+
String.format("/portfolios/%s/fills", request.getPortfolioId()),
108+
request,
109+
List.of(200),
110+
new TypeReference<ListPortfolioFillsResponse>() {});
111+
}
102112
}

0 commit comments

Comments
 (0)