Skip to content

Commit aea9821

Browse files
committed
june update
1 parent cee7d57 commit aea9821

File tree

84 files changed

+4403
-3994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4403
-3994
lines changed

README.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,49 +32,61 @@ String apiSecret = "21b12401";
3232
CryptomarketRestClient client = new CryptomarketRestClientImpl(apiKey, apiSecret);
3333

3434
// get all currencies
35-
Map<String, Currency> currencies = client.getCurrencies(null);
35+
Map<String, Currency> currencies = client.getCurrencies(null, null);
3636

3737
// get some symbols
38-
List<String> symbolIDs = new ArrayList<String>(Arrays.asList("eoseth","ethbtc"));
38+
List<String> symbolIDs = new ArrayList<String>(Arrays.asList("EOSETH","ETHBTC"));
3939
Map<String, Symbol> symbols = client.getSymbols(symbolIDs);
4040

4141
// get an order book
42-
OrderBook orderbook = client.getOrderbookOfSymbol("eoseth");
42+
OrderBook orderbook = client.getOrderbookBySymbol("EOSETH");
4343

4444
// get some candles
45-
List<String> symbols = new ArrayList<String>(Arrays.asList("eoseth", "ethbtc"));
45+
List<String> symbols = new ArrayList<String>(Arrays.asList("EOSETH", "ETHBTC"));
4646
Map<String, List<Candle>> candles = client.getCandles(symbols, Period._4_HOURS, Sort.ASC, null, null, null);
4747

48-
// get your account balances
49-
List<Balance> balances = client.getAccountBalance();
48+
// get your wallet balances
49+
List<Balance> walletBalances = client.getWalletBalances();
5050

51-
// get your trading balances
52-
List<Balance> balances = client.getTradingBalance();
51+
// get your spot trading balances
52+
List<Balance> spotBalances = client.getSpotTradingBalances();
5353

5454
// move balance from account to trading
55-
String result = client.transferBetweenTradingAndAccountBalance('eth', '3.2', TransferType.BANK_TO_EXCHANGE);
55+
String result = client.transferBetweenWalletAndExchange(
56+
'ETH',
57+
'3.2',
58+
AccountType.WALLET,
59+
AccountType.SPOT);
5660

5761
// get your active orders
58-
List<Order> orders = client.getActiveOrders('eoseth');
59-
62+
List<Order> orders = client.getAllActiveSpotOrders('ESOETH');
6063

6164
// create a new order
6265
Order order = client.createOrder(new ParamsBuilder()
6366
.symbol("EOSETH")
6467
.side(Side.SELL)
6568
.quantity("2")
66-
.price("100000")
69+
.price("10000")
6770
.timeInForce(TimeInForce.DAY));
6871
```
6972

7073
## Using the ParamsBuilder
7174

72-
most client methods have a version that accepts a ParamBuilder. This class makes easier to pass parameters.
75+
most client methods have a version that accepts a ParamBuilder. This class makes easier to pass parameters, and is expected to recieve the same parameters as the parameterized version.
7376

7477
```java
7578
import com.cryptomarket.params.ParamsBuilder;
7679

80+
List<String> symbols = new ArrayList<String>(Arrays.asList("EOSETH", "ETHBTC"));
7781
// get candles
82+
Map<String, List<Candle>> candles = client.getCandles(
83+
symbols,
84+
Period._4_HOURS,
85+
Sort.ASC,
86+
null,
87+
null,
88+
null);
89+
// is equivalent to:
7890
Map<String, List<Candle>> candles client.getCandles(new ParamsBuilder()
7991
.symbols(symbols)
8092
.period(Period._4_HOURS)
@@ -105,13 +117,17 @@ There are three websocket clients, the market data client, the spot trading clie
105117
The market data client requires no authentication, while the spot trading client and the wallet client do require it.
106118

107119
All websocket methods accept a `BiConsumer` with the first argument being the resulting data of the request, and the second
108-
argument a possible exception of type `CryptomarketSDKException`. If there is an exception the data is null: `(null, exception) -> {...}`.nd if
109-
there is no exception, the exception argument is null: `(data,null) -> {...}`
120+
argument a possible exception of type `CryptomarketSDKException`. If there is an exception the data is null: `(null, exception) -> {...}`. And if there is no exception, the exception argument is null: `(data,null) -> {...}`
110121

111122
websocket subscriptions take a second `BiConsumer` that takes the subscription data as the first argument, and the notification type as the second. The notification type is of type NotificationType, and is either SNAPSHOT, NOTIFICATION or DATA. there are functions to test the type of notification:
112123

124+
If there is an error in a notification of a subscription, a special notification type is used, to check it call `notificationType.isError()`, in such case, the data is null. This holds for all subscriptions
125+
113126
```java
114127
BiConsumer<List<Report>, NotificationType> biConsumerExample = (data, notificationType) -> {
128+
if (notificationType.isError()) {
129+
System.out.println("an error ocurred");
130+
}
115131
if (notificationType.isSnapshot()) {
116132
System.out.println("is a snapshot notification");
117133
}
@@ -124,9 +140,23 @@ BiConsumer<List<Report>, NotificationType> biConsumerExample = (data, notificati
124140
}
125141
```
126142

127-
The documentation of a specific subscriptions explains with of this types of
143+
The documentation of a specific subscription explains which types of
128144
notification uses.
129145

146+
### Websocket Lifetime
147+
There are hooks for the connection, close and faiule of the websockets.
148+
149+
On an authenticated client, onConnect is called after authentication, which happens automatically after connection.
150+
```java
151+
// ws client lifetime
152+
CryptomarketWSSpotTradingClient wsClient;
153+
wsClient = new CryptomarketWSSpotTradingClientImpl(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
154+
wsClient.onConnect(() -> System.out.println("connecting"));
155+
wsClient.onClose(reason -> System.out.println("closing: "+ reason));
156+
wsClient.onFailure(t -> t.printStackTrace());
157+
wsClient.connect();
158+
```
159+
130160
### MarketDataClient
131161

132162
Example of use of the market data client

src/main/java/com/cryptomarket/params/ArgNames.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ArgNames {
5151
public static final String VOLUME = "volume";
5252
public static final String FROM_CURRENCY = "from_currency";
5353
public static final String TO_CURRENCY = "to_currency";
54-
public static final String TRANSFER_BY = "by";
54+
public static final String IDENTIFY_BY = "by";
5555
public static final String IDENTIFIER = "identifier";
5656
public static final String ORDER_ID = "order_id";
5757
public static final String ORDER_LIST_ID = "order_list_id";
@@ -65,4 +65,12 @@ public class ArgNames {
6565
public static final String DESCRIPTION = "description";
6666
public static final String SUB_ACCOUNT_ID = "sub_account_id";
6767
public static final String TRANSFER_TYPE = "type";
68+
public static final String SUBSCRIPTION_MODE = "mode";
69+
public static final String NETWORK_CODE = "network_code";
70+
public static final String TARGET_CURRENCY = "target_currency";
71+
public static final String PREFERRED_NETWORK = "preferred_network";
72+
public static final String DEPTH = "depth";
73+
public static final String NETWORKS = "networks";
74+
public static final String EMAIL = "email";
75+
public static final String STATUS = "status";
6876
}

src/main/java/com/cryptomarket/params/ContingencyType.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.cryptomarket.params;
22

3+
import com.squareup.moshi.Json;
4+
35
public enum ContingencyType {
6+
@Json(name = "allOrNone")
47
ALL_OR_NONE("allOrNone"),
8+
@Json(name = "oneCancelOther")
59
ONE_CANCEL_OTHER("oneCancelOther"),
10+
@Json(name = "oneTriggerOther")
611
ONE_TRIGGER_OTHER("oneTriggerOther"),
12+
@Json(name = "oneTriggerOneCancelOther")
713
ONE_TRIGGER_ONE_CANCEL_OTHER("oneTriggerOneCancelOther");
814

915
private final String label;

src/main/java/com/cryptomarket/params/NotificationType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
public enum NotificationType {
44
SNAPSHOT("snapshot"),
55
UPDATE("update"),
6-
DATA("data");
6+
DATA("data"),
7+
PARSE_ERROR("error");
78

89
private final String label;
910

@@ -27,4 +28,8 @@ public boolean isData() {
2728
return this == NotificationType.DATA;
2829
}
2930

31+
public boolean isError() {
32+
return this == NotificationType.PARSE_ERROR;
33+
}
34+
3035
}
Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,99 @@
11
package com.cryptomarket.params;
22

3-
import java.util.List;
4-
import java.util.Map;
5-
6-
import com.cryptomarket.sdk.exceptions.CryptomarketArgumentException;
3+
import com.squareup.moshi.Json;
74

85
public class OrderBuilder {
9-
ParamsBuilder paramsBuilder = new ParamsBuilder();
6+
@Json(name = "client_order_id")
7+
private String clientOrderId;
8+
private String symbol;
9+
private Side side;
10+
private OrderType type;
1011

11-
public OrderBuilder checkRequired(List<String> requiredParams) throws CryptomarketArgumentException {
12-
paramsBuilder.checkRequired(requiredParams);
13-
return this;
14-
}
15-
public OrderBuilder clientOrderID(String clientOrderID) {
16-
paramsBuilder.clientOrderID(clientOrderID);
12+
@Json(name = "time_in_force")
13+
private TimeInForce timeInForce;
14+
private String quantity;
15+
private String price;
16+
17+
@Json(name = "stop_price")
18+
private String stopPrice;
19+
20+
@Json(name = "expire_time")
21+
private String expireTime;
22+
23+
@Json(name = "strict_validate")
24+
private Boolean strictValidate;
25+
26+
@Json(name = "post_only")
27+
private Boolean postOnly;
28+
29+
@Json(name = "take_rate")
30+
private String takeRate;
31+
32+
@Json(name = "make_rate")
33+
private String makeRate;
34+
35+
public OrderBuilder clientOrderId(String clientOrderId) {
36+
this.clientOrderId = clientOrderId;
1737
return this;
1838
}
1939

2040
public OrderBuilder symbol(String symbol) {
21-
paramsBuilder.symbol(symbol);
41+
this.symbol = symbol;
2242
return this;
2343
}
2444

2545
public OrderBuilder side(Side side) {
26-
paramsBuilder.side(side);
46+
this.side = side;
2747
return this;
2848
}
2949

30-
public OrderBuilder orderType(OrderType orderType) {
31-
paramsBuilder.orderType(orderType);
50+
public OrderBuilder orderType(OrderType type) {
51+
this.type = type;
3252
return this;
3353
}
3454

3555
public OrderBuilder timeInForce(TimeInForce timeInForce) {
36-
paramsBuilder.timeInForce(timeInForce);
56+
this.timeInForce = timeInForce;
3757
return this;
3858
}
3959

40-
public OrderBuilder quantity(String quantity) {
41-
paramsBuilder.quantity(quantity);
60+
public OrderBuilder quantity(String quanity) {
61+
this.quantity = quanity;
4262
return this;
4363
}
4464

4565
public OrderBuilder price(String price) {
46-
paramsBuilder.price(price);
66+
this.price = price;
4767
return this;
4868
}
4969

50-
public OrderBuilder stopPrice(String stpoPrice) {
51-
paramsBuilder.stopPrice(stpoPrice);
70+
public OrderBuilder stopPrice(String stopPrice) {
71+
this.stopPrice = stopPrice;
5272
return this;
5373
}
5474

5575
public OrderBuilder expireTime(String expireTime) {
56-
paramsBuilder.expireTime(expireTime);
76+
this.expireTime = expireTime;
5777
return this;
5878
}
5979

6080
public OrderBuilder strictValidate(Boolean strictValidate) {
61-
paramsBuilder.strictValidate(strictValidate);
81+
this.strictValidate = strictValidate;
6282
return this;
6383
}
6484

6585
public OrderBuilder postOnly(Boolean postOnly) {
66-
paramsBuilder.postOnly(postOnly);
86+
this.postOnly = postOnly;
6787
return this;
6888
}
6989

7090
public OrderBuilder takeRate(String takeRate) {
71-
paramsBuilder.takeRate(takeRate);
91+
this.takeRate = takeRate;
7292
return this;
7393
}
7494

7595
public OrderBuilder makeRate(String makeRate) {
76-
paramsBuilder.makeRate(makeRate);
96+
this.makeRate = makeRate;
7797
return this;
7898
}
79-
80-
public Map<String, Object> buildObjectMap() {
81-
return paramsBuilder.buildObjectMap();
82-
}
83-
84-
public Map<String, String> build() {
85-
return paramsBuilder.build();
86-
}
8799
}

0 commit comments

Comments
 (0)