├── .classpath
├── .gitattributes
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── pom.xml
├── src
├── main
│ └── java
│ │ └── com
│ │ └── mumu
│ │ ├── beans
│ │ ├── AccountInfo.java
│ │ ├── Cancel.java
│ │ ├── Common.java
│ │ ├── DealtInfo.java
│ │ ├── GetOrder.java
│ │ ├── ListOrders.java
│ │ ├── Market.java
│ │ ├── Order.java
│ │ └── OrderInfo.java
│ │ ├── common
│ │ ├── BaseForm.java
│ │ └── Constants.java
│ │ └── exchange
│ │ ├── MarketServiceFactory.java
│ │ ├── TradingServiceFactory.java
│ │ ├── api
│ │ ├── BinanceAPI.java
│ │ ├── CoinexAPI.java
│ │ ├── HoubiAPI.java
│ │ └── OkexAPI.java
│ │ ├── coins
│ │ ├── BinanceProfiles.java
│ │ ├── CoinexProfiles.java
│ │ ├── HuobiProfiles.java
│ │ └── OkexProfiles.java
│ │ ├── common
│ │ ├── Constants.java
│ │ ├── JacksonHelper.java
│ │ └── RequestUtils.java
│ │ ├── market
│ │ ├── BinanceMarketService.java
│ │ ├── CoinexMarketService.java
│ │ ├── HuobiMarketService.java
│ │ ├── IMarketService.java
│ │ ├── MarketService.java
│ │ └── OkexMarketService.java
│ │ ├── signature
│ │ ├── BinanceParamsSigner.java
│ │ ├── CoinexParamsSigner.java
│ │ ├── HoubiParamsSigner.java
│ │ ├── HuobiParamsSigner.java
│ │ ├── ISignature.java
│ │ ├── OkexParamsSigner.java
│ │ └── RequestParamsSigner.java
│ │ └── trading
│ │ ├── BinanceTradingService.java
│ │ ├── CoinexTradingService.java
│ │ ├── HuobiTradingService.java
│ │ ├── ITradingService.java
│ │ ├── OkexTradingService.java
│ │ └── TradingService.java
└── test
│ └── java
│ ├── MarketTest.java
│ └── TradingTest.java
├── target
├── classes
│ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ └── maven
│ │ │ └── com.mumu
│ │ │ └── mm-vcoinSDK
│ │ │ ├── pom.properties
│ │ │ └── pom.xml
│ └── com
│ │ └── mumu
│ │ ├── beans
│ │ ├── AccountInfo$AssetItem.class
│ │ ├── AccountInfo.class
│ │ ├── Cancel$Response.class
│ │ ├── Cancel.class
│ │ ├── Common.class
│ │ ├── DealtInfo.class
│ │ ├── GetOrder$Response.class
│ │ ├── GetOrder.class
│ │ ├── ListOrders$Response.class
│ │ ├── ListOrders.class
│ │ ├── Market.class
│ │ ├── Order$Response.class
│ │ ├── Order.class
│ │ └── OrderInfo.class
│ │ ├── common
│ │ ├── BaseForm.class
│ │ ├── Constants$EXCHANGE_NAME.class
│ │ ├── Constants$ORDER_STATUS.class
│ │ ├── Constants$ORDER_TYPE.class
│ │ ├── Constants$RESPONSE_STATUS.class
│ │ ├── Constants$TRADING_DIRECTION.class
│ │ └── Constants.class
│ │ └── exchange
│ │ ├── MarketServiceFactory.class
│ │ ├── TradingServiceFactory$TradingServiceSPI.class
│ │ ├── TradingServiceFactory.class
│ │ ├── api
│ │ ├── BinanceAPI$Api_allOrders_params.class
│ │ ├── BinanceAPI$Api_cancel_order_params.class
│ │ ├── BinanceAPI$Api_get_order_params.class
│ │ ├── BinanceAPI$Api_openOrders_params.class
│ │ ├── BinanceAPI$Api_order_params.class
│ │ ├── BinanceAPI$Api_ticker_24hr_params.class
│ │ ├── BinanceAPI$Api_trades_params.class
│ │ ├── BinanceAPI$Api_userinfo_params.class
│ │ ├── BinanceAPI$Wapi_depositHistory_params.class
│ │ ├── BinanceAPI$Wapi_withdrawHistory_params.class
│ │ ├── BinanceAPI.class
│ │ ├── CoinexAPI$Balance_info_params.class
│ │ ├── CoinexAPI$Market_deals_params.class
│ │ ├── CoinexAPI$Market_ticker_params.class
│ │ ├── CoinexAPI$Order_finished_params.class
│ │ ├── CoinexAPI$Order_path$orderType_params.class
│ │ ├── CoinexAPI$Order_pending_list_params.class
│ │ ├── CoinexAPI$Order_pending_params.class
│ │ ├── CoinexAPI$Order_status_params.class
│ │ ├── CoinexAPI.class
│ │ ├── HoubiAPI$Account_accounts_params.class
│ │ ├── HoubiAPI$Accounts_p$accountId_balance_params.class
│ │ ├── HoubiAPI$Market_detail_merged_params.class
│ │ ├── HoubiAPI$Market_history_trade_params.class
│ │ ├── HoubiAPI$Order_openOrders_params.class
│ │ ├── HoubiAPI$Order_orders_params.class
│ │ ├── HoubiAPI$Order_orders_path$orderId_params.class
│ │ ├── HoubiAPI$Order_orders_path$orderId_submitcancel_params.class
│ │ ├── HoubiAPI$Order_orders_place_params.class
│ │ ├── HoubiAPI$Query_deposit_withdraw_params.class
│ │ ├── HoubiAPI.class
│ │ ├── OkexAPI$Api_cancel_order_params.class
│ │ ├── OkexAPI$Api_order_history_params.class
│ │ ├── OkexAPI$Api_order_info_params.class
│ │ ├── OkexAPI$Api_orders_info_params.class
│ │ ├── OkexAPI$Api_ticker_params.class
│ │ ├── OkexAPI$Api_trade_params.class
│ │ ├── OkexAPI$Api_trades_params.class
│ │ ├── OkexAPI$Api_userinfo_params.class
│ │ └── OkexAPI.class
│ │ ├── coins
│ │ ├── BinanceProfiles.class
│ │ ├── CoinexProfiles.class
│ │ ├── HuobiProfiles.class
│ │ └── OkexProfiles.class
│ │ ├── common
│ │ ├── Constants$BINANCE_DEPOSIT_STATUS.class
│ │ ├── Constants$BINANCE_ORDER_SIDE.class
│ │ ├── Constants$BINANCE_ORDER_STATUS.class
│ │ ├── Constants$BINANCE_ORDER_TYPE.class
│ │ ├── Constants$BINANCE_RESP_TYPE.class
│ │ ├── Constants$BINANCE_SYMBOL_STATUS.class
│ │ ├── Constants$BINANCE_TIMEINFORCE.class
│ │ ├── Constants$BINANCE_WITHDRAW_STATUS.class
│ │ ├── Constants$COINEX_ORDER_DIRECTION.class
│ │ ├── Constants$COINEX_ORDER_STATUS.class
│ │ ├── Constants$COINEX_ORDER_TYPE.class
│ │ ├── Constants$HUOBI_ACCOUNTS_TYPE.class
│ │ ├── Constants$HUOBI_DEPOSIT_STATUS.class
│ │ ├── Constants$HUOBI_ORDER_STATUS.class
│ │ ├── Constants$HUOBI_ORDER_TYPE.class
│ │ ├── Constants$HUOBI_WITHDRAW_STATUS.class
│ │ ├── Constants$OKEX_COMMON_STATUS.class
│ │ ├── Constants$OKEX_ORDER_STATUS.class
│ │ ├── Constants$OKEX_ORDER_TYPE.class
│ │ ├── Constants.class
│ │ ├── JacksonHelper.class
│ │ └── RequestUtils.class
│ │ ├── market
│ │ ├── BinanceMarketService.class
│ │ ├── CoinexMarketService.class
│ │ ├── HuobiMarketService.class
│ │ ├── IMarketService.class
│ │ ├── MarketService.class
│ │ └── OkexMarketService.class
│ │ ├── signature
│ │ ├── BinanceParamsSigner$1.class
│ │ ├── BinanceParamsSigner.class
│ │ ├── CoinexParamsSigner$1.class
│ │ ├── CoinexParamsSigner.class
│ │ ├── HoubiParamsSigner$1.class
│ │ ├── HoubiParamsSigner.class
│ │ ├── HuobiParamsSigner$1.class
│ │ ├── HuobiParamsSigner.class
│ │ ├── ISignature.class
│ │ ├── OkexParamsSigner$1.class
│ │ ├── OkexParamsSigner.class
│ │ ├── RequestParamsSigner$1.class
│ │ └── RequestParamsSigner.class
│ │ └── trading
│ │ ├── BinanceTradingService.class
│ │ ├── CoinexTradingService.class
│ │ ├── HuobiTradingService.class
│ │ ├── ITradingService.class
│ │ ├── OkexTradingService.class
│ │ └── TradingService.class
└── test-classes
│ ├── MarketTest.class
│ └── TradingTest.class
└── transaction.log
/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | mm-vcoinSDK
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 | encoding/=UTF-8
5 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
5 | org.eclipse.jdt.core.compiler.source=1.8
6 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/AccountInfo.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.io.Serializable;
4 | import java.util.Collections;
5 | import java.util.Map;
6 |
7 | import com.mumu.common.BaseForm;
8 | import com.mumu.common.Constants.RESPONSE_STATUS;
9 |
10 | public class AccountInfo extends BaseForm {
11 |
12 |
13 | /**
14 | *
15 | */
16 | private static final long serialVersionUID = 3374677305748881668L;
17 | private RESPONSE_STATUS status;
18 | private String errorCode;
19 | private String errorMsg;
20 |
21 | /**
22 | * 帐户状态是否正常
23 | */
24 | private String accountId;
25 | private boolean isNormal = true;
26 | private Map assetMap = null;
27 |
28 |
29 |
30 | public RESPONSE_STATUS getStatus() {
31 | return status;
32 | }
33 |
34 |
35 |
36 | public void setStatus(RESPONSE_STATUS status) {
37 | this.status = status;
38 | }
39 |
40 |
41 |
42 | public String getErrorCode() {
43 | return errorCode;
44 | }
45 |
46 |
47 |
48 | public void setErrorCode(String errorCode) {
49 | this.errorCode = errorCode;
50 | }
51 |
52 |
53 |
54 | public String getErrorMsg() {
55 | return errorMsg;
56 | }
57 |
58 |
59 |
60 | public void setErrorMsg(String errorMsg) {
61 | this.errorMsg = errorMsg;
62 | }
63 |
64 |
65 |
66 | public String getAccountId() {
67 | return accountId;
68 | }
69 |
70 |
71 |
72 | public void setAccountId(String accountId) {
73 | this.accountId = accountId;
74 | }
75 |
76 |
77 |
78 | public boolean isNormal() {
79 | return isNormal;
80 | }
81 |
82 |
83 |
84 | public void setNormal(boolean isNormal) {
85 | this.isNormal = isNormal;
86 | }
87 |
88 |
89 |
90 | public Map getAssetMap() {
91 | return Collections.unmodifiableMap(this.assetMap);
92 | }
93 |
94 |
95 |
96 | public void setAssetMap(Map assetMap) {
97 | if (null == this.assetMap) {
98 | this.assetMap = assetMap;
99 | }
100 | }
101 |
102 |
103 |
104 | public class AssetItem implements Serializable {
105 |
106 |
107 | /**
108 | *
109 | */
110 | private static final long serialVersionUID = 2464994811180200234L;
111 | private String currency;
112 | private String available;
113 | private String frozen;
114 | public String getCurrency() {
115 | return currency;
116 | }
117 | public void setCurrency(String currency) {
118 | this.currency = currency;
119 | }
120 | public String getAvailable() {
121 | return available;
122 | }
123 | public void setAvailable(String available) {
124 | this.available = available;
125 | }
126 | public String getFrozen() {
127 | return frozen;
128 | }
129 | public void setFrozen(String frozen) {
130 | this.frozen = frozen;
131 | }
132 |
133 |
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/Cancel.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.mumu.common.Constants.RESPONSE_STATUS;
6 |
7 | public class Cancel extends Common {
8 |
9 | /**
10 | *
11 | */
12 | private static final long serialVersionUID = -2401774342779032830L;
13 | private String symbol;
14 | private String tid;
15 |
16 |
17 | public String getSymbol() {
18 | return symbol;
19 | }
20 |
21 | public void setSymbol(String symbol) {
22 | this.symbol = symbol;
23 | }
24 |
25 | public String getTid() {
26 | return tid;
27 | }
28 |
29 | public void setTid(String tid) {
30 | this.tid = tid;
31 | }
32 |
33 |
34 | public static class Response implements Serializable {
35 |
36 | /**
37 | *
38 | */
39 | private static final long serialVersionUID = 2870163071445336074L;
40 | private RESPONSE_STATUS status;
41 | private String errorCode;
42 | private String errorMsg;
43 |
44 | private String tid;
45 |
46 | public RESPONSE_STATUS getStatus() {
47 | return status;
48 | }
49 |
50 | public void setStatus(RESPONSE_STATUS status) {
51 | this.status = status;
52 | }
53 |
54 | public String getErrorCode() {
55 | return errorCode;
56 | }
57 |
58 | public void setErrorCode(String errorCode) {
59 | this.errorCode = errorCode;
60 | }
61 |
62 | public String getErrorMsg() {
63 | return errorMsg;
64 | }
65 |
66 | public void setErrorMsg(String errorMsg) {
67 | this.errorMsg = errorMsg;
68 | }
69 |
70 | public String getTid() {
71 | return tid;
72 | }
73 |
74 | public void setTid(String tid) {
75 | this.tid = tid;
76 | }
77 |
78 |
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/Common.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import com.mumu.common.BaseForm;
4 |
5 | public class Common extends BaseForm {
6 |
7 | private String accessKey;
8 | private String secretkey;
9 | private String accountId;
10 | private String requestId;
11 |
12 | public String getAccessKey() {
13 | return accessKey;
14 | }
15 | public void setAccessKey(String accessKey) {
16 | this.accessKey = accessKey;
17 | }
18 | public String getSecretkey() {
19 | return secretkey;
20 | }
21 | public void setSecretkey(String secretkey) {
22 | this.secretkey = secretkey;
23 | }
24 | public String getAccountId() {
25 | return accountId;
26 | }
27 |
28 | /**
29 | * 可不传
30 | * @param accountId
31 | */
32 | public void setAccountId(String accountId) {
33 | this.accountId = accountId;
34 | }
35 | public String getRequestId() {
36 | return requestId;
37 | }
38 | public void setRequestId(String requestId) {
39 | this.requestId = requestId;
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/DealtInfo.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import com.mumu.common.BaseForm;
4 | import com.mumu.common.Constants.TRADING_DIRECTION;
5 |
6 | public class DealtInfo extends BaseForm {
7 |
8 |
9 | /**
10 | *
11 | */
12 | private static final long serialVersionUID = -7957675042135563397L;
13 | /**
14 | * "id": 成交id,
15 | */
16 | private String id;
17 | /**
18 | * "price": 成交价,
19 | */
20 | private double price;
21 | /**
22 | * "amount": 成交量,
23 | */
24 | private double volume;
25 | /**
26 | * "direction": 主动成交方向,
27 | */
28 | private TRADING_DIRECTION direction;
29 | /**
30 | * "ts": 成交时间
31 | */
32 | private long ts;
33 |
34 |
35 | public String getId() {
36 | return id;
37 | }
38 | public void setId(String id) {
39 | this.id = id;
40 | }
41 | public double getPrice() {
42 | return price;
43 | }
44 | public void setPrice(double price) {
45 | this.price = price;
46 | }
47 | public double getVolume() {
48 | return volume;
49 | }
50 | public void setVolume(double volume) {
51 | this.volume = volume;
52 | }
53 | public TRADING_DIRECTION getDirection() {
54 | return direction;
55 | }
56 | public void setDirection(TRADING_DIRECTION direction) {
57 | this.direction = direction;
58 | }
59 | public long getTs() {
60 | return ts;
61 | }
62 | public void setTs(long ts) {
63 | this.ts = ts;
64 | }
65 |
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/GetOrder.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.mumu.common.Constants.RESPONSE_STATUS;
6 |
7 | public class GetOrder extends Common {
8 |
9 | /**
10 | *
11 | */
12 | private static final long serialVersionUID = 1638945906226887753L;
13 | private String symbol;
14 | private String tid;
15 |
16 | public String getSymbol() {
17 | return symbol;
18 | }
19 | public void setSymbol(String symbol) {
20 | this.symbol = symbol;
21 | }
22 | public String getTid() {
23 | return tid;
24 | }
25 | public void setTid(String tid) {
26 | this.tid = tid;
27 | }
28 |
29 | public static class Response implements Serializable {
30 |
31 |
32 | /**
33 | *
34 | */
35 | private static final long serialVersionUID = -3153622022992531371L;
36 | private RESPONSE_STATUS status;
37 | private String errorCode;
38 | private String errorMsg;
39 |
40 | private OrderInfo orderInfo;
41 |
42 | public RESPONSE_STATUS getStatus() {
43 | return status;
44 | }
45 |
46 | public void setStatus(RESPONSE_STATUS status) {
47 | this.status = status;
48 | }
49 |
50 | public String getErrorCode() {
51 | return errorCode;
52 | }
53 |
54 | public void setErrorCode(String errorCode) {
55 | this.errorCode = errorCode;
56 | }
57 |
58 | public String getErrorMsg() {
59 | return errorMsg;
60 | }
61 |
62 | public void setErrorMsg(String errorMsg) {
63 | this.errorMsg = errorMsg;
64 | }
65 |
66 | public OrderInfo getOrderInfo() {
67 | return orderInfo;
68 | }
69 |
70 | public void setOrderInfo(OrderInfo orderInfo) {
71 | this.orderInfo = orderInfo;
72 | }
73 |
74 |
75 |
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/ListOrders.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.io.Serializable;
4 | import java.util.List;
5 |
6 | import com.mumu.common.Constants.RESPONSE_STATUS;
7 |
8 | public class ListOrders extends Common {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1049013488197872434L;
14 | private String symbol;
15 |
16 | public String getSymbol() {
17 | return symbol;
18 | }
19 |
20 | public void setSymbol(String symbol) {
21 | this.symbol = symbol;
22 | }
23 |
24 | public static class Response implements Serializable {
25 |
26 |
27 | /**
28 | *
29 | */
30 | private static final long serialVersionUID = -4005463384102145276L;
31 | private RESPONSE_STATUS status;
32 | private String errorCode;
33 | private String errorMsg;
34 | private boolean hasNext = false;
35 |
36 | private List orderInfoList;
37 |
38 | public RESPONSE_STATUS getStatus() {
39 | return status;
40 | }
41 |
42 | public void setStatus(RESPONSE_STATUS status) {
43 | this.status = status;
44 | }
45 |
46 | public String getErrorCode() {
47 | return errorCode;
48 | }
49 |
50 | public void setErrorCode(String errorCode) {
51 | this.errorCode = errorCode;
52 | }
53 |
54 | public String getErrorMsg() {
55 | return errorMsg;
56 | }
57 |
58 | public void setErrorMsg(String errorMsg) {
59 | this.errorMsg = errorMsg;
60 | }
61 |
62 | public List getListOrderInfo() {
63 | return orderInfoList;
64 | }
65 |
66 | public void setListOrderInfo(List orderInfoList) {
67 | this.orderInfoList = orderInfoList;
68 | }
69 |
70 | public boolean isHasNext() {
71 | return hasNext;
72 | }
73 |
74 | public void setHasNext(boolean hasNext) {
75 | this.hasNext = hasNext;
76 | }
77 |
78 |
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/Market.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Calendar;
5 |
6 | import com.mumu.common.BaseForm;
7 |
8 | public class Market extends BaseForm {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 7592585925124568142L;
14 | private Calendar calendar = null;//Calendar.getInstance();
15 | private String date = null;
16 | private String time = null;
17 |
18 | /**
19 | * 行情时间戳
20 | */
21 | private long ts;
22 | /**
23 | * 标的
24 | */
25 | private String symbol;
26 | /**
27 | * 开盘价
28 | */
29 | private double open;
30 | /**
31 | * 最新价
32 | */
33 | private double last;
34 | /**
35 | * 买价
36 | */
37 | private double bid;
38 | /**
39 | * 买量
40 | */
41 | private double bidVolume;
42 | /**
43 | * 卖价
44 | */
45 | private double ask;
46 | /**
47 | * 卖量
48 | */
49 | private double askVolume;
50 | /**
51 | * 最高价
52 | */
53 | private double highest;
54 | /**
55 | * 最低价
56 | */
57 | private double lowest;
58 | /**
59 | * 成交量
60 | */
61 | private double volume;
62 | /**
63 | * 成交额
64 | */
65 | private double amount;
66 | public long getTs() {
67 | return ts;
68 | }
69 | public void setTs(long ts) {
70 | if (null == calendar) {
71 | calendar = Calendar.getInstance();
72 | calendar.setTimeInMillis(ts);
73 | }
74 | this.ts = ts;
75 | }
76 | public String getSymbol() {
77 | return symbol;
78 | }
79 | public void setSymbol(String symbol) {
80 | this.symbol = symbol;
81 | }
82 | public double getOpen() {
83 | return open;
84 | }
85 | public void setOpen(double open) {
86 | this.open = open;
87 | }
88 | public double getLast() {
89 | return last;
90 | }
91 | public void setLast(double last) {
92 | this.last = last;
93 | }
94 | public double getBid() {
95 | return bid;
96 | }
97 | public void setBid(double bid) {
98 | this.bid = bid;
99 | }
100 | public double getBidVolume() {
101 | return bidVolume;
102 | }
103 | public void setBidVolume(double bidVolume) {
104 | this.bidVolume = bidVolume;
105 | }
106 | public double getAsk() {
107 | return ask;
108 | }
109 | public void setAsk(double ask) {
110 | this.ask = ask;
111 | }
112 | public double getAskVolume() {
113 | return askVolume;
114 | }
115 | public void setAskVolume(double askVolume) {
116 | this.askVolume = askVolume;
117 | }
118 | public double getHighest() {
119 | return highest;
120 | }
121 | public void setHighest(double highest) {
122 | this.highest = highest;
123 | }
124 | public double getLowest() {
125 | return lowest;
126 | }
127 | public void setLowest(double lowest) {
128 | this.lowest = lowest;
129 | }
130 | public double getVolume() {
131 | return volume;
132 | }
133 | public void setVolume(double volume) {
134 | this.volume = volume;
135 | }
136 | public double getAmount() {
137 | return amount;
138 | }
139 | public void setAmount(double amount) {
140 | this.amount = amount;
141 | }
142 |
143 | public String getDate() {
144 | if (null == date) {
145 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
146 | date = dateFormat.format(this.calendar.getTime());
147 | }
148 |
149 | return date;
150 | }
151 |
152 | public String getTime() {
153 | if (null == time) {
154 | SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
155 | time = dateFormat.format(this.calendar.getTime());
156 | }
157 |
158 | return time;
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/Order.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.mumu.common.Constants.ORDER_TYPE;
6 | import com.mumu.common.Constants.RESPONSE_STATUS;
7 | import com.mumu.common.Constants.TRADING_DIRECTION;
8 |
9 | public class Order extends Common {
10 |
11 |
12 | /**
13 | *
14 | */
15 | private static final long serialVersionUID = -4205844875425589379L;
16 | private String symbol;
17 | private String volume;
18 | /**
19 | * 市价单没有价格
20 | */
21 | private String price;
22 | private TRADING_DIRECTION direction;
23 | private ORDER_TYPE type;
24 |
25 |
26 | public String getSymbol() {
27 | return symbol;
28 | }
29 |
30 | public void setSymbol(String symbol) {
31 | this.symbol = symbol;
32 | }
33 |
34 | public String getVolume() {
35 | return volume;
36 | }
37 |
38 | public void setVolume(String volume) {
39 | this.volume = volume;
40 | }
41 |
42 | public String getPrice() {
43 | return price;
44 | }
45 |
46 | public void setPrice(String price) {
47 | this.price = price;
48 | }
49 |
50 | public TRADING_DIRECTION getDirection() {
51 | return direction;
52 | }
53 |
54 | public void setDirection(TRADING_DIRECTION direction) {
55 | this.direction = direction;
56 | }
57 |
58 | public ORDER_TYPE getType() {
59 | return type;
60 | }
61 |
62 | public void setType(ORDER_TYPE type) {
63 | this.type = type;
64 | }
65 |
66 |
67 |
68 | public static class Response implements Serializable {
69 |
70 | /**
71 | *
72 | */
73 | private static final long serialVersionUID = 7657654382832287880L;
74 | private RESPONSE_STATUS status;
75 | private String errorCode;
76 | private String errorMsg;
77 |
78 | private String tid;
79 |
80 | public RESPONSE_STATUS getStatus() {
81 | return status;
82 | }
83 |
84 | public void setStatus(RESPONSE_STATUS status) {
85 | this.status = status;
86 | }
87 |
88 | public String getErrorCode() {
89 | return errorCode;
90 | }
91 |
92 | public void setErrorCode(String errorCode) {
93 | this.errorCode = errorCode;
94 | }
95 |
96 | public String getErrorMsg() {
97 | return errorMsg;
98 | }
99 |
100 | public void setErrorMsg(String errorMsg) {
101 | this.errorMsg = errorMsg;
102 | }
103 |
104 | public String getTid() {
105 | return tid;
106 | }
107 |
108 | public void setTid(String tid) {
109 | this.tid = tid;
110 | }
111 |
112 |
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/beans/OrderInfo.java:
--------------------------------------------------------------------------------
1 | package com.mumu.beans;
2 |
3 | import com.mumu.common.BaseForm;
4 | import com.mumu.common.Constants.EXCHANGE_NAME;
5 | import com.mumu.common.Constants.ORDER_STATUS;
6 | import com.mumu.common.Constants.ORDER_TYPE;
7 | import com.mumu.common.Constants.TRADING_DIRECTION;
8 |
9 | public class OrderInfo extends BaseForm {
10 |
11 | /**
12 | *
13 | */
14 | private static final long serialVersionUID = 1822555787222340534L;
15 | private String id;
16 | private String symbol;
17 | private String accountId;
18 | /**
19 | * 委托量
20 | */
21 | private String originalVolume;
22 | /**
23 | * 成交量
24 | */
25 | private String volume;
26 | private String price;
27 | /**
28 | * 创建时间
29 | */
30 | private String ts;
31 | private TRADING_DIRECTION direction;
32 | private ORDER_TYPE type;
33 | private ORDER_STATUS status;
34 | private EXCHANGE_NAME exchange;
35 | /**
36 | * 手续费
37 | */
38 | private String fee;
39 | /**
40 | * 手续费币种
41 | */
42 | private String feeSymbol;
43 | private String requestId;
44 |
45 | public String getId() {
46 | return id;
47 | }
48 | public void setId(String id) {
49 | this.id = id;
50 | }
51 | public String getSymbol() {
52 | return symbol;
53 | }
54 | public void setSymbol(String symbol) {
55 | this.symbol = symbol;
56 | }
57 | public String getAccountId() {
58 | return accountId;
59 | }
60 | public void setAccountId(String accountId) {
61 | this.accountId = accountId;
62 | }
63 | public String getOriginalVolume() {
64 | return originalVolume;
65 | }
66 | public void setOriginalVolume(String originalVolume) {
67 | this.originalVolume = originalVolume;
68 | }
69 | public String getVolume() {
70 | return volume;
71 | }
72 | public void setVolume(String volume) {
73 | this.volume = volume;
74 | }
75 | public String getPrice() {
76 | return price;
77 | }
78 | public void setPrice(String price) {
79 | this.price = price;
80 | }
81 | public String getTs() {
82 | return ts;
83 | }
84 | public void setTs(String ts) {
85 | this.ts = ts;
86 | }
87 | public TRADING_DIRECTION getDirection() {
88 | return direction;
89 | }
90 | public void setDirection(TRADING_DIRECTION direction) {
91 | this.direction = direction;
92 | }
93 | public ORDER_TYPE getType() {
94 | return type;
95 | }
96 | public void setType(ORDER_TYPE type) {
97 | this.type = type;
98 | }
99 | public ORDER_STATUS getStatus() {
100 | return status;
101 | }
102 | public void setStatus(ORDER_STATUS status) {
103 | this.status = status;
104 | }
105 | public EXCHANGE_NAME getExchange() {
106 | return exchange;
107 | }
108 | public void setExchange(EXCHANGE_NAME exchange) {
109 | this.exchange = exchange;
110 | }
111 | public String getFee() {
112 | return fee;
113 | }
114 | public void setFee(String fee) {
115 | this.fee = fee;
116 | }
117 | public String getRequestId() {
118 | return requestId;
119 | }
120 | public void setRequestId(String requestId) {
121 | this.requestId = requestId;
122 | }
123 | public String getFeeSymbol() {
124 | return feeSymbol;
125 | }
126 | public void setFeeSymbol(String feeSymbol) {
127 | this.feeSymbol = feeSymbol;
128 | }
129 |
130 |
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/common/BaseForm.java:
--------------------------------------------------------------------------------
1 | package com.mumu.common;
2 |
3 | import java.io.Serializable;
4 |
5 | public class BaseForm implements Serializable {
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/common/Constants.java:
--------------------------------------------------------------------------------
1 | package com.mumu.common;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 |
8 | public class Constants {
9 |
10 | public static enum EXCHANGE_NAME {
11 | EXCHANGE_HOUBI("huobi"),
12 | EXCHANGE_COINEX("coinex"),
13 | EXCHANGE_OKEX("okex"),
14 | EXCHANGE_BINANCE("binance");
15 |
16 | private final String code;
17 |
18 | private EXCHANGE_NAME(String code) {
19 | this.code = code;
20 | }
21 | public String getCode() {
22 | return code;
23 | }
24 |
25 | public static List> getKVPair() {
26 | EXCHANGE_NAME[] statuses = EXCHANGE_NAME.values();
27 | List> kvPairList = new ArrayList>(statuses.length);
28 | HashMap kvPairMap = null;
29 |
30 | for (int i = 0; i < statuses.length; i++) {
31 | kvPairMap = new HashMap(2);
32 | kvPairMap.put("name", statuses[i].name());
33 | kvPairMap.put("code", statuses[i].code);
34 |
35 | kvPairList.add(kvPairMap);
36 | }
37 | return kvPairList;
38 | }
39 |
40 | public static HashMap getCodeEnumMap() {
41 | EXCHANGE_NAME[] from = EXCHANGE_NAME.values();
42 | HashMap kvPairMap = new HashMap();;
43 | for (int i = 0; i < from.length; i++) {
44 | kvPairMap.put(from[i].code, from[i]);
45 | }
46 | return kvPairMap;
47 | }
48 | }
49 |
50 |
51 | public static enum TRADING_DIRECTION {
52 | BUY("buy"),
53 | SELL("sell");
54 |
55 | private final String code;
56 |
57 | private TRADING_DIRECTION(String code) {
58 | this.code = code;
59 | }
60 | public String getCode() {
61 | return code;
62 | }
63 |
64 | public static List> getKVPair() {
65 | TRADING_DIRECTION[] statuses = TRADING_DIRECTION.values();
66 | List> kvPairList = new ArrayList>(statuses.length);
67 | HashMap kvPairMap = null;
68 |
69 | for (int i = 0; i < statuses.length; i++) {
70 | kvPairMap = new HashMap(2);
71 | kvPairMap.put("name", statuses[i].name());
72 | kvPairMap.put("code", statuses[i].code);
73 |
74 | kvPairList.add(kvPairMap);
75 | }
76 | return kvPairList;
77 | }
78 | }
79 |
80 | /**
81 | * buy-limit-maker
82 | 当“下单价格”>=“市场最低卖出价”,订单提交后,系统将拒绝接受此订单;
83 | 当“下单价格”<“市场最低卖出价”,提交成功后,此订单将被系统接受。
84 | sell-limit-maker
85 | 当“下单价格”<=“市场最高买入价”,订单提交后,系统将拒绝接受此订单;
86 | 当“下单价格”>“市场最高买入价”,提交成功后,此订单将被系统接受。
87 | *
88 | */
89 | public static enum ORDER_TYPE {
90 | LIMIT("limit"),//
91 | MARKET("market"),//
92 | IOC("ioc"),//
93 | LIMIT_MAKER("LIMIT-MAKER"),//
94 | STOP_LOSS("STOP_LOSS"),//市价止损
95 | STOP_LOSS_LIMIT("STOP_LOSS_LIMIT"),//限价止损
96 | TAKE_PROFIT("TAKE_PROFIT"),//市价止盈
97 | TAKE_PROFIT_LIMIT("TAKE_PROFIT_LIMIT");//限价止盈;
98 |
99 | private final String code;
100 |
101 | private ORDER_TYPE(String code) {
102 | this.code = code;
103 | }
104 | public String getCode() {
105 | return code;
106 | }
107 |
108 | public static List> getKVPair() {
109 | ORDER_TYPE[] statuses = ORDER_TYPE.values();
110 | List> kvPairList = new ArrayList>(statuses.length);
111 | HashMap kvPairMap = null;
112 |
113 | for (int i = 0; i < statuses.length; i++) {
114 | kvPairMap = new HashMap(2);
115 | kvPairMap.put("name", statuses[i].name());
116 | kvPairMap.put("code", statuses[i].code);
117 |
118 | kvPairList.add(kvPairMap);
119 | }
120 | return kvPairList;
121 | }
122 | }
123 |
124 | public static enum RESPONSE_STATUS {
125 | OK("ok"),
126 | ERROR("error");
127 |
128 | private final String code;
129 |
130 | private RESPONSE_STATUS(String code) {
131 | this.code = code;
132 | }
133 | public String getCode() {
134 | return code;
135 | }
136 |
137 | public static RESPONSE_STATUS getByCode(String code) {
138 | RESPONSE_STATUS type = null;
139 |
140 | for (int i = 0; i < RESPONSE_STATUS.values().length; i++) {
141 | type = RESPONSE_STATUS.values()[i];
142 | if (type.getCode().equals(code)) {
143 | break;
144 | }
145 | }
146 |
147 | return type;
148 | }
149 |
150 | public static List> getKVPair() {
151 | RESPONSE_STATUS[] statuses = RESPONSE_STATUS.values();
152 | List> kvPairList = new ArrayList>(statuses.length);
153 | HashMap kvPairMap = null;
154 |
155 | for (int i = 0; i < statuses.length; i++) {
156 | kvPairMap = new HashMap(2);
157 | kvPairMap.put("name", statuses[i].name());
158 | kvPairMap.put("code", statuses[i].code);
159 |
160 | kvPairList.add(kvPairMap);
161 | }
162 | return kvPairList;
163 | }
164 | }
165 |
166 | public static enum ORDER_STATUS {
167 | UNMATCHED("未成交"),
168 | MATCHED("全部成交"),
169 | CANCELED("已撤销"),
170 | CANCELING("撤销中"),
171 | PART_MATCHED("部分成交"),
172 | PART_CANCELED("部成部撤");
173 |
174 | private final String code;
175 |
176 | private ORDER_STATUS(String code) {
177 | this.code = code;
178 | }
179 | public String getCode() {
180 | return code;
181 | }
182 |
183 | public static ORDER_STATUS getByCode(String code) {
184 | ORDER_STATUS type = null;
185 |
186 | for (int i = 0; i < ORDER_STATUS.values().length; i++) {
187 | type = ORDER_STATUS.values()[i];
188 | if (type.getCode().equals(code)) {
189 | break;
190 | }
191 | }
192 |
193 | return type;
194 | }
195 |
196 | public static List> getKVPair() {
197 | ORDER_STATUS[] statuses = ORDER_STATUS.values();
198 | List> kvPairList = new ArrayList>(statuses.length);
199 | HashMap kvPairMap = null;
200 |
201 | for (int i = 0; i < statuses.length; i++) {
202 | kvPairMap = new HashMap(2);
203 | kvPairMap.put("name", statuses[i].name());
204 | kvPairMap.put("code", statuses[i].code);
205 |
206 | kvPairList.add(kvPairMap);
207 | }
208 | return kvPairList;
209 | }
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/MarketServiceFactory.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange;
2 |
3 | import com.mumu.common.Constants;
4 | import com.mumu.exchange.market.BinanceMarketService;
5 | import com.mumu.exchange.market.CoinexMarketService;
6 | import com.mumu.exchange.market.HuobiMarketService;
7 | import com.mumu.exchange.market.IMarketService;
8 | import com.mumu.exchange.market.OkexMarketService;
9 |
10 | public class MarketServiceFactory {
11 |
12 | public static IMarketService getInstance(Constants.EXCHANGE_NAME exchange) {
13 | IMarketService iIMarketService = null;
14 | if (Constants.EXCHANGE_NAME.EXCHANGE_HOUBI.equals(exchange)) {
15 | iIMarketService = new HuobiMarketService();
16 | } else if (Constants.EXCHANGE_NAME.EXCHANGE_COINEX.equals(exchange)) {
17 | iIMarketService = new CoinexMarketService();
18 | } else if (Constants.EXCHANGE_NAME.EXCHANGE_OKEX.equals(exchange)) {
19 | iIMarketService = new OkexMarketService();
20 | } else if (Constants.EXCHANGE_NAME.EXCHANGE_BINANCE.equals(exchange)) {
21 | iIMarketService = new BinanceMarketService();
22 | }
23 |
24 | return iIMarketService;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/TradingServiceFactory.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange;
2 |
3 | import com.mumu.beans.AccountInfo;
4 | import com.mumu.beans.Cancel;
5 | import com.mumu.beans.GetOrder;
6 | import com.mumu.beans.ListOrders;
7 | import com.mumu.beans.Order;
8 | import com.mumu.exchange.common.Constants;
9 | import com.mumu.exchange.signature.BinanceParamsSigner;
10 | import com.mumu.exchange.signature.CoinexParamsSigner;
11 | import com.mumu.exchange.signature.HuobiParamsSigner;
12 | import com.mumu.exchange.signature.ISignature;
13 | import com.mumu.exchange.signature.OkexParamsSigner;
14 | import com.mumu.exchange.trading.BinanceTradingService;
15 | import com.mumu.exchange.trading.CoinexTradingService;
16 | import com.mumu.exchange.trading.HuobiTradingService;
17 | import com.mumu.exchange.trading.ITradingService;
18 | import com.mumu.exchange.trading.OkexTradingService;
19 |
20 | public class TradingServiceFactory {
21 |
22 | public static TradingServiceSPI getInstance(com.mumu.common.Constants.EXCHANGE_NAME exchange) {
23 |
24 | return new TradingServiceFactory.TradingServiceSPI(exchange);
25 | }
26 |
27 | public final static class TradingServiceSPI {
28 |
29 | private ITradingService tradingService;
30 | private ISignature signature;
31 |
32 | public TradingServiceSPI(com.mumu.common.Constants.EXCHANGE_NAME exchange) {
33 | if (com.mumu.common.Constants.EXCHANGE_NAME.EXCHANGE_HOUBI.equals(exchange)) {
34 | tradingService = new HuobiTradingService();
35 | signature = new HuobiParamsSigner();
36 | } else if (com.mumu.common.Constants.EXCHANGE_NAME.EXCHANGE_COINEX.equals(exchange)) {
37 | tradingService = new CoinexTradingService();
38 | signature = new CoinexParamsSigner();
39 | } else if (com.mumu.common.Constants.EXCHANGE_NAME.EXCHANGE_OKEX.equals(exchange)) {
40 | tradingService = new OkexTradingService();
41 | signature = new OkexParamsSigner();
42 | } else if (com.mumu.common.Constants.EXCHANGE_NAME.EXCHANGE_BINANCE.equals(exchange)) {
43 | tradingService = new BinanceTradingService();
44 | signature = new BinanceParamsSigner();
45 | }
46 | }
47 |
48 | public ISignature getSignature() {
49 | return signature;
50 | }
51 |
52 | /**
53 | *
54 | * @param clazz
55 | * @return
56 | */
57 | public T getLocalTradingService(Class clazz) {
58 |
59 | return clazz.cast(tradingService);
60 | }
61 |
62 | // /**
63 | // *
64 | // * @param key
65 | // * @param value
66 | // * @return
67 | // */
68 | // public TradingServiceSPI putParam(String key, String value) {
69 | // this.signature.putParam(key, value);
70 | // return this;
71 | // }
72 | //
73 | // /**
74 | // *
75 | // * @param params
76 | // * @return
77 | // */
78 | // public TradingServiceSPI addAllParams(Map params) {
79 | // this.signature.addAllParams(params);
80 | // return this;
81 | // }
82 | //
83 | // /**
84 | // * 清空参数后,在保证线程安全的情况下,可以使用同一SPI实例请求其它接口
85 | // * @return
86 | // */
87 | // public TradingServiceSPI clearParams() {
88 | // this.signature.clearParams();
89 | // return this;
90 | // }
91 |
92 | /**
93 | *
94 | * @param accessKey
95 | * @param secretkey
96 | * @param accountId 可以传本地ID,用来标识返回数据所有者
97 | * @return
98 | */
99 | public AccountInfo accountInfo(String accessKey, String secretkey, String accountId) {
100 | AccountInfo accountInfo = this.tradingService.accountInfo(accessKey, secretkey, signature);
101 | accountInfo.setAccountId(accountId);
102 | return accountInfo;
103 | }
104 |
105 | // public String orders(String accessKey, String secretkey) {
106 | // return this.tradingService.orders(accessKey, secretkey, signature);
107 | // }
108 |
109 | /**
110 | * h:{"status":"error","err-code":"account-frozen-balance-insufficient-error","err-msg":"余额不足,剩余:`0.0005`","data":null}
111 | * h:{"status":"ok","data":"10721786675"}
112 | * c:{ "code": 23, "data": {}, "message": "IP:66.42.71.205 is not allowed"} { "code": 107, "data": {}, "message": "Balance insufficient."}
113 | c: {
114 | "code": 0,
115 | "data": {
116 | "amount": "232.56235465",
117 | "asset_fee": "0",
118 | "avg_price": "0.00",
119 | "create_time": 1534845385,
120 | "deal_amount": "0",
121 | "deal_fee": "0",
122 | "deal_money": "0",
123 | "fee_asset": null,
124 | "fee_discount": "0",
125 | "id": 1371225525,
126 | "left": "232.56235465",
127 | "maker_fee_rate": "0.001",
128 | "market": "CETBCH",
129 | "order_type": "limit",
130 | "price": "0.00001880",
131 | "source_id": "",
132 | "status": "not_deal",
133 | "taker_fee_rate": "0.001",
134 | "type": "buy"
135 | },
136 | "message": "Ok"
137 | }
138 | * o:{"error_code":1002}
139 | * o:{"result":true,"order_id":53649387}
140 | * b:{"symbol":"ETHUSDT","orderId":106437085,"clientOrderId":"PtIGmuYsIa3uIz7fOh7i17","transactTime":1534847895782,"price":"380.00000000","origQty":"0.04000000","executedQty":"0.00000000","cummulativeQuoteQty":"0.00000000","status":"NEW","timeInForce":"GTC","type":"LIMIT","side":"SELL","fills":[]}
141 | * b:请求异常
142 | * @return
143 | */
144 | public Order.Response orders(Order order) {
145 | this.signature.addAllParams(tradingService.getOrdersParamsMap(order));
146 | return this.tradingService.orders(order.getAccessKey(), order.getSecretkey(), signature);
147 | }
148 |
149 | /**
150 | *
151 | * @param accessKey
152 | * @param secretkey
153 | * @return
154 | */
155 | public Cancel.Response cancel(Cancel cancel) {
156 | this.signature.addAllParams(this.tradingService.getCancelParamsMap(cancel));
157 | return this.tradingService.cancel(cancel.getAccessKey(), cancel.getSecretkey(), signature);
158 | }
159 |
160 | public GetOrder.Response orderInfo(GetOrder getOrder) {
161 | this.signature.addAllParams(this.tradingService.getGetOrderParamsMap(getOrder));
162 | return this.tradingService.orderInfo(getOrder.getAccessKey(), getOrder.getSecretkey(), signature);
163 | }
164 |
165 | public ListOrders.Response unmatchedList(ListOrders listOrders) {
166 | this.signature.addAllParams(this.tradingService.getListUnMatchedParamsMap(listOrders));
167 | return this.tradingService.unmatchedList(listOrders.getAccessKey(), listOrders.getSecretkey(), signature);
168 | }
169 |
170 | // public String dealtList(String accessKey, String secretkey, ISignature signature);
171 |
172 | public String historyList(String accessKey, String secretkey) {
173 | return this.tradingService.historyList(accessKey, secretkey, signature);
174 | }
175 |
176 | public String depositList(String accessKey, String secretkey) {
177 | return this.tradingService.depositList(accessKey, secretkey, signature);
178 | }
179 |
180 | public String withdrawList(String accessKey, String secretkey) {
181 | return this.tradingService.withdrawList(accessKey, secretkey, signature);
182 | }
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/api/BinanceAPI.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public final class BinanceAPI {
7 |
8 | //API-keys are passed into the Rest API via the X-MBX-APIKEY header.
9 | public static final String API_SIGN_KEY_AccessKeyId = "X-MBX-APIKEY";
10 | public static final String API_SIGN_KEY_Secret_key = "secret_key";
11 | public static final String API_SIGN_SignatureMethod = "HMACSHA256";
12 | public static final String API_SIGN_KEY_authorization = "signature";
13 | public static final String API_SIGN_KEY_Timestamp = "timestamp";
14 | public static final String API_SIGN_KEY_recvWindow = "recvWindow";//
15 | public static final String API_SIGN_DEFVAL_recvWindow = "5000";//
16 |
17 | private static Map uriMethodMap = new HashMap();
18 | public static final String rest_trading_root = "https://api.binance.com";//https://api.binance.com/api/v1/exchangeInfo
19 | public static final String ws_root = "wss://stream.binance.com:9443";
20 |
21 |
22 | /**
23 | * 用户资产API
24 | */
25 | public static final String api_account = "/api/v3/account";
26 | public static final String api_account_method_get = "GET";
27 | static { uriMethodMap.put(api_account, api_account_method_get); }
28 | public static enum Api_userinfo_params {
29 |
30 | }
31 |
32 | /**
33 | * POST /api/v3/order (HMAC SHA256)
34 | * Send in a new order.
35 | * Weight: 1
36 | */
37 | public static final String api_order = "/api/v3/order";
38 | public static final String api_order_method_post = "POST";
39 | static { uriMethodMap.put(api_order, api_order_method_post); }
40 | public static enum Api_order_params {
41 | symbol("symbol"),// STRING YES
42 | side("side"),// ENUM YES
43 | type("type"),// ENUM YES
44 | timeInForce("timeInForce"),// ENUM NO
45 | quantity("quantity"),/// DECIMAL YES
46 | price("price"),// DECIMAL NO
47 | newClientOrderId("newClientOrderId"),// STRING NO A unique id for the order. Automatically generated if not sent.
48 | stopPrice("stopPrice"), //DECIMAL NO Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.
49 | icebergQty("icebergQty"),// DECIMAL NO Used with LIMIT, STOP_LOSS_LIMIT, and TAKE_PROFIT_LIMIT to create an iceberg order.
50 | newOrderRespType("newOrderRespType");// ENUM NO Set the response JSON. ACK, RESULT, or FULL; MARKET and LIMIT order types default to FULL, all other orders default to ACK.
51 | // recvWindow("recvWindow" LONG NO
52 | // timestamp LONG YES
53 |
54 | private final String code;
55 |
56 | private Api_order_params(String code) {
57 | this.code = code;
58 | }
59 | public String getCode() {
60 | return code;
61 | }
62 | }
63 |
64 | /**
65 | * Cancel order (TRADE)
66 | * DELETE /api/v3/order (HMAC SHA256)
67 | * Cancel an active order.
68 | */
69 | public static final String api_cancel_order = "/api/v3/order";
70 | public static final String api_cancel_order_alias = "api_cancel_order";
71 | public static final String api_cancel_order_method_delete = "DELETE";
72 | static { uriMethodMap.put(api_cancel_order_alias, api_cancel_order_method_delete); }
73 | public static enum Api_cancel_order_params {
74 | symbol("symbol"),// STRING YES
75 | orderId("orderId"),// LONG NO
76 | origClientOrderId("origClientOrderId"),// STRING NO
77 | newClientOrderId("newClientOrderId");// STRING NO Used to uniquely identify this cancel. Automatically generated by default.
78 |
79 | private final String code;
80 |
81 | private Api_cancel_order_params(String code) {
82 | this.code = code;
83 | }
84 | public String getCode() {
85 | return code;
86 | }
87 | }
88 |
89 | /**
90 | * GET /api/v3/order (HMAC SHA256)
91 | * Check an order's status.
92 | * Weight: 1
93 | */
94 | public static final String api_get_order = "/api/v3/order";
95 | public static final String api_get_order_alias = "api_get_order";
96 | public static final String api_get_order_method_get = "GET";
97 | static { uriMethodMap.put(api_get_order_alias, api_get_order_method_get); }
98 | public static enum Api_get_order_params {
99 | symbol("symbol"),// STRING YES
100 | orderId("orderId"),// LONG NO
101 | origClientOrderId("origClientOrderId");// STRING NO
102 |
103 | private final String code;
104 |
105 | private Api_get_order_params(String code) {
106 | this.code = code;
107 | }
108 | public String getCode() {
109 | return code;
110 | }
111 | }
112 |
113 |
114 | /**
115 | *
116 | *GET /api/v3/openOrders (HMAC SHA256)
117 | *Get all open orders on a symbol. Careful when accessing this with no symbol.
118 | *Weight: 1 for a single symbol; 40 when the symbol parameter is omitted
119 | *If the symbol is not sent, orders for all symbols will be returned in an array.
120 | When all symbols are returned, the number of requests counted against the rate limiter is equal to the number of symbols currently trading on the exchange.
121 | */
122 | public static final String api_openOrders = "/api/v3/openOrders";
123 | public static final String api_openOrders_method_get = "GET";
124 | static { uriMethodMap.put(api_openOrders, api_openOrders_method_get); }
125 | public static enum Api_openOrders_params {
126 | symbol("symbol");
127 |
128 | private final String code;
129 |
130 | private Api_openOrders_params(String code) {
131 | this.code = code;
132 | }
133 | public String getCode() {
134 | return code;
135 | }
136 | }
137 |
138 | /**
139 | * GET /api/v3/allOrders (HMAC SHA256)
140 | * Get all account orders; active, canceled, or filled.
141 | * Weight: 5 with symbol
142 | */
143 | public static final String api_allOrders = "/api/v3/allOrders";
144 | public static final String api_allOrders_method_get = "GET";
145 | static { uriMethodMap.put(api_allOrders, api_allOrders_method_get); }
146 | public static enum Api_allOrders_params {
147 | symbol("symbol"),
148 | orderId("orderId"), //LONG NO
149 | startTime("startTime"), //LONG NO
150 | endTime("endTime"), //LONG NO
151 | limit("limit");// INT NO Default 500; max 1000.
152 |
153 | private final String code;
154 |
155 | private Api_allOrders_params(String code) {
156 | this.code = code;
157 | }
158 | public String getCode() {
159 | return code;
160 | }
161 | }
162 |
163 | /**
164 | * GET /wapi/v3/depositHistory.html (HMAC SHA256)
165 | Fetch deposit history.
166 | Weight: 1
167 | *
168 | */
169 | public static final String wapi_depositHistory = "/wapi/v3/depositHistory.html";
170 | public static final String wapi_depositHistory_method_get = "GET";
171 | static { uriMethodMap.put(wapi_depositHistory, wapi_depositHistory_method_get); }
172 | public static enum Wapi_depositHistory_params {
173 | asset("asset"),// STRING NO
174 | status("status"),// INT NO 0(0:pending,1:success)
175 | startTime("startTime"),// LONG NO
176 | endTime("endTime");// LONG NO
177 |
178 | private final String code;
179 |
180 | private Wapi_depositHistory_params(String code) {
181 | this.code = code;
182 | }
183 | public String getCode() {
184 | return code;
185 | }
186 | }
187 |
188 |
189 | /**
190 | * GET /wapi/v3/withdrawHistory.html (HMAC SHA256)
191 | * Fetch withdraw history.
192 | * Weight: 1
193 | */
194 | public static final String wapi_withdrawHistory = "/wapi/v3/withdrawHistory.html";
195 | public static final String wapi_withdrawHistory_method_get = "GET";
196 | static { uriMethodMap.put(wapi_withdrawHistory, wapi_withdrawHistory_method_get); }
197 | public static enum Wapi_withdrawHistory_params {
198 | asset("asset"),// STRING NO
199 | status("status"),// INT NO (0:Email Sent,1:Cancelled 2:Awaiting Approval 3:Rejected 4:Processing 5:Failure 6Completed)
200 | startTime("startTime"),// LONG NO
201 | endTime("endTime");// LONG NO
202 |
203 | private final String code;
204 |
205 | private Wapi_withdrawHistory_params(String code) {
206 | this.code = code;
207 | }
208 | public String getCode() {
209 | return code;
210 | }
211 | }
212 |
213 | /**
214 | * GET /api/v1/ticker/24hr
215 | 24 hour price change statistics. Careful when accessing this with no symbol.
216 | Weight: 1 for a single symbol; 40 when the symbol parameter is omitted
217 | */
218 | public static final String api_ticker_24hr = "/api/v1/ticker/24hr";
219 | public static final String api_ticker_24hr_method_get = "GET";
220 | static { uriMethodMap.put(api_ticker_24hr, api_ticker_24hr_method_get); }
221 | public static enum Api_ticker_24hr_params {
222 | symbol("symbol");// STRING NO
223 |
224 | private final String code;
225 |
226 | private Api_ticker_24hr_params(String code) {
227 | this.code = code;
228 | }
229 | public String getCode() {
230 | return code;
231 | }
232 | }
233 |
234 |
235 | /**
236 | * Recent trades list
237 | *GET /api/v1/trades
238 | *Get recent trades (up to last 500).
239 | */
240 | public static final String api_trades = "/api/v1/trades";
241 | public static final String api_trades_method_get = "GET";
242 | static { uriMethodMap.put(api_trades, api_trades_method_get); }
243 | public static enum Api_trades_params {
244 | symbol("symbol"),// STRING YES
245 | limit("limit");// INT NO Default 500; max 1000.
246 |
247 | private final String code;
248 |
249 | private Api_trades_params(String code) {
250 | this.code = code;
251 | }
252 | public String getCode() {
253 | return code;
254 | }
255 | }
256 |
257 | public static String getMethodByApiUri(String uri) {
258 | return uriMethodMap.get(uri);
259 | }
260 | }
261 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/api/CoinexAPI.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public final class CoinexAPI {
7 |
8 | public static final String API_SIGN_KEY_AccessKeyId = "access_id";
9 | public static final String API_SIGN_KEY_Secret_key = "secret_key";
10 | public static final String API_SIGN_SignatureMethod = "32-bit MD5";
11 | public static final String API_SIGN_KEY_Timestamp = "tonce";
12 | public static final String API_SIGN_KEY_authorization = "authorization";
13 |
14 | private static Map uriMethodMap = new HashMap();
15 | public static final String rest_trading_root = "https://api.coinex.com";
16 | public static final String ws_root = "wss://socket.coinex.com";
17 |
18 |
19 | /**
20 | * 用户资产API
21 | */
22 | public static final String balance_info = "/v1/balance/info";
23 | public static final String balance_info_method_get = "GET";
24 | static { uriMethodMap.put(balance_info, balance_info_method_get); }
25 | public static enum Balance_info_params {
26 |
27 | }
28 |
29 | /**
30 | * Place Limit Order
31 | * Request description:place limit order.
32 | * Request type: POST
33 | * Signature required: Yes
34 | * Request Header:
35 | * authorization:"xxxx" (32-digit capital letters, see generating methos in )
36 | * Request Url:https://api.coinex.com/v1/order/limit
37 | */
38 | public static final String order_path$orderType = "/v1/order/{path$orderType}";
39 | public static final String order_path$orderType_method_post = "POST";
40 | static { uriMethodMap.put(order_path$orderType, order_path$orderType_method_post); }
41 | public static enum Order_path$orderType_params {
42 | path$orderType("{path$orderType}"),
43 | // access_id String Yes access_id
44 | market("market"),// String Yes See
45 | type("type"),// String Yes sell: sell order; buy: buy order;
46 | amount("amount"),// String Yes order amount, min. 0.001, accurate to 8 decimal places
47 | price("price"),// String Yes order amount, accurate to 8 decimal places
48 | source_id("source_id");// String no user defines number and return
49 | // tonce Integer Yes Tonce is a timestamp with a positive Interger that represents the number of milliseconds from Unix epoch to the current time. Error between tonce and server time can not exceed plus or minus 60s
50 |
51 | private final String code;
52 |
53 | private Order_path$orderType_params(String code) {
54 | this.code = code;
55 | }
56 | public String getCode() {
57 | return code;
58 | }
59 | }
60 |
61 | /**
62 | * Cancel Order
63 | * Request description: Cancel unexecuted order.
64 | * Request type: DELETE
65 | * Signature required: Yes
66 | * Request Header: authorization:"xxxx" (32-digit capital letters, see generating methos in )
67 | * Request Url:https://api.coinex.com/v1/order/pending
68 | */
69 | public static final String order_pending = "/v1/order/pending";
70 | public static final String order_pending_method_delete = "DELETE";
71 | static { uriMethodMap.put(order_pending, order_pending_method_delete); }
72 | public static enum Order_pending_params {
73 | // access_id String Yes access_id
74 | id("id"),// Integer Yes Unexecuted order No
75 | market("market");// String Yes See
76 | // tonce Integer Yes
77 |
78 | private final String code;
79 |
80 | private Order_pending_params(String code) {
81 | this.code = code;
82 | }
83 | public String getCode() {
84 | return code;
85 | }
86 | }
87 |
88 |
89 | /**
90 | * Acquire Order Status
91 | * Request description: Acquire order status.
92 | Request type: GET
93 | Signature required: Yes
94 | Request Header:
95 | authorization:"xxxx" (32-digit capital letters, see generating methos in )
96 | Request Url:https://api.coinex.com/v1/order/status
97 | */
98 | public static final String order_status = "/v1/order/status";
99 | public static final String order_status_method_get = "GET";
100 | static { uriMethodMap.put(order_status, order_status_method_get); }
101 | public static enum Order_status_params {
102 | // access_id String Yes access_id
103 | id("id"),// Integer Yes Unexecuted order No
104 | market("market");// String Yes See
105 | // tonce Integer Yes
106 |
107 | private final String code;
108 |
109 | private Order_status_params(String code) {
110 | this.code = code;
111 | }
112 | public String getCode() {
113 | return code;
114 | }
115 | }
116 |
117 | /**
118 | * Acquire Unexecuted Order List
119 | Request description: Acquire Unexecuted Order List.
120 | Request type: GET
121 | Signature required: Yes
122 | Request Header:
123 | authorization:"xxxx" (32-digit capital letters, see generating methos in )
124 | Request Url:https://api.coinex.com/v1/order/pending
125 | */
126 | public static final String order_pending_list = "/v1/order/pending";
127 | public static final String order_pending_list_alias = "order_pending_list";
128 | public static final String order_pending_list_method_get = "GET";
129 | static { uriMethodMap.put(order_pending_list_alias, order_pending_list_method_get); }
130 | public static enum Order_pending_list_params {
131 | // access_id String Yes access_id
132 | market("market"),// String Yes See
133 | page("page"),// Interger Yes Page, start from 1
134 | limit("limit");// Interger Yes Amount per page(1-100)
135 | // tonce Integer Yes
136 |
137 | private final String code;
138 |
139 | private Order_pending_list_params(String code) {
140 | this.code = code;
141 | }
142 | public String getCode() {
143 | return code;
144 | }
145 | }
146 |
147 | /**
148 | * Acquire Executed Order List
149 | Request description: Acquire executed order list, including datas in last 2 days.
150 | Request type: GET
151 | Signature required: Yes
152 | Request Header:
153 | authorization:"xxxx" (32-digit capital letters, see generating methos in )
154 | Request Url:https://api.coinex.com/v1/order/finished
155 | */
156 | public static final String order_finished = "/v1/order/finished";
157 | public static final String order_finished_method_get = "GET";
158 | static { uriMethodMap.put(order_finished, order_finished_method_get); }
159 | public static enum Order_finished_params {
160 | // access_id String Yes access_id
161 | market("market"),// String Yes See
162 | page("page"),// Interger Yes Page, start from 1
163 | limit("limit");// Interger Yes Amount per page(1-100)
164 | // tonce Integer Yes
165 |
166 | private final String code;
167 |
168 | private Order_finished_params(String code) {
169 | this.code = code;
170 | }
171 | public String getCode() {
172 | return code;
173 | }
174 | }
175 |
176 | /**
177 | * Request description: Acquire real-time market data
178 | Request type: GET
179 | Signature required: No
180 | Request Url: https://api.coinex.com/v1/market/ticker?market=BTCBCH
181 | */
182 | public static final String market_ticker = "/v1/market/ticker";
183 | public static final String market_ticker_method_get = "GET";
184 | static { uriMethodMap.put(market_ticker, market_ticker_method_get); }
185 | public static enum Market_ticker_params {
186 | market("market");// String Yes See
187 |
188 | private final String code;
189 |
190 | private Market_ticker_params(String code) {
191 | this.code = code;
192 | }
193 | public String getCode() {
194 | return code;
195 | }
196 | }
197 |
198 |
199 | /**
200 | * Acquire Latest Transaction Data
201 | Request description: Acquire latest transaction data,return up to 1000
202 | Request type: GET
203 | Signature required: No
204 | Request Url:https://api.coinex.com/v1/market/deals
205 | *
206 | */
207 | public static final String market_deals = "/v1/market/deals";
208 | public static final String market_deals_method_get = "GET";
209 | static { uriMethodMap.put(market_deals, market_deals_method_get); }
210 | public static enum Market_deals_params {
211 | market("market"),// String Yes See
212 | last_id("last_id");// Interger No Transaction history id, send 0 to draw from the latest record.
213 |
214 | private final String code;
215 |
216 | private Market_deals_params(String code) {
217 | this.code = code;
218 | }
219 | public String getCode() {
220 | return code;
221 | }
222 | }
223 |
224 | public static String getMethodByApiUri(String uri) {
225 | return uriMethodMap.get(uri);
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/api/HoubiAPI.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public final class HoubiAPI {
7 |
8 | // POST请求头信息中必须声明 Content-Type:application/json;
9 | // GET请求头信息中必须声明 Content-Type:application/x-www-form-urlencoded。
10 | // (汉语用户建议设置 Accept-Language:zh-cn)
11 | //
12 | // 请务必在header中设置user agent为 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'
13 |
14 | public static final String API_SIGN_KEY_AccessKeyId = "AccessKeyId";//=e2xxxxxx-99xxxxxx-84xxxxxx-7xxxx
15 | public static final String API_SIGN_KEY_SignatureMethod = "SignatureMethod";//=HmacSHA256
16 | public static final String API_SIGN_SignatureMethod = "HmacSHA256";//=HmacSHA256
17 | public static final String API_SIGN_KEY_SignatureVersion = "SignatureVersion";//=2
18 | public static final String API_SIGN_SignatureVersion = "2";//=2
19 | public static final String API_SIGN_KEY_Timestamp = "Timestamp";//=2017-05-11T15%3A19%3A30
20 |
21 | private static Map uriMethodMap = new HashMap();
22 | public static final String rest_market_root = "https://api.huobi.pro";
23 | public static final String rest_trading_root = "https://api.huobi.pro";//https://api.huobi.pro/v1/common/symbols
24 | public static final String ws_root = "wss://api.huobi.pro/ws";
25 |
26 |
27 | /**
28 | * 用户资产API
29 | */
30 | public static final String account_accounts = "/v1/account/accounts";
31 | public static final String account_accounts_method_get = "GET";
32 | static { uriMethodMap.put(account_accounts, account_accounts_method_get); }
33 | public static enum Account_accounts_params {
34 |
35 | }
36 |
37 | /**
38 | * 下单
39 | */
40 | public static final String order_orders_place = "/v1/order/orders/place";
41 | public static final String order_orders_place_method_post = "POST";
42 | static { uriMethodMap.put(order_orders_place, order_orders_place_method_post); }
43 | public static enum Order_orders_place_params {
44 | // true string 账户 ID,使用accounts方法获得。币币交易使用‘spot’账户的accountid;借贷资产交易,请使用‘margin’账户的accountid
45 | account_id("account-id"),
46 | // true string 限价单表示下单数量,市价买单时表示买多少钱,市价卖单时表示卖多少币
47 | amount("amount"),
48 | // false string 下单价格,市价单不传该参数
49 | price("price"),
50 | // false string 订单来源 api,如果使用借贷资产交易,请填写‘margin-api’
51 | source("source"),
52 | // true string 交易对 btcusdt, bchbtc, rcneth ...
53 | symbol("symbol"),
54 | // true string 订单类型 buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖, buy-ioc:IOC买单, sell-ioc:IOC卖单, buy-limit-maker, sell-limit-maker(详细说明见下)
55 | type("type");
56 |
57 | private final String code;
58 |
59 | private Order_orders_place_params(String code) {
60 | this.code = code;
61 | }
62 | public String getCode() {
63 | return code;
64 | }
65 | }
66 |
67 |
68 | /**
69 | * 取消
70 | * /v1/order/orders/{order-id}/submitcancel
71 | */
72 | public static final String order_orders_path$orderId_submitcancel = "/v1/order/orders/{path$orderId}/submitcancel";
73 | public static final String order_orders_path$orderId_submitcancel_method_post = "POST";
74 | static { uriMethodMap.put(order_orders_path$orderId_submitcancel, order_orders_path$orderId_submitcancel_method_post); }
75 | public static enum Order_orders_path$orderId_submitcancel_params {
76 | path$orderId("{path$orderId}");
77 |
78 | private final String code;
79 |
80 | private Order_orders_path$orderId_submitcancel_params(String code) {
81 | this.code = code;
82 | }
83 | public String getCode() {
84 | return code;
85 | }
86 |
87 | }
88 |
89 | /**
90 | * 订单信息
91 | * GET /v1/order/orders/{order-id}
92 | */
93 | public static final String order_orders_path$orderId = "/v1/order/orders/{path$orderId}";
94 | public static final String order_orders_path$orderId_method_get = "GET";
95 | static { uriMethodMap.put(order_orders_path$orderId, order_orders_path$orderId_method_get); }
96 | public static enum Order_orders_path$orderId_params {
97 | path$orderId("{path$orderId}");
98 |
99 | private final String code;
100 |
101 | private Order_orders_path$orderId_params(String code) {
102 | this.code = code;
103 | }
104 | public String getCode() {
105 | return code;
106 | }
107 |
108 | }
109 |
110 | /**
111 | * GET /v1/order/openOrders 获取所有当前帐号下未成交订单
112 | * “account-id” 和 “symbol” 需同时指定或者二者都不指定。如果二者都不指定,返回最多500条尚未成交订单,按订单号降序排列。
113 | */
114 | public static final String order_openOrders = "/v1/order/openOrders";
115 | public static final String order_openOrders_method_get = "GET";
116 | static { uriMethodMap.put(order_openOrders, order_openOrders_method_get); }
117 | public static enum Order_openOrders_params {
118 | // true string 账号ID
119 | account_id("account-id"),
120 | // true string 交易对 单个交易对字符串,缺省将返回所有符合条件尚未成交订单
121 | symbol("symbol"),
122 | // false string 主动交易方向 “buy”或者“sell”,缺省将返回所有符合条件尚未成交订单
123 | side("side"),
124 | // false int 所需返回记录数 10 [0,500]
125 | size("size");
126 |
127 | private final String code;
128 |
129 | private Order_openOrders_params(String code) {
130 | this.code = code;
131 | }
132 | public String getCode() {
133 | return code;
134 | }
135 |
136 | }
137 |
138 | /**
139 | * GET /v1/order/orders 查询当前委托、历史委托
140 | */
141 | public static final String order_orders = "/v1/order/orders";
142 | public static final String order_orders_method_get = "GET";
143 | static { uriMethodMap.put(order_orders, order_orders_method_get); }
144 | public static enum Order_orders_params {
145 | //true string 交易对 btcusdt, bchbtc, rcneth ...
146 | symbol("symbol"),
147 | //false string 查询的订单类型组合,使用','分割 buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖, buy-ioc:IOC买单, sell-ioc:IOC卖单
148 | types("types"),
149 | //false string 查询开始日期, 日期格式yyyy-mm-dd
150 | start_date("start-date"),
151 | //false string 查询结束日期, 日期格式yyyy-mm-dd
152 | end_date("end-date"),
153 | //true string 查询的订单状态组合,使用','分割 submitted 已提交, partial-filled 部分成交, partial-canceled 部分成交撤销, filled 完全成交, canceled 已撤销
154 | states("states"),
155 | //false string 查询起始 ID
156 | from("from"),
157 | //false string 查询方向 prev 向前,next 向后
158 | direct("direct"),
159 | //false string 查询记录大小
160 | size("size");
161 |
162 | private final String code;
163 |
164 | private Order_orders_params(String code) {
165 | this.code = code;
166 | }
167 | public String getCode() {
168 | return code;
169 | }
170 |
171 | }
172 |
173 | /**
174 | * GET /v1/query/deposit-withdraw 查询虚拟币充提记录
175 | */
176 | public static final String query_deposit_withdraw = "/v1/query/deposit-withdraw";
177 | public static final String query_deposit_withdraw_method_get = "GET";
178 | static { uriMethodMap.put(query_deposit_withdraw, query_deposit_withdraw_method_get); }
179 | public static enum Query_deposit_withdraw_params {
180 | //true string 币种
181 | currency("currency"),
182 | // //true string 'deposit' or 'withdraw'
183 | type("type"),
184 | //false string 查询起始 ID
185 | from("from"),
186 | //false string 查询记录大小
187 | size("size");
188 |
189 | private final String code;
190 |
191 | private Query_deposit_withdraw_params(String code) {
192 | this.code = code;
193 | }
194 | public String getCode() {
195 | return code;
196 | }
197 |
198 | }
199 |
200 |
201 |
202 | /**
203 | * 查询Pro站指定账户的余额
204 | * /v1/account/accounts/4276741/balance
205 | */
206 | public static final String accounts_p$accountId_balance = "/v1/account/accounts/{path$accountId}/balance";
207 | public static final String accounts_p$accountId_balance_method_get = "GET";
208 | static { uriMethodMap.put(accounts_p$accountId_balance, accounts_p$accountId_balance_method_get); }
209 | public static enum Accounts_p$accountId_balance_params {
210 | path$accountId("{path$accountId}");
211 |
212 | private final String code;
213 |
214 | private Accounts_p$accountId_balance_params(String code) {
215 | this.code = code;
216 | }
217 | public String getCode() {
218 | return code;
219 | }
220 |
221 | }
222 |
223 | /**
224 | * GET /market/detail/merged 获取聚合行情(Ticker)
225 | */
226 | public static final String market_detail_merged = "/market/detail/merged";
227 | public static final String market_detail_merged_method_get = "GET";
228 | static { uriMethodMap.put(market_detail_merged, market_detail_merged_method_get); }
229 | public static enum Market_detail_merged_params {
230 | symbol("symbol");// true string 交易对 btcusdt, bchbtc, rcneth ...
231 |
232 | private final String code;
233 |
234 | private Market_detail_merged_params(String code) {
235 | this.code = code;
236 | }
237 | public String getCode() {
238 | return code;
239 | }
240 |
241 | }
242 |
243 | /**
244 | * GET /market/history/trade 批量获取最近的交易记录
245 | */
246 | public static final String market_history_trade = "/market/history/trade";
247 | public static final String market_history_trade_method_get = "GET";
248 | static { uriMethodMap.put(market_history_trade, market_history_trade_method_get); }
249 | public static enum Market_history_trade_params {
250 | symbol("symbol"),// true string 交易对 btcusdt, bchbtc, rcneth ...
251 | size("size");// false integer 获取交易记录的数量 1 [1, 2000]
252 |
253 | private final String code;
254 |
255 | private Market_history_trade_params(String code) {
256 | this.code = code;
257 | }
258 | public String getCode() {
259 | return code;
260 | }
261 |
262 | }
263 |
264 | public static String getMethodByApiUri(String uri) {
265 | return uriMethodMap.get(uri);
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/api/OkexAPI.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.api;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | public final class OkexAPI {
7 |
8 |
9 | public static final String API_SIGN_KEY_AccessKeyId = "api_key";
10 | public static final String API_SIGN_KEY_Secret_key = "secret_key";
11 | public static final String API_SIGN_SignatureMethod = "32-bit MD5";
12 | public static final String API_SIGN_KEY_authorization = "sign";
13 |
14 | private static Map uriMethodMap = new HashMap();
15 | public static final String rest_trading_root = "https://www.okex.com";
16 | public static final String ws_root = "wss://real.okex.com:10441/websocket";
17 |
18 |
19 | /**
20 | * 用户资产API
21 | */
22 | public static final String api_userinfo = "/api/v1/userinfo.do";
23 | public static final String api_userinfo_method_post = "POST";
24 | static { uriMethodMap.put(api_userinfo, api_userinfo_method_post); }
25 | public static enum Api_userinfo_params {
26 |
27 | }
28 |
29 | /**
30 | * POST /api/v1/trade 下单交易
31 | * URL https://www.okex.com/api/v1/trade.do 访问频率 20次/2秒
32 | */
33 | public static final String api_trade = "/api/v1/trade.do";
34 | public static final String api_trade_method_post = "POST";
35 | static { uriMethodMap.put(api_trade, api_trade_method_post); }
36 | public static enum Api_trade_params {
37 | // api_key String 是 用户申请的apiKey
38 | symbol("symbol"),// String 是 币对如ltc_btc
39 | type("type"),// String 是 买卖类型:限价单(buy/sell) 市价单(buy_market/sell_market)
40 | price("price"),// Double 否 下单价格 市价卖单不传price
41 | amount("amount");// Double 否 交易数量 市价买单不传amount,市价买单需传price作为买入总金额
42 | // sign String 是 请求参数的签名
43 |
44 | private final String code;
45 |
46 | private Api_trade_params(String code) {
47 | this.code = code;
48 | }
49 | public String getCode() {
50 | return code;
51 | }
52 | }
53 |
54 | /**
55 | * POST /api/v1/cancel_order 撤销订单
56 | * URL https://www.okex.com/api/v1/cancel_order.do 访问频率 20次/2秒
57 | * result:true撤单请求成功,等待系统执行撤单;false撤单失败(用于单笔订单)
58 | * order_id:订单ID(用于单笔订单)
59 | * success:撤单请求成功的订单ID,等待系统执行撤单(用于多笔订单)
60 | * error:撤单请求失败的订单ID(用户多笔订单)
61 | */
62 | public static final String api_cancel_order = "/api/v1/cancel_order.do";
63 | public static final String api_cancel_order_method_post = "POST";
64 | static { uriMethodMap.put(api_cancel_order, api_cancel_order_method_post); }
65 | public static enum Api_cancel_order_params {
66 | // api_key String 是 用户申请的apiKey
67 | symbol("symbol"),// String 是 币对如ltc_btc
68 | order_id("order_id");// 订单ID(多个订单ID中间以","分隔,一次最多允许撤消3个订单)
69 | // sign String 是 请求参数的签名
70 |
71 | private final String code;
72 |
73 | private Api_cancel_order_params(String code) {
74 | this.code = code;
75 | }
76 | public String getCode() {
77 | return code;
78 | }
79 | }
80 |
81 | /**
82 | * POST /api/v1/order_info 获取用户的订单信息
83 | * URL https://www.okex.com/api/v1/order_info.do 访问频率 20次/2秒(未成交)
84 | */
85 | public static final String api_order_info = "/api/v1/order_info.do";
86 | public static final String api_order_info_method_post = "POST";
87 | static { uriMethodMap.put(api_order_info, api_order_info_method_post); }
88 | public static enum Api_order_info_params {
89 | // api_key String 是 用户申请的apiKey
90 | symbol("symbol"),// String 是 币对如ltc_btc
91 | order_id("order_id");// 订单ID -1:未完成订单,否则查询相应订单号的订单
92 | // sign String 是 请求参数的签名
93 |
94 | private final String code;
95 |
96 | private Api_order_info_params(String code) {
97 | this.code = code;
98 | }
99 | public String getCode() {
100 | return code;
101 | }
102 | }
103 |
104 | /**
105 | * POST /api/v1/orders_info 批量获取用户订单
106 | * URL https://www.okex.com/api/v1/orders_info.do 访问频率 20次/2秒
107 | */
108 | public static final String api_orders_info = "/api/v1/orders_info.do";
109 | public static final String api_orders_info_method_post = "POST";
110 | static { uriMethodMap.put(api_orders_info, api_orders_info_method_post); }
111 | public static enum Api_orders_info_params {
112 | // api_key String 是 用户申请的apiKey
113 | type("type"),// Integer 是 查询类型 0:未完成的订单 1:已经完成的订单
114 | symbol("symbol"),// String 是 币对如ltc_btc
115 | order_id("order_id");// 订单ID(多个订单ID中间以","分隔,一次最多允许查询50个订单)
116 | // sign String 是 请求参数的签名
117 |
118 | private final String code;
119 |
120 | private Api_orders_info_params(String code) {
121 | this.code = code;
122 | }
123 | public String getCode() {
124 | return code;
125 | }
126 | }
127 |
128 | /**
129 | * POST /api/v1/order_history 获取历史订单信息,只返回最近两天的信息
130 | * URL https://www.okex.com/api/v1/order_history.do
131 | */
132 | public static final String api_order_history = "/api/v1/order_history.do";
133 | public static final String api_order_history_method_post = "POST";
134 | static { uriMethodMap.put(api_order_history, api_order_history_method_post); }
135 | public static enum Api_order_history_params {
136 | // api_key String 是 用户申请的apiKey
137 | symbol("symbol"),// String 是 币对如ltc_btc
138 | status("status"),// Integer 是 查询状态 0:未完成的订单 1:已经完成的订单(最近两天的数据)
139 | current_page("current_page"),// Integer 是 当前页数
140 | page_length("page_length");// Integer 是 每页数据条数,最多不超过200
141 | // sign String 是 请求参数的签名
142 |
143 | private final String code;
144 |
145 | private Api_order_history_params(String code) {
146 | this.code = code;
147 | }
148 | public String getCode() {
149 | return code;
150 | }
151 | }
152 |
153 | /**
154 | * Get /api/v1/ticker 获取OKEx币币行情
155 | URL https://www.okex.com/api/v1/ticker.do
156 | * @param uri
157 | * @return
158 | */
159 | public static final String api_ticker = "/api/v1/ticker.do";
160 | public static final String api_ticker_method_get = "GET";
161 | static { uriMethodMap.put(api_ticker, api_ticker_method_get); }
162 | public static enum Api_ticker_params {
163 | symbol("symbol");// String 是 币对如ltc_btc
164 |
165 | private final String code;
166 |
167 | private Api_ticker_params(String code) {
168 | this.code = code;
169 | }
170 | public String getCode() {
171 | return code;
172 | }
173 | }
174 |
175 | /**
176 | * Get /api/v1/trades 获取OKEx币币交易信息(60条)
177 | URL https://www.okex.com/api/v1/trades.do
178 | */
179 | public static final String api_trades = "/api/v1/trades.do";
180 | public static final String Api_trades_method_get = "GET";
181 | static { uriMethodMap.put(api_trades, Api_trades_method_get); }
182 | public static enum Api_trades_params {
183 | symbol("symbol"), //String 是 币对如ltc_btc
184 | since("since");// Long 否(默认返回最近成交60条) tid:交易记录ID(返回数据不包括当前tid值,最多返回60条数据)
185 |
186 | private final String code;
187 |
188 | private Api_trades_params(String code) {
189 | this.code = code;
190 | }
191 | public String getCode() {
192 | return code;
193 | }
194 | }
195 |
196 | public static String getMethodByApiUri(String uri) {
197 | return uriMethodMap.get(uri);
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/coins/BinanceProfiles.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.coins;
2 |
3 | import org.apache.http.client.fluent.Request;
4 | public class BinanceProfiles {
5 |
6 | /**
7 | * All requests based on the Https protocol should set the request header information Content-Type as:'application/json’.
8 | * Request header information must be declared:
9 | * User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
10 | * Request submission frequency: 20 times per second per IP (for Trading and Account API); no limit on Market API
11 | *
12 | * @param request
13 | */
14 | public static void addHeader(Request request, String method) {
15 | request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
16 | request.addHeader("Content-Type", "application/x-www-form-urlencoded");
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/coins/CoinexProfiles.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.coins;
2 |
3 | import org.apache.http.client.fluent.Request;
4 |
5 | public class CoinexProfiles {
6 |
7 | /**
8 | * All requests based on the Https protocol should set the request header information Content-Type as:'application/json’.
9 | * Request header information must be declared:
10 | * User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
11 | * Request submission frequency: 20 times per second per IP (for Trading and Account API); no limit on Market API
12 | *
13 | * @param request
14 | */
15 | public static void addHeader(Request request, String method) {
16 | request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
17 | request.addHeader("Content-Type", "application/json");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/coins/HuobiProfiles.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.coins;
2 |
3 | import org.apache.http.client.fluent.Request;
4 | public class HuobiProfiles {
5 |
6 | /**
7 | * POST请求头信息中必须声明 Content-Type:application/json;
8 | * GET请求头信息中必须声明 Content-Type:application/x-www-form-urlencoded。
9 | * (汉语用户建议设置 Accept-Language:zh-cn)
10 | *
11 | * 请务必在header中设置user agent为 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36'
12 | *
13 | * Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36
14 | Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 《-
15 | Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
16 | *
17 | * @param request
18 | */
19 | public static void addHeader(Request request, String method) {
20 | request.addHeader("Accept-Language", "zh-cn");
21 | request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
22 | if (org.springframework.http.HttpMethod.GET.name().equalsIgnoreCase(method)) {
23 | request.addHeader("Content-Type", "application/x-www-form-urlencoded");
24 | } else {
25 | request.addHeader("Content-Type", "application/json");
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/coins/OkexProfiles.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.coins;
2 |
3 | import org.apache.http.client.fluent.Request;
4 |
5 | public class OkexProfiles {
6 |
7 | /**
8 | * All requests based on the Https protocol should set the request header information Content-Type as:'application/json’.
9 | * Request header information must be declared:
10 | * User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
11 | * Request submission frequency: 20 times per second per IP (for Trading and Account API); no limit on Market API
12 | *
13 | * @param request
14 | */
15 | public static void addHeader(Request request, String method) {
16 | // request.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
17 | request.addHeader("Content-Type", "application/x-www-form-urlencoded");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/common/JacksonHelper.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.common;
2 |
3 | import java.io.IOException;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | import com.fasterxml.jackson.annotation.JsonInclude;
8 | import com.fasterxml.jackson.core.JsonParseException;
9 | import com.fasterxml.jackson.core.type.TypeReference;
10 | import com.fasterxml.jackson.databind.DeserializationFeature;
11 | import com.fasterxml.jackson.databind.JavaType;
12 | import com.fasterxml.jackson.databind.JsonMappingException;
13 | import com.fasterxml.jackson.databind.ObjectMapper;
14 | import com.fasterxml.jackson.databind.PropertyNamingStrategy;
15 | import com.fasterxml.jackson.databind.SerializationFeature;
16 |
17 | public final class JacksonHelper {
18 |
19 | private static final ObjectMapper objectMapper = createObjectMapper();
20 | public static final JavaType mapType = objectMapper.getTypeFactory().constructParametricType(HashMap.class, String.class, Object.class);
21 |
22 | public static String writeValueAsString(Object obj) throws IOException {
23 | return objectMapper.writeValueAsString(obj);
24 | }
25 |
26 | public static T readValue(String s, TypeReference ref) throws IOException {
27 | return objectMapper.readValue(s, ref);
28 | }
29 |
30 | public static ObjectMapper getMapper() {
31 | return objectMapper;
32 | }
33 |
34 |
35 | static ObjectMapper createObjectMapper() {
36 | final ObjectMapper mapper = new ObjectMapper();
37 | mapper.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE);
38 | mapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
39 | // disabled features:
40 | mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
41 | mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
42 | mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
43 | return mapper;
44 | }
45 |
46 | public static Map getJsonMap(String jsonStr) {
47 | Map jsonMap = null;
48 | try {
49 | jsonMap = (Map) objectMapper.readValue(jsonStr, JacksonHelper.mapType);
50 | } catch (JsonParseException e) {
51 | // TODO Auto-generated catch block
52 | e.printStackTrace();
53 | } catch (JsonMappingException e) {
54 | // TODO Auto-generated catch block
55 | e.printStackTrace();
56 | } catch (IOException e) {
57 | // TODO Auto-generated catch block
58 | e.printStackTrace();
59 | }
60 | return jsonMap;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/common/RequestUtils.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.common;
2 |
3 | import java.io.IOException;
4 | import java.nio.charset.Charset;
5 | import java.nio.charset.UnsupportedCharsetException;
6 | import java.util.Map;
7 |
8 | import org.apache.http.HttpHost;
9 | import org.apache.http.client.fluent.Form;
10 | import org.apache.http.client.fluent.Request;
11 | import org.apache.http.entity.ContentType;
12 |
13 | public class RequestUtils {
14 |
15 |
16 | /**
17 | *
18 | * @param request
19 | * @param params
20 | * @param charset
21 | */
22 | public static void addForm(Request request, Map params, String charset) {
23 | Form form = Form.form();
24 | for(Map.Entry entry : params.entrySet()) {
25 | if (!entry.getKey().startsWith(Constants.PATH_PARAM_PREFIX)) {
26 | form.add(entry.getKey(), entry.getValue());
27 | }
28 | }
29 |
30 | request.bodyForm(form.build(), Charset.forName(charset));
31 | }
32 |
33 | public static void addJson(Request request, Map params, String charset) throws UnsupportedCharsetException, IOException {
34 | // Iterator> it = params.entrySet().iterator();
35 | // while(it.hasNext()){
36 | // Map.Entry entry = it.next();
37 | // if (entry.getKey().startsWith(Constants.PATH_PARAM_PREFIX)) {
38 | // it.remove();
39 | // }
40 | // }
41 |
42 | request.bodyString(JacksonHelper.writeValueAsString(params), ContentType.create("application/json", charset));
43 | }
44 |
45 | /**
46 | *
47 | * @param request
48 | */
49 | public static void setProxy(Request request) {
50 | HttpHost proxy = new HttpHost("localhost", 1080);
51 | request.viaProxy(proxy);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/mumu/exchange/market/BinanceMarketService.java:
--------------------------------------------------------------------------------
1 | package com.mumu.exchange.market;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.Iterator;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 |
10 | import org.apache.commons.lang3.ArrayUtils;
11 | import org.apache.commons.lang3.StringUtils;
12 | import org.apache.http.client.fluent.Content;
13 | import org.apache.http.client.fluent.Form;
14 | import org.apache.http.client.fluent.Request;
15 | import com.mumu.beans.DealtInfo;
16 | import com.mumu.beans.Market;
17 | import com.mumu.exchange.api.BinanceAPI;
18 | import com.mumu.exchange.coins.BinanceProfiles;
19 | import com.mumu.exchange.common.JacksonHelper;
20 | import com.mumu.exchange.common.RequestUtils;
21 | import com.mumu.exchange.signature.BinanceParamsSigner;
22 | import com.mumu.exchange.signature.CoinexParamsSigner;
23 | import com.mumu.exchange.signature.ISignature;
24 |
25 | public class BinanceMarketService extends MarketService implements IMarketService {
26 |
27 | /**
28 | * If the symbol is not sent, tickers for all symbols will be returned in an array.
29 | *
30 | {"symbol":"BNBBTC",
31 | "priceChange":"0.00006740",
32 | "priceChangePercent":"4.465",
33 | "weightedAvgPrice":"0.00153351",
34 | "prevClosePrice":"0.00151040",
35 | "lastPrice":"0.00157690",
36 | "lastQty":"0.08000000",
37 | "bidPrice":"0.00157670",
38 | "bidQty":"1.11000000",
39 | "askPrice":"0.00157690",
40 | "askQty":"0.92000000",
41 | "openPrice":"0.00150950",
42 | "highPrice":"0.00158590",
43 | "lowPrice":"0.00148020",
44 | "volume":"900996.21000000",
45 | "quoteVolume":"1381.68836299",
46 | "openTime":1534388378877,
47 | "closeTime":1534474778877,
48 | "firstId":26740356,
49 | "lastId":26800274,
50 | "count":59919
51 | }
52 | */
53 | @Override
54 | public List quotationTicker(String accessKey, String secretkey, String... symbols) {
55 | String param = null;
56 | if (ArrayUtils.isNotEmpty(symbols)) {
57 | param = Arrays.toString(symbols);
58 | }
59 |
60 | ISignature signature = new BinanceParamsSigner();
61 | signature.setApiRoot(BinanceAPI.rest_trading_root);
62 | signature.setApiUri(BinanceAPI.api_ticker_24hr);
63 | if (StringUtils.isNotBlank(param)) {
64 | signature.putParam(BinanceAPI.Api_ticker_24hr_params.symbol.getCode(), StringUtils.trim(param.substring(1, (param.length() - 1))));
65 | }
66 | String uri = signature.getUri(BinanceAPI.api_ticker_24hr_method_get, CoinexParamsSigner.charset_utf8);
67 | logger.warn("uri=" + uri);
68 | Content content = null;
69 | try {
70 | Request request = Request.Get(uri);
71 | RequestUtils.setProxy(request);
72 | BinanceProfiles.addHeader(request, BinanceAPI.api_ticker_24hr_method_get);
73 | content = request
74 | .execute()
75 | .returnContent();
76 |
77 |
78 | String result = "{\"list\":" +content.asString() +"}";
79 | logger.warn("ticker=" + result);
80 | Map jsonMap = JacksonHelper.getJsonMap(result);
81 | List listMarket = null;
82 | Market market = null;
83 | if (null != symbols) {
84 | listMarket = new ArrayList(1);
85 | jsonMap = (Map) jsonMap.get("list");
86 |
87 | market = new Market();
88 | market.setAmount(new Double(jsonMap.get("volume").toString()));
89 | market.setAsk(new Double(jsonMap.get("askPrice").toString()));
90 | market.setAskVolume(new Double(jsonMap.get("askQty").toString()));
91 | market.setBid(new Double(jsonMap.get("bidPrice").toString()));
92 | market.setBidVolume(new Double(jsonMap.get("bidQty").toString()));
93 | market.setHighest(new Double(jsonMap.get("highPrice").toString()));
94 | market.setLast(new Double(jsonMap.get("lastPrice").toString()));
95 | market.setLowest(new Double(jsonMap.get("lowPrice").toString()));
96 | market.setOpen(new Double(jsonMap.get("openPrice").toString()));
97 | market.setSymbol(jsonMap.get("symbol").toString());
98 | market.setTs(Long.valueOf(jsonMap.get("closeTime").toString()));
99 | market.setVolume(new Double(jsonMap.get("count").toString()));
100 | listMarket.add(market);
101 |
102 | return listMarket;
103 | } else {
104 | List