You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.7 KiB
46 lines
1.7 KiB
package com.sigmaflare.binancej.entities.transform; |
|
|
|
import com.fasterxml.jackson.core.JsonParser; |
|
import com.fasterxml.jackson.databind.DeserializationContext; |
|
import com.fasterxml.jackson.databind.JsonNode; |
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
|
import com.sigmaflare.binancej.entities.Candlestick; |
|
|
|
import java.io.IOException; |
|
import java.math.BigDecimal; |
|
|
|
/** |
|
* A custom deserializer for OrderBookDepth. Binance returns some non-standard looking data |
|
* in it's array, so we convert the entire thing into our own representation here to make |
|
* it easier to use. |
|
*/ |
|
public class CandlestickDeserializer extends StdDeserializer<Candlestick> { |
|
|
|
public CandlestickDeserializer() { |
|
this(null); |
|
} |
|
|
|
public CandlestickDeserializer(Class<?> vc) { |
|
super(vc); |
|
} |
|
|
|
@Override |
|
public Candlestick deserialize(JsonParser jp, DeserializationContext context) throws IOException { |
|
JsonNode n = jp.getCodec().readTree(jp); |
|
|
|
return Candlestick |
|
.builder() |
|
.openTime(n.get(0).asLong()) |
|
.open(new BigDecimal(n.get(1).asText())) |
|
.high(new BigDecimal(n.get(2).asText())) |
|
.low(new BigDecimal(n.get(3).asText())) |
|
.close(new BigDecimal(n.get(4).asText())) |
|
.volume(new BigDecimal(n.get(5).asText())) |
|
.closeTime(n.get(6).asLong()) |
|
.quoteAssetVolume(new BigDecimal(n.get(7).asText())) |
|
.numberOfTrades(n.get(8).asLong()) |
|
.takerBuyBaseAssetVolume(new BigDecimal(n.get(9).asText())) |
|
.takerBuyQuoteAssetVolume(new BigDecimal(n.get(10).asText())) |
|
.build(); |
|
} |
|
}
|
|
|