Find previous candles in Ethereum with Binance Net: Problem with DateTime.adddeconds
As an enthusiastic operator of the CRIPTO currency, it is probably not an alien to work with data foods from different exchanges. However, when it comes to finding previous candles in Ethereum using API binance.net wrapping, there is a common problem that can make your code unusable. In this article, we will deepen why datetime.adseconds
does not function as it is intended and we will provide a solution to overcome this restriction.
Problem: DateTime.adddeconds
When using the datetime.addseconds
, add seconds of the date/hour. This can be problematic in certain scenarios, especially in working with exchanged candles that store their prices at UTC (coordinated universal time).
In Ethereum, candles are generally stored as time ratings of UTC, which means that every adjustment of a brand over time through datetime.adseconds' will not result in the correct representation of the previous candle.
Solution: UseDateTime.fromticksO'DateTime.parteeexakact
To find the previous candle, you need to turn the time brand into a date and time object. However, since Binance Net uses ticks to return API (instead of seconds), you must use one of two approaches:
-
DateTime.fromticks
: This method allows you to analyze the time marks stored as a tick (INT64 values) and restore the datetime object.
`CSHARP
Var previous candle = waiting for binance.net api.client.candles.getprevius (commands, 0);
VAR Previous date = new datetime (previous condjle.dateutc.secondsimpeepoch / Timespan.ticsperscond);
`
- DateTime.parteeexact
: If you have Mark utc Time as a chain in 'Yyy-Mm-DdthH format: mm: SSZ, you can use this method for analysis in the facility to DateTimea.
`CSHARP
Var previous candle = waiting for binance.net api.client.candles.getprevius (commands, 0);
Sting previatimestamp = previous candle.Timestamp;
Date and time? Previous date = datetiime.parseexact (preceding-out, „aaaa-mm-ddthh: mm: SSZZ”, null);
`
UseDateTime.fromticks
To make the most of the previous solution, use the following fragment code as a starting point:
CSHARP
Orders var = alea binance.net api.client.order.getnderSync (Ordersymbol, Ordertype, Datetime.now, New Orderinfo {Side = Side.buy});
Var previous candle = waiting for binance.net api.client.candles.getprevius (commands, 0);
VAR Previous date = new datetime (previous condjle.dateutc.secondsimpeepoch / Timespan.ticsperscond);
// Use previous candle data
`
UseDateTime.prseexact
To analyze the time brand UTC as chains in a specific format (for example, "AAA YYY-MM-DDTHH: MM: SSZ"), you can use the following cod fragment:
CSHARP
Orders var = alea binance.net api.client.order.getnderSync (Ordersymbol, Ordertype, Datetime.now, New Orderinfo {Side = Side.buy});
String pretirimestamp = commands [0] .Candletime;
Date and time? Previous date = datetiime.parseexact (preceding-out, „aaa yyyy-mm-ddthh: mm: ssz”, null);
`
In conclusion, when working with Binance Net and finds previous candles in Ethereum,DateTime.addseconds’ is not a reliable method for deviating between ticks and seconds. By using datetime.fromticks
odatetime.parseexact
can overcome this restriction and recover the previous candle information.
Remember to guarantee the precise analysis and conversion of the brand while working with API that stores prices in UTC.