Automatically buying HBD when it is "on sale".
Someone asked if there was a bot to buy HBD when it is below $1 on Bittrex.
While I don't know of any bot that is able to do this, the process it pretty simple. I am going to use Python, but this can be done just as easily in Javascript or any other language.
import requests
TICKER_ENDPOINT = 'https://api.bittrex.com/v3/markets/tickers'
tickers = requests.get(TICKER_ENDPOINT)
if not tickers.ok:
print("Something went wrong")
for ticker in tickers.json():
if ticker['symbol'] == 'HBD-BTC':
hbd_btc = float(ticker['lastTradeRate'])
if ticker['symbol'] == 'BTC-USD':
btc_usd = float(ticker['lastTradeRate'])
hbd_usd = btc_usd*hbd_btc
if hbd_usd < 0.98:
print("BONANZA!")
# bittrex.buy()
else:
print(f"HBD: {hbd_usd}")
This code is pretty simple, and will query Bittrex API looking for the current price of BTC and HBD.
There is a BTC-USD pairing, which means we can treat the BTC price as USD. Bittrex only has a HBD-BTC pairing, meaning we need to treat HBD as a BTC price.
First we need to import requests, this is the goto library in Python to fetch data on the web and communicate with APIs.
If you do a quick Google search for "Bittrex API" you will find this page.
Some quick looking around you will find what we are looking for is a list of their tickers.
It looks like this end point has what we are looking for. 'https://api.bittrex.com/v3/markets/tickers'
As you can see it is basically a list of dictionaries containing some basic market data on each of their pairs.
So let's download this data into a variable named tickers
using tickers = requests.get(endpoint).
Let's do a quick guard clause to make sure we have a valid response.
if not tickers.ok:
print("Something went wrong")
Request has a nice feature where you can check the response for valid status codes. You can also query tickers.status_code to get the exact status code or use ticker.raise_for_status() which will throw an exception on a bad status code. Requests has a few ways to handle this in more detail.
Now that we have a reasonable expection of ticker data, we need to iterate the results to find the ones we are looking for. This can be done in many ways, I opt'd for a more straight forward approach that is easy to read as a laymen.
for ticker in tickers.json():
if ticker['symbol'] == 'HBD-BTC':
hbd_btc = float(ticker['lastTradeRate'])
if ticker['symbol'] == 'BTC-USD':
btc_usd = float(ticker['lastTradeRate'])
This iterates (goes though every one) all the dictionaries that represents each pair in the list and assigns the result we are looking for into variables.
At this point hbd_btc represents the last trade price (in BTC) of HBD. btc_usd represnts the last trade price of BTC (in USD). We are looking for a USD price of HBD, so we can multply the two to get a USD version of HBD.
hbd_usd = btc_usd*hbd_btc
Simple enough, and now we have a hbd_usd pairing price, technically this doesn't exist but it gives us an accurate price of HBD in terms of USD if we traded both on Bittrex immediately.
At this point we just need a simple if statement to check if HBD is below our buy threshold.
if hbd_usd < 0.98:
print("BONANZA!")
# bittrex.buy()
else:
print(f"HBD: {hbd_usd}")
# bittrex.buy()
is just a comment and would be where we would add code to authenticate and execute a buy order for HBD on Bittrex.
Using the last traded price may not be the best option, you may want to use bid or ask prices a more accurate representation of the current price. You could experiment with different options to see how it more accurately reflects your needs.
If the ask price of HBD is below, you can comfortable knowing the price is below $1 as people are trying to sell at this price. If the bid price is below $1, this could just be people trying to undercut the price and isn't as accurate representation of the "current price" of HBD.
Why you should vote me as witness
Posted Using LeoFinance Beta
That's nice, we need more arbitrage hunters.
https://twitter.com/itsjustmarky/status/1456063469812428800
The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.
I know absolutely nothing about bots so this was extremely interesting and informative. I'm going to have to study this for a while to figure it all out but thank you for putting it out there. !PIZZA
Posted Using LeoFinance Beta
PIZZA Holders sent $PIZZA tips in this post's comments:
@dagger212(1/20) tipped @themarkymark (x1)
Learn more at https://hive.pizza.
Tnx ser :)
This is cool, now all I need to do is figure out how to run this.
Ots quite simple to run python script at your pc. Install and run like: python Mybot.py
But i thin you will need to make few improvement at this code... Bit its great starter
I have been wondering if features like this could be used by front ends so regular Joes could participate in this to help stabilize HBD price.
This, i would totally want to"pull my weight" but dont know anything on coding....
Right? Similar to the internal market, if everyone had their 10 HBD orders in, it would help stabilize the price I would think.
Is something like this possible @jarvie?
I really can't understand the technique behind these bots and scripts, I know a little about how python could extract this data and stuff, but a naive question may I? How exactly would it execute a BUY order when I'm not logged directly inside my Bittrex account?
It would automatically authenticate.
Very informative thanks much.
The creation of any movement on the exchange is a good deed!
Hmm ... in essence, you predict market intentions with your method?
No prediction logic, just reaction.
marky's got some great tastes when it comes to thumbnails
Headlines and thumbnails are 90% of what drives people to actually spend more than 1 second.
100% agree :)
In that case, it was a tad more than a second. But the article was satisfying as well.
I have to admit, I didn't understand a word of that, but I wanted to leave a thank you for your memes. I didn't catch covid yet, so you must be right :o).
While coding means nothing to me, I can see that this is a pretty clever use of the available resources to get to the answers that you need to support the functionality required. Nice one!
This looks so interesting. But I am wondering how to use it!