#5 Get Coin History Scripting Part 3 - Integration
hi everyone so in this video we will be finishing our script so we are right here we wrote this code here we have created these arrays about a b c d e f and also we have modified values that we can have in the last element for a C and E ok we have a specific syntax here which will point to a certain value that we have in this array world coin ID last pair arrays doubling of what we have as input ok so if we get Bitcoin is going to be hundred and twenty if it is Bitcoin SV is going to be 231 okay we have to also notice that in our for loop we have a and B okay it's like a pair but we can use a and B if we have as input Bitcoin or - or this coin decreed but we cannot use if we have Bitcoin SV for example we should use another pair which is e and F okay so we need to find a way in order to switch in between pairs based on on input that we get okay so the first thing what I'm going to do is I'm going to create a container array which will have all the areas I'm gonna have a a b c d e and f okay then this is the syntax here for example container if you want to access this specific area can do container zeros you if you want being a container one zero if you want F can do container fights you then what I have here this is the coins ID last pair arrays okay let's say the code that you have okay let me just copy the entire code and put it okay and put it here okay so the code that you have here our coins ideal aster repairs that's what I represent you know from off table here okay I have the coin I have the length here and then what I'm going to do I'm going to basically define where I should have as pairs for each one of these coins okay so I'm gonna have a and B that pair if it is decree right I'm gonna have the same thing here same thing here but I'm gonna have Cindy if it's been on this coin or chain-link I'm gonna have PMF if it is Bitcoin cash or big Bitcoin ask me or cosmos this coin okay this is this is the condition now I'm going to replace the array a by the syntax I'm gonna have instead of having container sorry instead of having array a I'm gonna have this one okay continue is you zero I'm gonna do the same thing for everybody and same thing for C same thing for the same thing for F I'm gonna have continue of ice you good so I just replace with the proper syntax now where you can observe here is for if you try to access the teaser is from the container the last the second brackets it is all the time 0 0 0 0 0 0 but the first part is it is changing from 0 to 1 2 3 4 5 okay so so what I'm going to do instead of having 0 here I'm gonna have a variable which which you have that value okay so I'm gonna have here for example X that's a variable that I'm creating it will be equal to 0 okay so instead of having 0 at this level on the first one under in the first bracket I'm going to have X okay so that's e this this one is equal to a now because X is equal to zero and now I have here one so how I can change it because X is equal to zero I'm gonna do just X plus one okay I just know it is going to be one now so this this syntax when X is equal to zero we are accessing a and B right so I'm gonna apply the same thing for the rest of the coin that I have so these ones now so these ones okay but this time here X will be equal to two okay container to 0 it is C contain your 3 0 to +1 here is going to be D so same logic for the last the remaining coins that we have here and this time X it will be equal to 4 right so I'm gonna have X 0 0 or 2 or 4 depending on the group of the coin that I have here so depending on the coins that I have here I should change the value that I will have in the X variable so how I can do that one of the way to do that is having another array inside our coins ideal a story pairs so I can have a third one so that's going to be in this too and I'm going to have these values set up I'm gonna have here 0 then 0 here and then 0 here I'm gonna have here to turn and then 4 4 and then 4 ok so even know how you can access these values right so you can just you just need to use this coin IDE laughter a valuable ok this is an array so all you need to do is take this code let's say this variable I'm gonna replace it like this okay the first one is going to be 2 that's the image that we have right here and the second part for example what I have here here I'm gonna I'm going to have a cake okay remember that we have a for loop which is executing the entire code based on a condition and it goes from k equal to 0 to k 7 okay 0 1 2 3 4 5 6 7 and if I have - so I will have a certain syntax which is actually going to verify if I have a dashes going up or not and then k will have a certain value let's say in that if I have - K will be equal to 1 and then 2 K comes last point slightly last pairs - k it going to be 0 okay so if this if you take the value from here and we are sending it to the X variable X will be equal to 0 as well now automatically we have the right pair here okay I'm gonna have continue 0 0 continue 1 0 is actually a and P so in this way we can actually switch in between pairs okay so from so what we have done we have just did it in in our table everything we have changing it yeah put all these values now let's write it in terms of JavaScript code everything that we have done here so the first thing I'm going to create this container which will have all our arrays so which I have actually here so I'm gonna just copy and then put it in my cool okay so I'm gonna put it right here okay the container with all these arrays a b c d e and f the second thing i'm gonna add this the third array into my well coins ID last pair lost I repair okay so I'm gonna have it right here okay so that's the second thing the third thing is we are going to have the bar X variable it should be equal to but what we have written before okay so I'm gonna write here were an X equal two coins i d-- luster forest okay great so now we have to also change the code in the for loop level okay we have a and B and we want to actually change you we cannot have a we have to have the syntax that we have already created okay we have it for for that okay now we know how we can access every a or C or E okay so we're going to use that you know cool okay so instead of having a we're gonna have continue so let's first focus on on the first coin arrays length so what is that so if it is Bitcoin I'm gonna have to look for the land that I have in the coronaries okay so I mean now we have pairs so we don't need to look right here okay because depending on the coin that we get we don't have the same that okay we have in which is equal to the length is going to be one two three four five so this one is six this one is eight so we cannot use the land for that we have for the coin arrays which is fixed so we need to use a length which is actually going to change based on input okay so we need to have either the length of a either the length of C either the length of e so instead of having corner is length here I'm gonna have container okay brackets brackets the first one I'm gonna have here X the second one is going to be 0 and then dot let alright if you try to imagine the whole thing here you know I understand why I'm using this goal let's say they have Bitcoin as an input okay so if you have duquan as an input try to calculate what you should have on the X variable what is the value that I that I'm going to have 0 right that's what I mentioned here it's going to be coins X will be equal to coins last array 2 K K what is the value of K so if I go back into the table here K will be equal to 0 okay to 0 okay so in my phone I will be on the and the first bar a k equal to 0 and then I will have your 2 0 2 coins are you last press 2 0 is equal to 0 that's what I happen in here so X will be equal to 0 which means container 0 0 in containers use you it is the array a okay then X will be always 0 0 and the 2 out of 4 right so I'm gonna have a burnheal container 0 0 o 2 0 or 4 0 depending on the coin that I can if it is to 0 I'm looking at the array see where I'm going to get the length which is equal to 6 okay if it is cosmos but for example the last coin it is going to be in here okay so that's I hope now we understood why we are why we changed from corner is to this okay now let's [Music] for the second floor so what one here we want the value that we are having here in the bar a bar hey Eric okay we have two hundred and forty five and then it is going to change because we have a as valuable into the brackets so it's going to be two hundred and forty five again 245 and then 240 in case we have Bitcoin we can have a but if you have other coins where you have to have either C or E so the same logic here I'm going to just take the first part of the code she's actually going to allow me to switch in between array so it's going to be either a C or E then what I want I want the first value so I'm gonna have another bracket okay there and I have to put in here a variable and this time I'm going to be eight okay so a because we will have go through this these values okay for this C we will have n equal to zero equals one and then so on okay so this is how we're basically defining our arrays in our loop okay which are you should choose based on input and the last thing not the last thing but we have also something else to do here is the the code that we have in each theory we have I plus B okay we cannot have be all the time so what is the logic so if I have a I should happy if I have C I should have D if I have you I should have F right so so the difference so if I have a it is going to be container X let's say it's continue X 0 a so what I should have here is container X plus 1 and that's it the same code just I'm going to have instead of X I'm going to have X plus 1 which is actually going to access the other part of the pair okay so I'm going to just take this code oh and then paste it here so you can be able to be or either or either okay that's it sorry I haven't put your the plus one I'm going to have plus 1 and then plus one great so now we have to do one more thing we have our code which is like 99% done we have now one thing we need to be done is is how to collect those values we are collecting these values but we have to use it in our flow so in our flow as we have some inputs in our action steps or in the past step we have some inputs we're gonna have some outputs the output values where we are going to have this data so we have to create some outputs very poor so I'm gonna just copy paste the variable that I've already here outputs that canary and equal to coronary hey and then the same thing for all other arrays so I'm gonna just take just code here and then paste it right here this is highly important why I'm putting the code at this point not anywhere else okay so happy really matching a little bit okay then you have a for loop okay let's go back here in the table here you have the first thing equal to zero and then you start a for loop okay I'll call the zero is going along this numbers okay and at each iteration you're collecting some data okay we're accessing the history array in the response body and you're taking the data and you're putting into the coin object okay but at that specific moment as you're storing it into that specific cell right that's what we have right here the third line and this line of the code that go here make it bigger here okay this line okay you crazy object and then you put that and that's specific on that specific search for that specific rate okay so once you are done with the entire loop here before going for the second one we have all the data in your coin array a so so you are just transferring at the moment hey I have corner a now let's put it in the output variable now okay then go for the second so that's what we are doing right here logically so the first loop okay and then we have obviously gonna have coin I will filled with data this one and then we are putting it in the output variable okay but these are these are empties okay at that moment specifically then we are going to have bar equal to one we are going to the second loop and then this time it is going to fill the data into the coin arrays point a B okay and we will put the data when we will have the data right here and then put it in output variable okay what is the difference it is calling every race this is coins array a it's totally different variable so you have to be clear on that so coin is a these are output variables that we are going to use in our steps okay that we can use later on in the data source that's why we need to do that here okay so it's going to do for all coins we're gonna get for anti-age if it is Bitcoin but if it isn't let's let's say this chain link or cosmos we don't need as many areas so it's going to stop at a certain moment it's going to either stop at E sorry F or you or something like this depending on how many number we need so one two three that this is FRA so it's going to be one two three four five it's gonna stop for example for cosmos at E so the last IV it will put the values it's going to be coin at E and these these arrays will be empty so that's not going to cause any problem for us it's going to be simply it's going to be like we don't have not have any D data that's it okay okay now as we are done with the scripting part so what we are going to do next is we're going to create our rest request and also put our code and then see if we get the result that's it thank you for watching see you in the next video
https://www.youtube.com/watch?v=KqLFbvkP1og