Skip to content

Commit

Permalink
更新JavaSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
XylonXG committed Jul 6, 2020
1 parent a032bd2 commit 70f9911
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public class OrderBookDiffer {
}*/

//20200507 添加参数 order: 1正向排序 2反向排序
public <T extends OrderBookItem> List<T> diff(List<T> current, List<T> snapshot,
final Comparator<String> comparator) {
final Comparator<String> comparator,int order) {

//增量的数组
final Iterator<T> snapshotIter = snapshot.iterator();
//现有全量的数据
Expand All @@ -74,8 +76,15 @@ public <T extends OrderBookItem> List<T> diff(List<T> current, List<T> snapshot,


for (;;) {
final int compare = comparator.compare(snapshotBookItem.getPrice(), currentBookItem.getPrice());
//final int compare = comparator.compare(spotOrderBookItems[0], currentBookItems[0]);
// final int compare = comparator.compare(snapshotBookItem.getPrice(), currentBookItem.getPrice());
double currentPrc = Double.parseDouble(currentBookItem.getPrice());
double snapPrc = Double.parseDouble(snapshotBookItem.getPrice());
int compare = 0;
if((order==1&&snapPrc > currentPrc)||(order==2&&snapPrc<currentPrc)) //增>全
compare = 1;
else if((order==1&&snapPrc < currentPrc)||(order==2&&snapPrc>currentPrc))//增<全
compare = -1;

//价格相等时候
if (compare == 0) {
if (!snapshotBookItem.equals(currentBookItem)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,19 @@ public boolean check() {
public SpotOrderBookDiff diff(SpotOrderBook that) {
System.out.println("全量数据:"+this.toString());
System.out.println("增量数据:"+that.toString());
//深度合并 添加参数 order: 1正向排序 2反向排序 20200507
//深度合并ask
final List<SpotOrderBookItem> askDiff = this.diff(this.getAsks(), that.getAsks(), Comparator.naturalOrder());
final List<SpotOrderBookItem> askDiff = this.diff(this.getAsks(), that.getAsks(), Comparator.naturalOrder(),1);
//深度合并bid
final List<SpotOrderBookItem> bidDiff = this.diff(this.getBids(), that.getBids(), Comparator.reverseOrder());
final List<SpotOrderBookItem> bidDiff = this.diff(this.getBids(), that.getBids(), Comparator.reverseOrder(),2);
//根据ask和bid创建合并后的对象
return new SpotOrderBookDiff(this.contract, askDiff, bidDiff, that.timestamp, that.checksum);
}

//深度合并,返回深度合并后的内容current为现有的数据,snapshot为快照增量的数据
//深度合并,返回深度合并后的内容current为现有的数据,snapshot为快照增量的数据 test20200507
private List<SpotOrderBookItem> diff(final List<SpotOrderBookItem> current, final List<SpotOrderBookItem> snapshot,
final Comparator<String> comparator) {
return differ.diff(current, snapshot, comparator);
final Comparator<String> comparator,int order) {
return differ.diff(current, snapshot, comparator,order);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ private Headers headers(final Request request, final String timestamp) {
builder.add(HttpHeadersEnum.OK_ACCESS_SIGN.header(), this.sign(request, timestamp));
builder.add(HttpHeadersEnum.OK_ACCESS_TIMESTAMP.header(), timestamp);
builder.add(HttpHeadersEnum.OK_ACCESS_PASSPHRASE.header(), this.credentials.getPassphrase());
/*模拟盘*/
/* builder.add("x-simulated-trading","1");*/
}
return builder.build();
}
Expand Down

0 comments on commit 70f9911

Please sign in to comment.