[Guide] Buying (not selling) a coin exactly when listed, at market rate, in Spot Trading (not Margin) #105
ADTC
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all, I made changes to this project in order to buy
THE(Thena) when it listed today. I am on MacOS so I had lot of challenges and only a few hours to fix them. Here are my notes:Which Python?
Using the right Python was the first challenge. MacOS has an outdated version of Python 3 pre-installed, and you can install latest Python through Homebrew. Both won't work here.
python-binanceneeds OpenSSL.externally-managed-environment.Your best bet is to download the
pkgfile from Python website and install it with the installed. When you runwhere python3you should see/usr/local/bin/python3in the list. You must always use this with the exact path. Example:/usr/local/bin/python3 ./main.pyDependencies
Installation script:
I do not install Selenium because I will not use it. See below.
PS: To project author: It will be helpful if the dependencies are in a
requirements.txtfile.Code changes
Selenium dependency is for the web scraper, which just checks Binance Announcements page and sends an email when a new coin is announced. This part of the project is entirely optional and if you're just trying to buy/sell a new listing, it's totally unnecessary.
I also think this will slow down the Python interpreter even further, so it's better to remove it.
# from new_listings_scraper import *# threading.Thread(target=search_and_update, ...EMAIL_ADDRESSandEMAIL_PASSWORDkeys inconfig.yml. You don't need to set anything here.Just to know that something is happening, I added a dot indicator. This is completely optional:
Avoid selling immediately. We're looking to HOLD the coin we bought:
Change the order type from a Margin Order to a Spot Order:
In
trade_client.pyassetBalanceto the number you want (decimals accepted).And in
main.pyNext, get rid of price and volume computations (you no longer need them after above change):
In hindsight, I should have commented out the print statements as well, because it slows down the interpreter when trying to buy the coin (by milliseconds, yes, but those milliseconds matter!):
Configuration changes
config.ymlI had to fix the quoting inEMAIL_PASSWORD: "I'll let you figure out what this one is"or the YAML processor will error out trying to parse this.EMAIL_PASSWORD: ''.auth.ymlI commented out the# binance_tldkey because my TLD iscom. If yours is different, you will need to set it.Binance API and testing
When setting up the API keys, you need to add your own IP address to Binance API management. Just search "what is my IP address" in Google, and use any website to get it. Only after you add an IP address, you can enable "Spot and Margin Trading" access for the API key.
To ensure that your API keys are working correctly you should try retrieving the balance of any existing currency. Just add this to
trade_client.pyat top level (afterclientis defined):Try a test run with
/usr/local/bin/python3 ./main.pyand if you can see your balance, the API key works. (If you added the wrong IP address, it will fail.) Once tested, terminate the script with Control-C pressed twice.Live Run
Now you can set
TEST: Falseand run it 1 minute before the coin goes live.My Result: Newly listed coin was purchased with my USDT balance immediately at the 0-second mark upon listing, but there was still some milliseconds delay. I'm estimating 700 milliseconds, and the price rose a little from the initial listing price. Nevertheless I got a very competitive price and I'm making a decent profit by holding.
Live Run Update
Successfully purchased two new listings (at the same time) with the script optimized to only print anything after buying both:
Also, commented out all unused variables and imports.
In order to split my USDT balance $50 equally between the two new listings, I added this in
def create_order(coin, asset):Note: Because of market volatility, the exact amount may be greater than 25 but only by a few cents, which is why we compare
> 30which is still well below 50.Beta Was this translation helpful? Give feedback.
All reactions