It is currently April 27th, 2024, 10:41 am

How to use api for unmineable pool?

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 12th, 2024, 7:51 pmBut when I enter this command in the browser; "https://www.nicehash.com/main/api/v2/accounting/account2/BTC" I get a 404 not found error. If I can pass this stage, I will handle the rest. I couldn't pass it. I will tinker with it again when I have free time. Thank you again and again.
I think you'll need to try https://api2.nicehash.com/main/api/v2/accounting/account2/BTC instead (naturally, with your own account / key and such).

How do I know, without an account or a key? Simple: I went to the public REST API methods below on that page, enabled Developer Tools in Chrome and switched to the Network Tab, then clicked on "Try It Out" and "GET" buttons on the NiceHash page to trigger a request. This produced an XHR (i.e. XMLHttpRequest in Javascript) named "algorithms" in the Developer Tools' Network Tab (since I tried https://api2.nicehash.com/main/api/v2/mining/algorithms from the public methods). Hovering the mouse over that name revealed the address that the site used for the API request. Obviously, the root part of the site should be the same for both public and private methods, hence the above conclusion.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

Yincognito wrote: March 12th, 2024, 10:10 pm I think you'll need to try https://api2.nicehash.com/main/api/v2/accounting/account2/BTC instead (naturally, with your own account / key and such).

How do I know, without an account or a key? Simple: I went to the public REST API methods below on that page, enabled Developer Tools in Chrome and switched to the Network Tab, then clicked on "Try It Out" and "GET" buttons on the NiceHash page to trigger a request. This produced an XHR (i.e. XMLHttpRequest in Javascript) named "algorithms" in the Developer Tools' Network Tab (since I tried https://api2.nicehash.com/main/api/v2/mining/algorithms from the public methods). Hovering the mouse over that name revealed the address that the site used for the API request. Obviously, the root part of the site should be the same for both public and private methods, hence the above conclusion.
I managed to get it working after long efforts. I managed to get "balance" in the cmd prompt using "phyton".
As you said, it happened with the "user api key". However, the only problem is that I cannot reflect it on the "rainmeter" screen. Let me give the example code;
"python nicehash.py -b https://api2.nicehash.com -o KEY1 -k KEY2 -s KEY3 -m GET -p /main/api/v2/accounting/account2/BTC"
.. When I write my user API information in the KEY sections, the following screen appears. quite successful. I congratulate myself :)
Image

rainmeter command;

Code: Select all

---TEST APi---
[TEST]
Measure=WebParser
URL=python nicehash.py -b https://api2.nicehash.com -o KEY1 -k KEY2 -s KEY3 -m GET -p /main/api/v2/accounting/account2/BTC
RegExp=(?siU)"totalBalance":(.*)[,}]
UpdateRate=600
---TEST APi---
---------------------------------------APi---

---------------------------------------APi CONNECT---
---TEST APi CONNECT---
[TESTApi]
Measure=WebParser
URL=[TEST]
StringIndex=1
RegExpSubstitute=1
Substitute="(?:^\s+|\s+$)":"",'(?:^"|"$)':""
---------------------------------------APi CONNECT---

---TEST TEXT---
[TESTApiText]
Meter=String
X=20
Y=38
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=TESTApi
Text=NiCEHASH  : %1 $
DynamicVariables=1
---TEST TEXT---
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 12th, 2024, 11:37 pm I managed to get it working after long efforts. I managed to get "balance" in the cmd prompt using "phyton".
As you said, it happened with the "user api key". However, the only problem is that I cannot reflect it on the "rainmeter" screen. Let me give the example code;
"python nicehash.py -b https://api2.nicehash.com -o KEY1 -k KEY2 -s KEY3 -m GET -p /main/api/v2/accounting/account2/BTC"
.. When I write my user API information in the KEY sections, the following screen appears. quite successful. I congratulate myself :)
Image

rainmeter command;

Code: Select all

---TEST APi---
[TEST]
Measure=WebParser
URL=python nicehash.py -b https://api2.nicehash.com -o KEY1 -k KEY2 -s KEY3 -m GET -p /main/api/v2/accounting/account2/BTC
RegExp=(?siU)"totalBalance":(.*)[,}]
UpdateRate=600
---TEST APi---
---------------------------------------APi---

---------------------------------------APi CONNECT---
---TEST APi CONNECT---
[TESTApi]
Measure=WebParser
URL=[TEST]
StringIndex=1
RegExpSubstitute=1
Substitute="(?:^\s+|\s+$)":"",'(?:^"|"$)':""
---------------------------------------APi CONNECT---

---TEST TEXT---
[TESTApiText]
Meter=String
X=20
Y=38
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=TESTApi
Text=NiCEHASH  : %1 $
DynamicVariables=1
---TEST TEXT---
I don't know why you needed long efforts to make it work, since the address style I mentioned above should have worked directly in the WebParser's URL, once you adapted it for your case (which only you know and can test).

Anyway, if you insist in using python for this, you will have to replace your WebParser measures with a RunCommand one, which is specifically designed to run external programs (with or without parameters) and yield the STDOUT result (i.e. what you get in the cmd window) back to the skin, once the program terminates successfully (see the example and the explanation at the bottom of the page to get the idea, and also make sure you check and use the FinishAction properly, if needed):
https://docs.rainmeter.net/manual/plugins/runcommand/

The difference compared to WebParser is that, unless you use the optional OutputFile of the RunCommand measure as a local URL in a subsequent WebParser measure (just like you'd do for an online source, but via commanding the WebParser to update from the FinishAction of the RunCommand measure), the RunCommand measure would need some regex Substitute to capture and "extract" the value(s) you're after (or remove the unneeded parts if the desired pattern has not been found), e.g.:

Code: Select all

RegExpSubstitute=1
Substitute='(?siU)^(?:.*"totalBalance":(.*)[,}].*|.*)$':"\1","^\\\d+$":""
So, basically, it's somewhat similar to the WebParser approach, but in a suited measure for your current method.

P.S. Feel free to swap the " and the ' in the part before the :"\1" if the output uses ' as field name delimiters, and add the substitution parts that remove spaces and quotes from the value, like mentioned earlier. For the record, the RunCommand approach will be slightly slower than the WebParser one, since it involves running external programs, so I'm not sure how suited it would be for near real-time monitoring of those values. Commanding the RunCommand to run should be done at a reasonable frequency.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

nicehash python link : https://github.com/nicehash/rest-clients-demo
test api key code : python nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC

For now I can't run this outside of Python. I tried as you mentioned in your last message, but I got a 404 not found error. Let me share my test keys with you. The balance is currently zero so you may not see any profit. What matters is the work. I will be very pleased to be able to get the balance output, albeit slowly. I will test the information you provided in the last message to run Python. I think I can.

edited;

Code: Select all

[Rainmeter]
Update=1
DynamicWindowSize=1
AccurateText=1

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=python nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#CPUName.txt
RegExpSubstitute=1
Substitute="\s+#CRLF#":""

[MeterRun]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click to Run
LeftMouseUpAction=[!CommandMeasure MeasureRun "Run"]

[MeterResult]
Meter=String
MeasureName=MeasureRun
Y=10R
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
When I run this code, I get the output shown in the picture below.
Image

Substitute="\s+#CRLF#":"" : I played with this part a lot. I tried the codes you gave. I tried different variations but the image on the screen always remains like this.
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

Code: Select all

python nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC > totalBalance.txt
I found an alternative solution, but I didn't know if it would be possible to hold my left ear with my right hand. I would still like to share my opinion.
We save the above code as .bat.
When we click it, it will create a text document called "totalBalance.txt".
When we look inside;

Code: Select all

{'active': True, 'currency': 'BTC', 'totalBalance': '0.00000000', 'current': '0.00000000', 'debt': '0.00000000', 'pending': '0.00000000', 'btcRate ' : 1,0, 'status': 'ACTIVE'}"
These will be written.
I thought of an alternative like pulling the 'totalBalance': '0.00000000' part from this 'rainmeter' text document. I even looked at many case studies. I think I'm having a problem because there are single quotes and not double quotes. My mind is a million right now :)
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 13th, 2024, 6:36 pm nicehash python link : https://github.com/nicehash/rest-clients-demo
test api key code : python nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC

For now I can't run this outside of Python. I tried as you mentioned in your last message, but I got a 404 not found error. Let me share my test keys with you. The balance is currently zero so you may not see any profit. What matters is the work. I will be very pleased to be able to get the balance output, albeit slowly. I will test the information you provided in the last message to run Python. I think I can.

edited;

Code: Select all

[Rainmeter]
Update=1
DynamicWindowSize=1
AccurateText=1

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=PowerShell
Parameter=python nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC
State=Hide
OutputType=ANSI
OutputFile=#CURRENTPATH#CPUName.txt
RegExpSubstitute=1
Substitute="\s+#CRLF#":""

[MeterRun]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click to Run
LeftMouseUpAction=[!CommandMeasure MeasureRun "Run"]

[MeterResult]
Meter=String
MeasureName=MeasureRun
Y=10R
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
When I run this code, I get the output shown in the picture below.
Image

Substitute="\s+#CRLF#":"" : I played with this part a lot. I tried the codes you gave. I tried different variations but the image on the screen always remains like this.
No need for Update=1. No need for Powershell as the value of the Program option, using python there will do just fine. No need for an OutputFile option (unless you really want to save the output to a file for later use). You did almost everything right, but you didn't use the Substitute I mentioned, nor followed the advice about swapping the " and ' if the output used ' as field name delimiters.

Personally, I couldn't make it work since I got a Unexpected error: 401: Unauthorized: b'{"error_id":"318c81db-90f6-4fb0-90f5-c1a2176226c7","errors":[{"code":2005,"message":"Session IP not allowed <my IP here>"}]}' message. However, if you did get the ouput seen in the picture you posted, then the code works for you, you just need to follow my advice about some minor adjustments to the Substitute, e.g.:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC
State=Hide
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^(?:.*'totalBalance':(.*)[,}].*|.*)$":"\1","^\\\d+$":"","(?:^\s+|\s+$)":"","(?:^'|'$)":""

[MeterRun]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=Click to Run
LeftMouseUpAction=[!CommandMeasure MeasureRun "Run"]

[MeterResult]
Meter=String
MeasureName=MeasureRun
Y=10R
FontSize=14
FontColor=255,255,255,255
AntiAlias=1
Notice the differences compared to your code. Swapping the " and ' is necessary because using the same type of quote (i.e. single or double) inside a string as the quotes used to enclose / delimit that string will confuse Rainmeter, so, for example, you can have "This ' is fine" and 'This " is fine', but not "This " is fine" or 'This ' is fine'.

I reiterate what I said in my first replies: to get familiar with how to manipulate strings to your desire, take a look at RegExR.com or regex101.com to test regular expressions and get to know what such symbols mean (use the PCRE flavor of regex, since that is used by Rainmeter; on RegExR.com, you can use the RegEx Reference menu from the sidebar at the left of the page to help you understand what everything means). It might look complicated at first look, but it really isn't - there aren't more than around 30 or so symbols that one uses the most when dealing with regex, the rest is a bit of creativity and logic to do what you want. ;-)
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

I realized later that I had specified the IP address as a security measure when generating the keys. No one can enter except me. I realized later. I'm sorry for my carelessness.

I wanted to share the slightly edited and finished version.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Nicehash]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC
State=Hide
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^(?:.*'totalBalance':(.*)[,}].*|.*)$":"\1","^\\\d+$":"","(?:^\s+|\s+$)":"","(?:^'|'$)":""

[NicehashOdenecekBakiye]
Meter=String
OnUpdateAction=[!CommandMeasure Nicehash "Run"]

[NicehashOdenecekBakiyeText]
Meter=String
X=20
Y=78
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=Nicehash
Text=NiCEHASH    : %1 BTC
DynamicVariables=1
Just like you said, I missed the important points you mentioned. But again, you put the final point and made it work. I'm really grateful. Honestly, I work 14 to 16 hours a day. I try to spend as much time as possible at night. There is nothing that someone who knows Rainmeter coding cannot do. But thanks to you, I slowly started to adapt. I am currently looking for a new job for a better life. I'm so tired now. I can't find time for myself. If I can establish my routine, I will be able to spend more time on "rainmeter".
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 14th, 2024, 10:28 am I realized later that I had specified the IP address as a security measure when generating the keys. No one can enter except me. I realized later. I'm sorry for my carelessness.

I wanted to share the slightly edited and finished version.

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Nicehash]
Measure=Plugin
Plugin=RunCommand
Program=python
Parameter=nicehash.py -b https://api2.nicehash.com -o e3029db6-6e47-4d3b-a750-2a1b97b8ce6e -k 71ae774d-f7f8-4d12-b039-fa3ccf90e125 -s 6ac62486-9c87-4fe4-b016-87ee5d01114328f24d8a-987d-4316-a026-fed4b778d821 -m GET -p /main/api/v2/accounting/account2/BTC
State=Hide
OutputType=ANSI
RegExpSubstitute=1
Substitute="(?siU)^(?:.*'totalBalance':(.*)[,}].*|.*)$":"\1","^\\\d+$":"","(?:^\s+|\s+$)":"","(?:^'|'$)":""

[NicehashOdenecekBakiye]
Meter=String
OnUpdateAction=[!CommandMeasure Nicehash "Run"]

[NicehashOdenecekBakiyeText]
Meter=String
X=20
Y=78
FontFace=Consolas
FontColor=255,255,255,255
StringStyle=BOLD
StringEffect=SHADOW
FontEffectColor=0,0,0,50
FontSize=15
AntiAlias=1
MeasureName=Nicehash
Text=NiCEHASH    : %1 BTC
DynamicVariables=1
Just like you said, I missed the important points you mentioned. But again, you put the final point and made it work. I'm really grateful. Honestly, I work 14 to 16 hours a day. I try to spend as much time as possible at night. There is nothing that someone who knows Rainmeter coding cannot do. But thanks to you, I slowly started to adapt. I am currently looking for a new job for a better life. I'm so tired now. I can't find time for myself. If I can establish my routine, I will be able to spend more time on "rainmeter".
Yeah, no worries, everyone needs time to adapt and understand something - glad to see you finally managed to solve this. The priorities in life should always be your well being first, then real life and other stuff you care about, then as time permits other hobbies like Rainmeter and such - can't have or enjoy the latter if the former is not settled in a reasonable fashion. ;-)

P.S. You should add an UpdateDivider=<how many seconds between requests> to your NicehashOdenecekBakiye measure, otherwise it won't work well and you might be banned for excessively accessing the resource. I'd go for at least UpdateDivider=60 to run python and request data at least with a minute (i.e. Update × UpdateDivider = 1000 ms × 60 = 60000 ms = 60 s = 1 minute) interval between attempts. See this for details:
https://docs.rainmeter.net/manual/measures/general-options/#UpdateDivider

This is why I said that the RunCommand approach isn't exactly suited for near real-time monitoring - doing this from the address' API parameters in a WebParser would have been more natural, but even so, a slightly longer time between requests is highly recommended. This will probably depend on how many requests per day your account / IP is allowed to do by the site.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
mtchannel
Posts: 24
Joined: October 21st, 2021, 11:08 pm

Re: How to use api for unmineable pool?

Post by mtchannel »

Thanks to "Yincognito" I've come to the end now. Thank you very much. I decorated it a little and did the final make-up. I added some visuals. It looked very stylish. Now this is enough for me for 5-10 years :)

widget that calculates according to hashrate;
Image

Current prices and exchange rates of coins;
Image

Current earnings table of the pools I mine from;
Image
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: How to use api for unmineable pool?

Post by Yincognito »

mtchannel wrote: March 14th, 2024, 10:29 pm Thanks to "Yincognito" I've come to the end now. Thank you very much. I decorated it a little and did the final make-up. I added some visuals. It looked very stylish. Now this is enough for me for 5-10 years :)

widget that calculates according to hashrate;
Image

Current prices and exchange rates of coins;
Image

Current earnings table of the pools I mine from;
Image
You're welcome, I'm glad I could help (sorry for the delay in responding). :great:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth