Results 1 to 23 of 23

Thread: how to extract first values from array in vb.net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    how to extract first values from array in vb.net

    Hi,

    I want to extract the first value of an array using Binance API and I'm interested on extract just the first value of it, which reppresent the price of BTC 1 h ago. Since Binance API doesn't provide any 1h price change, I found the only article online which is really interesting cause this particular API allow me to get the 60 candles prices. Knowing the actual price, I just need now to extract the first value wich now at 2.11PM is
    [[1615600800000,"47224.48000000"
    I think that "1615600800000" it s the timestamp, while I need to grab 477224,48 from it. I've been googling lots of forums about arrays but all the examples are referring to a list of numbers. In my case, how should I remove that first timestamp to grab just the 1h ago price? Thanks ,
    Mattia

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    Seeing the whole JSON response would be helpful, but I assume that it looks something like this:
    Code:
    [[1615600800000,"47224.48000000"], [...,"..."], [...,"..."]]
    If that's the case, then you could use Netwonsoft's JArray.Parse method:

    Example:https://www.newtonsoft.com/json/help...rray_Parse.htm
    Code:
    Dim parsedArray = JArray.Parse(payload)
    Dim firstItem = parsedArray(0)
    Dim firstItemPrice = firstItem(1)
    Console.WriteLine(firstItemPrice)
    Fiddle: https://dotnetfiddle.net/olcm34
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: how to extract first values from array in vb.net

    That's not an array. At least, it's not a .NET array. That looks like JSON data so you should be researching how to parse JSON in VB.NET.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Hi thanks everybody for answering.
    I'm already parsing json data from another Binance API like this one
    with:

    Code:
    Imports System.Net
    Imports Newtonsoft.Json
    Imports System.Collections.Generic
    
    Public Class Form1
        Private wc As New WebClient()
     Private Async Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            Timer1.Stop()
    
            Dim downloadTasks As New List(Of Task(Of String))
    
            Dim btc = wc.DownloadStringTaskAsync("https://api.binance.com/api/v1/ticker/24hr?symbol=BTCEUR")
    
            downloadTasks.Add(btc)
            Await Task.WhenAll(downloadTasks)
    
            Dim d = JsonConvert.DeserializeObject(Of Dictionary(Of String, String))(btc.Result)
            Label1.Text = ("PRICE € " + Val(d("lastPrice")).ToString("n2"))
            Timer1.Start()
        End Sub
    and this it's quite easy to me cause I can "use" the key "lastPrice".
    Instead, In the API posted in the first post, I don't have those "keys" so it's quite difficult to me to grab the data.
    Thanks

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    @dday9, the whole Json response is:

    Code:
    [[1615811640000,"55999.99000000","56160.39000000","55971.06000000","56126.63000000","127.35561000",1615811699999,"7140917.54920933",2718,"85.79497500","4810152.66605409","0"],[1615811700000,"56125.01000000","56139.20000000","55840.00000000","56078.48000000","150.00658800",1615811759999,"8406160.13787214",2584,"55.71370500","3123956.92982448","0"],[1615811760000,"56078.48000000","56204.93000000","56073.70000000","56204.92000000","87.36407600",1615811819999,"4905684.87450682",1913,"50.81277300","2853096.10691667","0"],[1615811820000,"56204.93000000","56249.00000000","56141.32000000","56177.15000000","67.53896300",1615811879999,"3794632.85038739",1918,"32.03805500","1800048.83328390","0"],[1615811880000,"56177.14000000","56200.00000000","56124.57000000","56124.58000000","105.88004900",1615811939999,"5947108.95503962",1525,"59.66898200","3351395.87685397","0"],[1615811940000,"56122.36000000","56165.83000000","56047.00000000","56160.05000000","66.81468600",1615811999999,"3748637.50379320",1600,"36.34033100","2038985.60660055","0"],[1615812000000,"56160.06000000","56249.00000000","56150.01000000","56193.06000000","59.58360300",1615812059999,"3348588.75715546",1343,"27.78929800","1561807.47942541","0"],[1615812060000,"56193.72000000","56205.49000000","56141.64000000","56166.77000000","42.94701500",1615812119999,"2412613.74868940",1275,"18.07985600","1015749.66665980","0"],[1615812120000,"56165.35000000","56236.08000000","56096.00000000","56131.17000000","65.78767900",1615812179999,"3694990.97568351",1780,"22.33253500","1254267.43979186","0"],[1615812180000,"56131.17000000","56142.07000000","56066.98000000","56140.76000000","96.66199000",1615812239999,"5422428.31653116",1797,"56.46651100","3167513.30338681","0"],[1615812240000,"56140.75000000","56162.21000000","56115.50000000","56162.20000000","34.49429100",1615812299999,"1936490.73930014",1236,"21.26461000","1193783.24400321","0"],[1615812300000,"56162.20000000","56171.72000000","56050.75000000","56100.00000000","59.69603700",1615812359999,"3348879.78664654",1745,"24.65082700","1382917.97680833","0"],[1615812360000,"56100.00000000","56100.01000000","56036.15000000","56046.82000000","48.72668900",1615812419999,"2732108.45339469",1272,"15.80265900","886010.90343018","0"],[1615812420000,"56047.53000000","56150.00000000","56043.18000000","56125.65000000","39.50862100",1615812479999,"2216311.92103893",1417,"18.79307400","1054359.63028116","0"],[1615812480000,"56125.65000000","56240.00000000","56125.64000000","56220.42000000","57.57245200",1615812539999,"3235191.04962033",1398,"41.11716300","2310548.53261548","0"],[1615812540000,"56220.42000000","56319.94000000","56220.41000000","56281.70000000","107.99542100",1615812599999,"6078167.63072032",2247,"68.87305100","3876374.47048274","0"],[1615812600000,"56279.98000000","56310.00000000","56212.32000000","56297.40000000","54.66843500",1615812659999,"3076389.47946328",1558,"35.57332700","2002015.93176857","0"],[1615812660000,"56300.71000000","56419.00000000","56300.71000000","56379.36000000","75.30551400",1615812719999,"4245088.81901867",2166,"44.13655400","2488035.83190109","0"],[1615812720000,"56379.37000000","56382.55000000","56285.09000000","56308.69000000","71.25400000",1615812779999,"4013238.93736895",1924,"30.13278700","1697076.69073774","0"],[1615812780000,"56308.70000000","56334.24000000","56224.79000000","56323.27000000","58.32181700",1615812839999,"3282273.40381432",1485,"24.29807900","1367524.09534994","0"],[1615812840000,"56323.27000000","56350.73000000","56264.23000000","56290.19000000","45.16475100",1615812899999,"2543344.10342098",1414,"21.19432400","1193541.91031787","0"],[1615812900000,"56290.19000000","56323.27000000","56183.83000000","56213.87000000","74.51705200",1615812959999,"4190629.98816418",1925,"34.07533700","1916290.61839201","0"],[1615812960000,"56218.50000000","56300.00000000","56205.44000000","56290.68000000","33.86284500",1615813019999,"1904831.53504746",1151,"14.39532300","809833.08106656","0"],[1615813020000,"56295.90000000","56481.38000000","56290.66000000","56393.78000000","156.78646200",1615813079999,"8844549.11621510",2650,"79.71123100","4495368.18015073","0"],[1615813080000,"56393.78000000","56394.87000000","56256.21000000","56325.16000000","51.30385800",1615813139999,"2889640.04462432",1532,"21.80754200","1228344.13486594","0"],[1615813140000,"56325.17000000","56450.00000000","56306.61000000","56439.53000000","55.86187200",1615813199999,"3148861.78433423",1432,"40.48042700","2281902.43963218","0"],[1615813200000,"56439.54000000","56450.00000000","56350.32000000","56421.07000000","88.80807600",1615813259999,"5009847.82737117",2031,"53.09578600","2994842.13203495","0"],[1615813260000,"56423.12000000","56449.54000000","56388.35000000","56400.00000000","37.66269700",1615813319999,"2124851.55767540",1244,"20.75754900","1171136.40056453","0"],[1615813320000,"56400.00000000","56400.01000000","56280.55000000","56303.58000000","76.68071900",1615813379999,"4319200.39399184",1888,"27.61974700","1555651.04170781","0"],[1615813380000,"56303.59000000","56339.99000000","56250.48000000","56330.45000000","59.95223100",1615813439999,"3375234.27827228",1185,"32.02088300","1802843.18656433","0"],[1615813440000,"56330.44000000","56419.99000000","56330.44000000","56403.04000000","49.74886300",1615813499999,"2804949.36903991",1256,"29.86877600","1683982.80781964","0"],[1615813500000,"56403.04000000","56403.94000000","56290.00000000","56319.97000000","53.71679100",1615813559999,"3025672.89016831",1330,"24.24130600","1365270.40791895","0"],[1615813560000,"56314.26000000","56410.00000000","56261.56000000","56367.58000000","51.50167500",1615813619999,"2900978.75114510",1421,"20.06698800","1130338.67474570","0"],[1615813620000,"56367.58000000","56500.00000000","56361.66000000","56500.00000000","72.02942300",1615813679999,"4065409.57862531",1663,"43.02047600","2428151.01304134","0"],[1615813680000,"56499.99000000","56670.62000000","56495.31000000","56635.22000000","217.37860100",1615813739999,"12297902.03294681",5312,"145.12143900","8208707.58135503","0"],[1615813740000,"56635.22000000","56685.81000000","56616.85000000","56643.36000000","118.33384500",1615813799999,"6704227.16234423",2713,"58.72603300","3327176.01432611","0"],[1615813800000,"56643.36000000","56655.01000000","56507.36000000","56524.82000000","95.84094300",1615813859999,"5422408.33163122",2403,"39.39604800","2229084.47072520","0"],[1615813860000,"56523.43000000","56606.33000000","56502.02000000","56519.98000000","81.59527700",1615813919999,"4613649.74753294",1817,"27.05651200","1530136.97977036","0"],[1615813920000,"56514.81000000","56536.63000000","56464.31000000","56501.65000000","50.77911700",1615813979999,"2869005.66601790",1634,"19.93429700","1126285.65120341","0"],[1615813980000,"56501.64000000","56522.66000000","56426.36000000","56489.09000000","99.87941100",1615814039999,"5640814.62618117",1739,"48.42433300","2734715.82102101","0"],[1615814040000,"56489.10000000","56533.42000000","56446.26000000","56523.22000000","48.43485800",1615814099999,"2735898.96075687",1406,"24.01129000","1356309.81033498","0"],[1615814100000,"56523.22000000","56531.07000000","56465.70000000","56473.57000000","34.96653300",1615814159999,"1975339.33077136",1316,"14.75414400","833505.85660627","0"],[1615814160000,"56473.56000000","56480.82000000","56388.00000000","56474.37000000","53.92574000",1615814219999,"3043029.62500634",1587,"24.35916100","1374592.36551997","0"],[1615814220000,"56474.37000000","56582.04000000","56474.37000000","56562.71000000","59.05477600",1615814279999,"3338933.47015474",1523,"38.45677000","2174573.77585356","0"],[1615814280000,"56562.71000000","56630.98000000","56559.94000000","56624.48000000","39.77854400",1615814339999,"2251660.59787337",1283,"23.62427700","1337277.45677313","0"],[1615814340000,"56624.49000000","56774.42000000","56600.00000000","56711.75000000","210.26412600",1615814399999,"11921787.51946524",3229,"79.23101300","4492846.32745928","0"],[1615814400000,"56697.11000000","56866.05000000","56670.00000000","56721.40000000","182.49413000",1615814459999,"10355834.81096302",3840,"100.05375100","5678346.90837010","0"],[1615814460000,"56721.41000000","56797.24000000","56688.00000000","56688.00000000","98.20802100",1615814519999,"5570928.95008297",2089,"52.80137100","2995600.97170552","0"],[1615814520000,"56688.00000000","56831.70000000","56628.48000000","56818.80000000","105.33640300",1615814579999,"5974179.19172481",2198,"57.26434900","3248301.56966553","0"],[1615814580000,"56831.05000000","56851.04000000","56695.24000000","56820.93000000","125.90201600",1615814639999,"7149790.49153555",2791,"53.22834200","3022684.73011776","0"],[1615814640000,"56820.93000000","56822.46000000","56750.00000000","56807.77000000","99.37920600",1615814699999,"5643491.06929039",2495,"45.59928800","2589563.04286218","0"],[1615814700000,"56807.76000000","56883.00000000","56767.00000000","56820.33000000","132.33855500",1615814759999,"7519741.52057110",2885,"68.83620200","3911672.79030523","0"],[1615814760000,"56820.34000000","56869.09000000","56796.85000000","56850.09000000","74.36711600",1615814819999,"4226258.29426735",1924,"43.75198600","2486429.25982553","0"],[1615814820000,"56850.09000000","56979.40000000","56850.09000000","56961.52000000","130.53363100",1615814879999,"7428387.50289251",3439,"71.92947900","4093597.03008567","0"],[1615814880000,"56961.53000000","57000.00000000","56910.37000000","56956.40000000","135.00830000",1615814939999,"7689214.46255961",3286,"67.50734100","3845353.25242036","0"],[1615814940000,"56956.28000000","57039.00000000","56933.34000000","57014.58000000","85.55599000",1615814999999,"4875647.46355596",3015,"56.84367200","3239607.36607090","0"],[1615815000000,"57014.58000000","57021.54000000","56863.45000000","56989.85000000","101.93563000",1615815059999,"5804630.62433798",2802,"38.85257200","2212389.50906188","0"],[1615815060000,"56989.86000000","57046.87000000","56986.36000000","57015.37000000","131.51955500",1615815119999,"7499501.86034612",2488,"52.99310700","3021499.33853199","0"],[1615815120000,"57015.38000000","57015.38000000","56837.01000000","56909.35000000","102.13239600",1615815179999,"5814750.87492981",3024,"37.40317600","2129279.78073917","0"],[1615815180000,"56911.90000000","57009.99000000","56887.00000000","56933.89000000","112.45288700",1615815239999,"6402652.27042090",2486,"46.49169000","2646743.40435399","0"]]
    and as I stated before I just need to grab the first value, in this case( in this exactly moment ) is 55999.99000000.
    I'll try your code.
    Thanks

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    I'm trying my best to achieve this!
    So, first of all I need to grab the Json and deserialize this. I'm trying with:

    Code:
       Private wc1 As New WebClient
        Private Async Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    
            Timer1.Stop()
    
            Dim downloadTasks As New List(Of Task(Of String))
     Dim Jsonsource = wc1.DownloadStringTaskAsync("https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&limit=60")
     downloadTasks.Add(Jsonsource)
            Await Task.WhenAll(downloadTasks)
    
             Dim J = JsonConvert.DeserializeObject(Of String)(Jsonsource.Result)
            Dim json As String = J
            Dim jsonObject As Newtonsoft.Json.Linq.JObject = Newtonsoft.Json.Linq.JObject.Parse(json)
            Dim firstItem = jsonObject(0)
            Dim firstItemPrice = firstItem(1)
            Label16.Text = firstItemPrice
    This doesn't reproduce an output and it return an error
    Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: [. Path '', line 1, position 1.'
    on
    Dim J = JsonConvert.DeserializeObject(Of String)(Jsonsource.Result)
    Can you please tell me where I'm doing wrong? I really appreciate your help and I feel I'm almost there.
    Thanks,
    Mattia

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    Here is the documentation on the particular endpoint that you are hitting: https://binance-docs.github.io/apido...ndlestick-data

    Why in the world the developers opted to stuff all of the information in an array instead of an object is beyond me.

    The reason why your code is failing is because, well, you didn't follow the instructions in my original post. You are trying to use DeserializeObject when I explicitly told you to use JArray.Parse.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    You are endeed right!
    I solved with
    Code:
     Private wc9 As New WebClient
        Private Async Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
            Dim downloadTasks As New List(Of Task(Of String))
            Dim payload = wc9.DownloadStringTaskAsync("https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&limit=60")
            downloadTasks.Add(payload)
    
            Dim parsedArray = JArray.Parse((Await payload))
            Dim firstItem = parsedArray(0)
            Dim firstItemPrice = firstItem(1)
            Console.WriteLine(firstItemPrice)
            Await Task.WhenAll(downloadTasks)
        End Sub
    Would you please suggest me any change ?

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    I would suggest moving the WebClient declaration to the scope of your button click and to also declare it using the Using statement:
    Code:
    Using wc9 = New WebClient()
        ' ...
    End Using
    Another suggestion I would make is to create a class representation of the data so that you can use a strongly typed object instead of relying on indices, e.g.:
    Code:
    Public Class KlineCandlestick
    
        Public Property OpenTime As ULong
        Public Property OpenValue As Decimal
        Public Property HighValue As Decimal
        ' etc..
    
        Sub New(incoming As JArray)
            OpenTime = incoming(0)
            OpenValue = incoming(1)
            HighValue = incoming(2)
            ' etc...
        End Sub
    
    End Class
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Thanks a lot for your suggestions!
    just the last thing.
    How comes that
    Code:
     Label16.Text = Val(firstItemPrice).ToString("n2")
    doesn't work?
    it gives at ouput Attachment 180580 while I just need 2 decimals after comma... thanks

  11. #11
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    Do not rely on Val, it is a legacy Visual Basic holdover and can give unexpected results.

    I believe the data type is already a Double, you should be able to call ToString and pass your format on it without any casting:
    Code:
    Label16.Text = firstItemPrice.ToString("n2")
    FYI, I'd change n2 to C considering it is currency you're wanting to format.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    hmm I already tried it but I didnt posted it. Unfortunately is showing an error of System.InvalidCastException. Using Val instead is running but showing that zeros after the real price... :\

  13. #13
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    My apologies, the actual type is a JValue.

    You can still cast it, just don't use Val:
    Code:
    Convert.ToDecimal(firstItemPrice).ToString("C")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Wow that's impressive. It's working!
    just don't understand how I can decide how many decimals after comma and for what magical thing he s also dissplaying the symbol of currency when the api is not showing any symbol. Thanks!

    edit: I might not use C as the API im using is btc to usdt and it's displaying € instead

  15. #15
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    You can set the localility of the format, just add this before your ToString:
    Code:
    Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US", false)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: how to extract first values from array in vb.net

    Val is a very old BASIC function and is hard coded to work on a string that uses "." for the decimal point, so it won't work on strings that use "," for a decimal point. It will just convert the digits up to the "," and stop, so it will always return the Integer portion and ignore the rest of the string once it hits the ",".
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Thanks I didn't know about that!
    Probably, one problem I didn't think about was how to operate and calculate the price difference between first item price and the last item price. I thought that I could make operations between labels using cint, but I need to re organize the things!

    So, I think to get also the last item value, which should be item#60 and as arrays are zero base, it should be #59, right?
    but when I'm doing :
    Code:
    Dim downloadTasks As New List(Of Task(Of String))
            Dim payload = wc.DownloadStringTaskAsync("https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&limit=60")
            downloadTasks.Add(payload)
            Await Task.WhenAll(downloadTasks)
            Dim parsedArray = JArray.Parse((Await payload))
            Dim lastItem = parsedArray(59)
            Dim lastItemPrice = lastItem(60)
            Console.WriteLine(lastItemPrice)
    I get an Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll

    Am I doing something wrong? I'm sure the items are 60 as the API shows 60 values for 60m chart.
    I'm trying then to do FirstItemPrice - LastItemPrice = 1 h price change

    Hope I explained well my problem

    Thanks,
    Mattia

  18. #18
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    Since your parsedArray variable is a JArray object, really you don't need to get the items by their index at all. Instead you can get the First and Last properties:


    Example:
    Code:
    Dim parsedArray = JArray.Parse((Await payload))
    Dim firstItem = parsedArray.First()
    Dim firstItemPrice = firstItem(1)
    Dim lastItem = parsedArray.Last()
    Dim lastItemPrice = lastItem(1)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Thanks for your answer!
    So, I ve just tried it and It's extracting the first key of the last array

    In this moment, the last array is:

    Code:
    [1615835460000,"56277.69000000","56282.12000000","56274.84000000","56278.00000000","3.79778400",1615835519999,"213741.14136772",381,"0.97681700","54974.29244996","0"]]
    so 54974.29244996 should be the last price. 56277.69000000 is instead picked from it, which it doesn't represent the last price ..
    Any idea? :\

    thanks

    edit1:

    in this moment, the last array is:
    Code:
    [1615835760000,"56251.25000000","56259.84000000","56247.42000000","56259.41000000","6.97781200",1615835819999,"392553.06732524",438,"3.48838800","196246.28185818","0"]]
    and with your code 56251.25 is picked. How is that even possible that few minutes ago, the last number of the array was the last price and now the last numbers of this array are useless numbers? Prices seems changing positions.
    Last edited by matty95srk; Mar 15th, 2021 at 02:18 PM.

  20. #20
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    I don't think 54974.29244996 is the last price. According to the documentation (linked in post 7), 54974.29244996 represents "Taker buy quote asset volume" value and 56277.69000000 represents the "Open" value.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    Well, you are right, obviously a price can't stay the same for 1 minute. What do you think it's the best reasonable idea then do what I'm trying to do? Cause during dips price could change a lot between open and close candle. Many thanks, Mattia

    edit: I think it's best to use close price, what do you think?

    edit2: in my previous post, the second array I posted, "196246.28185818" should be the taker buy base asset volume, but that it's not even possible. that's 3x btc price. Either there is something I still didnt' understand or the values are changing positions.

    edit3: Well, I have to re organize things better. The last value I'm trying to grab it's the actual traded price, which I'm extracting from another api with the code I posted in post #4. The problem is to calculate
    Code:
     Label1.Text = ("PRICE € " + (d("lastPrice")).ToString("n2"))
    minus
    Code:
    label16.text= Convert.ToDecimal(firstItemPrice).ToString("C")
    Do you think it's possible to make this calculation? This would be our solution.
    Still many thanks
    Last edited by matty95srk; Mar 15th, 2021 at 03:20 PM.

  22. #22
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: how to extract first values from array in vb.net

    You are sort of limited to the API that you're using. It doesn't look like they provide a simple to use endpoint to query klines.

    The ideal thing to do would be to query based on the timestamp, have an object returned, parse the object, and then average the prices. The issue is that binance doesn't let you do that (apparently).

    I think the only way that you can work with this data is like what I showed you and just hope that the indices you're using are accurately representing the properties.

    For what its worth, I plan on writing to binance and requesting that they setup an endpoint to return an array of JSON objects instead of an array of JSON arrays.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Jul 2013
    Posts
    108

    Re: how to extract first values from array in vb.net

    That would make a lot more sense! Anyway, with my inexperience as a developer, would my idea be possible? Subtracting 1h ago price
    Code:
    label16.text= Convert.ToDecimal(firstItemPrice).ToString("C")
    from actual price
    Code:
    Label1.Text = ("PRICE € " + (d("lastPrice")).ToString("n2"))
    ? Eventhough i know that doesnt seems the right way to do, would it be even possible to calculate it via code? I d like to make this workaround as we know for sure the 1h ago price and we can get the actual price( via the 2nd api) as well. This is a percy tool and to me in this case it would be good to make it work by any way.

    edit: I simply solving with:

    Code:
    Console.WriteLine(CInt(actualPrice.Text - CInt(1hagoPrice.Text)))
    it's doing its dirty job atleast... Thanks
    Last edited by matty95srk; Mar 15th, 2021 at 04:52 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width