08 Feb Ethereum: Finding previous candle doesn’t work because of DateTime.AddSeconds
Finding previous candles in Ethereum with Binance Net: Problem with datetime.addseconds
As a passionate cryptoma trader, you probably don’t have a special job with data information channels in various exchanges. However, when it comes to finding previous candles in Ethereum using the API Binance.net cover, there is a common problem that can cause your code to be unusable. In this article, we will go deeper, why “datetsime.addsecond” does not work as planned and will provide a solution to overcome this restriction.
Problem: DATETIME.ADDSECONDS
If you use the datetsime.addseconds method, it adds seconds to the specified date/hour value. This can be problematic in certain scenarios, especially when working with the transfer of data that store their prices in UTC (coordinated universal time).
In Ethereum, candles are usually stored as a date and time records of UTC, which means that any adjustments in the date and time record via datetime.addseconds' do not know the correct representation of the previous candle.
Solution: Usedatetime.fromticksor datetime.parsexact
To find the previous candle, you must transfer the date and time record to the Datetime object. However, since Binance Net uses pliers for your API yields (instead of a second), you will need to use one of two approaches:
1.
`csharp
VAR ANTERCANDLE = waiting for binance.net-api.Client.candles.getPrevious (Orders, 0);
Var anteriordate = new datetime (anteriorcandle.dateutc.secondssancepoch / Timespan.ticksecond);
-
DATETIME.PARSEXACT
: If you have a UTC time stamp as YYYY-M-DDTHH: MM: SSZ
Format String, you can use this method to analyze it on the Datetime object.
csharp
VAR ANTERCANDLE = waiting for binance.net-api.Client.candles.getPrevious (Orders, 0);
String antreiotimestamp = anteriorcandle.imtamp;
DatetiMe? Previous datetime.parsexact (previous anteriortime, “RRRR-MM-DDTHH: MM: SSZZ”, null);
Use datetime.froticks
To make the most of the above solution as the starting point, use the following code fragment:
`csharp
boiling orders = expects binance.net-api.Client.order.orderaync (ordsymbol, lighttype, datetime.now, new order {side = side = .buy});
VAR ANTERCANDLE = waiting for binance.net-api.Client.candles.getPrevious (Orders, 0);
Var anteriordate = new datetime (anteriorcandle.dateutc.secondssancepoch / Timespan.ticksecond);
// Use previous candle data
Use DATETIME.PARSEXACT
To analyze the records of the date and time of UTC as chains in a particular format (for example, “AAAA-MM-DDTHH: MM: SSZ”), you can use the following code fragment:
`csharp
boiling orders = expects binance.net-api.Client.order.orderaync (ordsymbol, lighttype, datetime.now, new order {side = side = .buy});
String antreiotimestamp = ORDERS [0] .candletime;
DatetiMe? Previous datetime.parsexact (anteriortime, "YYYY-MM-DTTHH: MM: SSZ", null);
In conclusion, when working with Binance Net and finding previous candles in Ethereum, “Datetiime.addseconds” is not a reliable method due to the difference between ticks and seconds. When using “datetime.fromticicks” or datetime.parsexact` you can overcome this restriction and accurately restore previous candle data.
Be sure to ensure an accurate analysis and conversion of the date and time recording when working with the API that stores your UTC prices.
No Comments