1 package org.oxerr.okcoin.rest.dto;
2
3 import java.math.BigDecimal;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.apache.http.NameValuePair;
8 import org.apache.http.message.BasicNameValuePair;
9
10 import com.fasterxml.jackson.annotation.JsonProperty;
11 import com.fasterxml.jackson.core.JsonProcessingException;
12 import com.fasterxml.jackson.databind.ObjectMapper;
13
14 public class TradeParam extends BaseObject {
15
16 private static final long serialVersionUID = 2013122101L;
17
18 @JsonProperty
19 private BigDecimal tradeAmount;
20
21 @JsonProperty
22 private BigDecimal tradeCnyPrice;
23
24 @JsonProperty
25 private String tradePwd;
26
27 @JsonProperty
28 private int symbol;
29
30 @JsonProperty
31 private int limited = 0;
32
33 public TradeParam(BigDecimal tradeAmount, BigDecimal tradeCnyPrice,
34 String tradePwd, int symbol) {
35 this.tradeAmount = tradeAmount;
36 this.tradeCnyPrice = tradeCnyPrice;
37 this.tradePwd = tradePwd;
38 this.symbol = symbol;
39 }
40
41
42
43
44 public BigDecimal getTradeAmount() {
45 return tradeAmount;
46 }
47
48
49
50
51 public void setTradeAmount(BigDecimal tradeAmount) {
52 this.tradeAmount = tradeAmount;
53 }
54
55
56
57
58 public BigDecimal getTradeCnyPrice() {
59 return tradeCnyPrice;
60 }
61
62
63
64
65 public void setTradeCnyPrice(BigDecimal tradeCnyPrice) {
66 this.tradeCnyPrice = tradeCnyPrice;
67 }
68
69
70
71
72 public String getTradePwd() {
73 return tradePwd;
74 }
75
76
77
78
79 public void setTradePwd(String tradePwd) {
80 this.tradePwd = tradePwd;
81 }
82
83
84
85
86 public int getSymbol() {
87 return symbol;
88 }
89
90
91
92
93 public void setSymbol(int symbol) {
94 this.symbol = symbol;
95 }
96
97 public String toJson() {
98 ObjectMapper mapper = new ObjectMapper();
99 try {
100 return mapper.writeValueAsString(this);
101 } catch (JsonProcessingException e) {
102 throw new RuntimeException(e);
103 }
104 }
105
106 public String toUrlencoded() {
107 return String.format("tradeAmount=%1$s&tradeCnyPrice=%2$s&tradePwd=%3$s&symbol=%4$d&limited=%5$s",
108 getTradeAmount().toPlainString(),
109 getTradeCnyPrice().toPlainString(),
110 getTradePwd(),
111 getSymbol(),
112 limited);
113 }
114
115 public List<NameValuePair> toNameValurPairs() {
116 List<NameValuePair> params = new ArrayList<>(5);
117 params.add(new BasicNameValuePair("tradeAmount", getTradeAmount().toPlainString()));
118 params.add(new BasicNameValuePair("tradeCnyPrice", getTradeCnyPrice().toPlainString()));
119 params.add(new BasicNameValuePair("tradePwd", getTradePwd()));
120 params.add(new BasicNameValuePair("symbol", String.valueOf(getSymbol())));
121 params.add(new BasicNameValuePair("limited", String.valueOf(limited)));
122 return params;
123 }
124
125 }