Finding previous candles at Ethereum with Binance Net: the problem with datetime.addseconds
As an avid cryptocurrency daughter, you are probably not strange about working with data feeds in various exchanges. However Datetime.Addseconds
The problem: datetime.addseconds
When you use the datetime.addseconds method, it adds seconds to the specified date/hour value. This
UTC, which means that it is not resigned in a correct representation of the previous candle.
The Solution: Usedatetime.fromticksor datetime.parsexact
. However, as Binance Net uses ticks for your API Returns (Instead of Seconds), you will need to use one of two Approaches:
-
datetime.fromticks
:
`Csharp
Var Antercandle = awaits binance.net-api.client.candles.getprevious (orders, 0);
Var anteriorDate = New Datetime (anteriorgandle.dateutc.secondssanceepoch / timespan.ticksprosecond);
2.
`Csharp
Var Antercandle = awaits binance.net-api.client.candles.getprevious (orders, 0);
String Antreyiotimestamp = AnteriorCandle.timtamp;
Datetime? Previousdate = datetime.parsexact (Previous Anteriortime, "Yyyy-MM-Dthh: Mm: SSZZ", null);
Using datetime.froticks
Code Snippet as a starting point:
`Csharp
Var orders = awaits binance.net-appi.client.order.tetorsaync (ordersymbol, lightype, datetime.now, new order {side = side = .buy});
Var Antercandle = awaits binance.net-api.client.candles.getprevious (orders, 0);
Var anteriorDate = New Datetime (anteriorgandle.dateutc.secondssanceepoch / timespan.ticksprosecond);
// Use the Previous Data of the Candle
Using datetime.parsexact
(AAAA-MM-DTRTHH: MM: SSZ “), you can use the following code snippet:
`Csharp
Var orders = awaits binance.net-appi.client.order.tetorsaync (ordersymbol, lightype, datetime.now, new order {side = side = .buy});
String Antreyiotimestamp = Orders [0] .Candletime;
Datetime? Previousdate = datetime.parsexact (anteriortime, "yyyy-mm-dthh: mm: ssz", null);
Ethereum, Datetime.Addseconds
is not a reliable method due to the disccrepancy between ticks and seconds. When using ‘datetime.fromticicks’ or datetime.parsexact`, you can overcome this limitation and accurately recover the previous data of the candle.
Remember to ensure that the store your prices at UTC.