Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SymbolV2Parser #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

<properties>
<java.version>1.8</java.version>
<okhttp3.version>4.5.0</okhttp3.version>
<fastjson.version>1.2.47</fastjson.version>
<okhttp3.version>5.0.0-alpha.9</okhttp3.version>
<fastjson.version>2.0.9.graal</fastjson.version>
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
</properties>

Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<version>1.4.14</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<SymbolV2> getSymbolsV2(Long ts) {
.putToUrl("ts", ts);
JSONObject jsonObject = restConnection.executeGet(GET_SYMBOLS_PATH_V2, builder);
JSONArray data = jsonObject.getJSONArray("data");
return new SymbolV2Parser().parseArray(data);
return new SymbolV2Parser().parseArray(data).subList(0, Math.toIntExact(ts));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,72 @@

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.huobi.model.generic.Person;
import com.huobi.model.generic.Symbol;
import com.huobi.model.generic.SymbolV2;
import com.huobi.service.huobi.parser.HuobiModelParser;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class SymbolV2Parser implements HuobiModelParser<SymbolV2> {

@Override
public SymbolV2 parse(JSONObject json) {
return json.toJavaObject(SymbolV2.class);
if (json.get("p1") == null)
return null;

SymbolV2 result = new SymbolV2();
result.setP1(new Person(((JSONObject)((JSONArray) json.get("p1")).getFirst()).getInteger("id"),
((JSONObject)((JSONArray) json.get("p1")).getFirst()).getString("name"),
((JSONObject)((JSONArray) json.get("p1")).getFirst()).getInteger("weight")));
result.setBc(json.getString("bc"));
result.setLr(json.getBigDecimal("lr"));
result.setToa(json.getLong("toa"));
result.setFp(json.getBigDecimal("fp"));
result.setDn(json.getString("dn"));
result.setSc(json.getString("sc"));
result.setQc(json.getString("qc"));
result.setState(json.getString("state"));
result.setWr(json.getString("wr"));
result.setSp(json.getString("sp"));
result.setCd(json.getBoolean("cd"));
result.setTap(json.getBigDecimal("tap"));
result.setBcdn(json.getString("bcdn"));
result.setQcdn(json.getString("qcdn"));
result.setTe(json.getBoolean("te"));
result.setTtp(json.getBigDecimal("ttp"));
result.setTpp(json.getBigDecimal("tpp"));
result.setWhe(json.getBoolean("whe"));
result.setW(json.getInteger("w"));

return result;
}

@Override
public SymbolV2 parse(JSONArray json) {
System.out.println(json);
return null;
}

public SymbolV2 parse(Object json) {
if (json instanceof JSONArray)
return parse((JSONArray) json);
else
return parse((JSONObject) json);
}

@Override
public List<SymbolV2> parseArray(JSONArray jsonArray) {
if (jsonArray == null || jsonArray.size() <= 0) {
return new ArrayList<>();
}

List<SymbolV2> list = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
list.add(parse(jsonArray.getJSONObject(i)));
}
return list;
return (List<SymbolV2>) jsonArray.stream()
.map(this::parse)
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}