marko001 Posted January 25, 2022 Share Posted January 25, 2022 Hi all, I have the following function that will gather data from Crypto.com and should return me top 10/worst 10 assets: expandcollapse popupFunc _TopBad() AdlibRegister("_wait2", 1000) Local $aAssetDataPositive[0][2] ; name - diff% Local $aAssetDataNegative[0][2] ; name - diff% If $iDefaultExchange = "Crypto.com" Then For $i = 0 To UBound($aPublicAssets) - 1 Local $sResult = CryptoQueryPublic("get-ticker", "instrument_name=" & $aPublicAssets[$i] & "_" & $iDefaultCurrency) ;Ticker $ask = _StringBetween($sResult, '"a":', ',') If IsArray($ask) Then $last = _StringBetween($sResult, '"a":', ',') $Change = _StringBetween($sResult, '"c":', '}') Local $delta = Round(((Number($last[0]) / (Number($last[0]) - Number($Change[0]))) - 1) * 100, 2) If StringInStr($delta, "-") = 0 Then ; positive _ArrayAdd($aAssetDataPositive, $aPublicAssets[$i] & "|" & Number($delta)) Else _ArrayAdd($aAssetDataNegative, $aPublicAssets[$i] & "|" & Number($delta)) EndIf Else _CW($aPublicAssets[$i] & ": " & $sResult) EndIf Next EndIf _ArraySort($aAssetDataPositive, 1, 1, 0, 1) _ArraySort($aAssetDataNegative, 1, 0, 0, 1) For $i = 0 To UBound($aAssetDataPositive) - 1 If $aAssetDataPositive[$i][1] >= 5 Then GUICtrlSetColor($I_TopPerformers[$i][1], $verde) ElseIf $aAssetDataPositive[$i][1] >= 0 Then GUICtrlSetColor($I_TopPerformers[$i][1], $verdechiaro) ElseIf $aAssetDataPositive[$i][1] < 0 Then GUICtrlSetColor($I_TopPerformers[$i][1], $rosso) EndIf GUICtrlSetData($I_TopPerformers[$i][0], $aAssetDataPositive[$i][0]) GUICtrlSetData($I_TopPerformers[$i][1], $aAssetDataPositive[$i][1] & "%") If $i = 9 Then ExitLoop Next For $i = 0 To UBound($aAssetDataNegative) - 1 If $aAssetDataNegative[$i][1] <= -5 Then GUICtrlSetColor($I_BadPerformers[$i][1], $rosso) ElseIf $aAssetDataNegative[$i][1] <= 0 Then GUICtrlSetColor($I_BadPerformers[$i][1], $giallo) ElseIf $aAssetDataNegative[$i][1] > 0 Then GUICtrlSetColor($I_BadPerformers[$i][1], $verde) EndIf GUICtrlSetData($I_BadPerformers[$i][0], $aAssetDataNegative[$i][0]) GUICtrlSetData($I_BadPerformers[$i][1], $aAssetDataNegative[$i][1] & "%") If $i = 9 Then ExitLoop Next _ArrayDisplay($aAssetDataPositive, "Positive") _ArrayDisplay($aAssetDataNegative, "Negative") AdlibUnRegister("_wait2") GUICtrlSetState($htoplabel, $GUI_HIDE) $showLabel2 = False GUISetState(@SW_SHOW, $FRM_TopPerformers) GUISetState(@SW_SHOW, $FRM_BadPerformers) EndFunc ;==>_TopBad it should just pick best 10 performers and worst 10 performers and display on a GUI but these are the results (just a subset of the _arraydisplay() where you can see numbers are not ordered) So when the GUI is created here are the results (same for worst assets) Arrays are sorted before cycling _ArraySort($aAssetDataPositive, 1, 1, 0, 1) _ArraySort($aAssetDataNegative, 1, 0, 0, 1) and I also added a _ArrayAdd($aAssetDataPositive, $aPublicAssets[$i] & "|" & Number($delta)) but it seems not working. Any suggestion? Maybe @Melba23?, I also tried your MultiCol array sort but didn't work Thanks, Marco Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2022 Moderators Share Posted January 25, 2022 marko001, Although you are using Number, you are also concatenating the various elements of the row using & - and so it all ends up as a string: _ArrayAdd($aAssetDataNegative, $aPublicAssets[$i] & "|" & Number($delta)) You will need to add a further line after adding to the array specifically setting that element to the number datatype: If StringInStr($delta, "-") = 0 Then ; positive $iRow = _ArrayAdd($aAssetDataPositive, $aPublicAssets[$i] & "|" & $delta) Else $iRow = _ArrayAdd($aAssetDataNegative, $aPublicAssets[$i] & "|" & $delta) EndIf ; Now set the element to Number datatype $aAssetDataPositive[$iRow][1] = Number($aAssetDataPositive[$iRow][1]) And my UDF uses the _ArraySort function and so, unsurprisingly, acts the same way. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
marko001 Posted January 25, 2022 Author Share Posted January 25, 2022 (edited) @Melba23 It seems better but first row is still wrong If StringInStr($delta, "-") = 0 Then ; positive $iRow = _ArrayAdd($aAssetDataPositive, $aPublicAssets[$i] & "|" & $delta) $aAssetDataPositive[$iRow][1] = Number($aAssetDataPositive[$iRow][1]) Else $iRow = _ArrayAdd($aAssetDataNegative, $aPublicAssets[$i] & "|" & $delta) $aAssetDataNegative[$iRow][1] = Number($aAssetDataNegative[$iRow][1]) EndIf Negative it's whis way: I used _ArraySort($aAssetDataPositive, 1, 1, 0, 1) _ArraySort($aAssetDataNegative, 1, 0, 0, 1) and here results: If I use 1 and not 0 it doesn't order at all but messes everything Edited January 25, 2022 by marko001 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2022 Moderators Share Posted January 25, 2022 marko001, This seems to work fine for me: #include <Array.au3> Global $aPublicAssets[] = ["1INCH", "KNC", "PLA", "FTM", "RNDR", "ATOM", "LRC", "GODS", _ "EGLD", "PAXG", "POWR", "BRZ", "DERC", "MIR", "SDN", "XYO", _ "BADGER", "PENDLE", "ANY", "PERP", "HOD","RADAR"] ; Save as strings Global $aDelta[] = ["2.7", "24.04", "18.45", "18.26", "17.68", "17.63", "15.06", "14.78", _ "12.83", "-0.14", "-0.48", "0.72", "-1.33", "-1.51", "-1.93", "-3.31", _ "-4.62", "-4.93", "-5.25", "-9.24", "-10.41","-20.29"] _ArrayShuffle($aDelta) ; Randomize the order Global $aAssetDataPositive[0][2], $aAssetDataNegative[0][2] For $i = 0 tO UBound($aPublicAssets) - 1 If StringInStr($aDelta[$i], "-") = 0 Then ; positive $iRow = _ArrayAdd($aAssetDataPositive, $aPublicAssets[$i] & "|" & $aDelta[$i]) $aAssetDataPositive[$iRow][1] = Number($aAssetDataPositive[$iRow][1]) Else $iRow = _ArrayAdd($aAssetDataNegative, $aPublicAssets[$i] & "|" & $aDelta[$i]) $aAssetDataNegative[$iRow][1] = Number($aAssetDataNegative[$iRow][1]) EndIf Next _ArrayDisplay($aAssetDataPositive, "Unsorted", Default, 8) _ArraySort($aAssetDataPositive, 1, 0, 0, 1) _ArrayDisplay($aAssetDataPositive, "Sorted", Default, 8) _ArrayDisplay($aAssetDataNegative, "Unsorted", Default, 8) _ArraySort($aAssetDataNegative, 1, 0, 0, 1) _ArrayDisplay($aAssetDataNegative, "Sorted", Default, 8) I have randomized the delta values because copying the lists from your post above meant that the arrays were already sorted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
marko001 Posted January 25, 2022 Author Share Posted January 25, 2022 (edited) well now it works. I had to remove all those number() here and there leaving just the last one. Thanks again, @Melba23 Edited January 25, 2022 by marko001 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 25, 2022 Moderators Share Posted January 25, 2022 marko001, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now