Three years ago i released a bot that allows you to automatically trade a coin when it's listed on binance exchange now the code became obsolete and the two no longer work so i got a lot of emails and comments to upgrade the bot so here i am finally releasing a newer version of that bot the bot's functionality can be divided.
Into two phases the first one is detection the second one is trading in the previous version of the bot i used a rest api to frequently pull the server every few seconds to detect when a new coin is listed it's not really that efficient so in this version i used a websocket so that the server itself tells you when a new coin is listed so.
You get the best entry time once the coin is detected the bot goes into the trading phase where the bot places a market order for the specified quantity and after the market order is filled it immediately places a sell order or an oc order depending on your settings we'll discuss more about the cell settings later in this video.
When we talk about each individual component of this bot all right now let's look at the code so the code is structured into different modules where each module handles a certain part of the functionality with the detection module so here is where we handle the detection part of the code so as i explained.
Earlier we connect to a web socket and listen to the ticker stream to detect a new coin so let's look at how the code is structured in this module so we have this refresh symbols function that takes a snapshot of all the pairs to compare and identify a new coin then we have this open on open function that connects to the.
Mini ticker stream when the socket is connection is established then we have this on error function that reconnects the socket when there is an error then we have this heartbeat function that also reconnects the socket when there's a network issue.
Then we have this process stream function that listens to all the incoming data stream and detects a new coin and finally we have start websocket function which brings all the previous functions together to make it work as expected then we have this binance dot js module which handles all the binance.
Api calls public and signed api calls then we have this orders.js module that handles the order management part of the code so here we have the code to handle the buy and the sell orders that we need to place once the coin is detected and then we have this index.js file which we're going to run when we run the bot and this module brings all the other.
Modules together to create the desired functionality and finally we have this environment variable file which is the dot env file where we pass all the settings for this board so here we specify the api key and secret key which are needed to place the buy and sell orders after the coin is detected now to keep your account really.
Secure i suggest you to only allow access to the ip address where you're running this bot so that your account is really secure then we specify the dollar amount for which the bot has to make it rate so keep in mind that this version of the bot only works for the usd market and the bot will place a buy market order as.
Soon as it's detected for the specified quantity once the buy market order is filled the bot will place a sell order or an oc order depending on these two conditions so here we specify the profit and stop loss conditions in percentages so these two and one these values are interpreted as percentages and if you just specify profit as two percentage.
Then the bot will place a sell limit order at two percent price point and if you specify both profit loss profit and stop loss then the bot will place an oco order with profit at two percent and stop loss at one person price point let me summarize the functionality again so the bot will.
Use a web socket to detect a new coin listing and when a new coin is detected in the usd to the market the bot will place a market buy order for this quantity and when it's filled it places a sell order at this price point or an oc order if both profit and stop loss percentages are specified here are some observations that i made.
While testing the bot so the first coin that i traded using this is proto usdt that got listed on 16th of november and this is the first payload that was received by the websocket and this value is the timestamp in milliseconds when the payload was first received so you can consider this as the timestamp when.
The coin got listed on the exchange and then we have the symbol and then we have oh lc which is the open high low close values of the price i know the coin just got listed but i don't know where these values are coming from but this is what was sent by the trade stream so our bot detected this at this time stamp again in milliseconds so you can.
See that the bot detected in 58 milliseconds which is you know quite quite good and quite fast compared to the previous version one other thing that i noticed is that there's a delay in trading view loading this coin so if you open this coin now on trading view you will see the data starting from the exact time stamp but.
When the coin was initially listed there was a few hours delay before trading view could show this information and finally i noticed that there's a 3000 price difference between the opening and closing price of the scandal i know the coin just got listed so i don't know where the price difference is coming from and where this volume is.
Generated from if you have more information on this you can let me know in the comment section but i'm surprised where this volume is getting generated when the coin is just listed on the the second coin that i tested is power duty which got listed on 17th of november and as you can see this one was also detected in 59 milliseconds which.
Is quite good and i also noticed a delay in trading view updating this information and one thing i noticed differently with the previous one is that the price difference is only 38 it is still high but it's not as high compared to the previous symbol i think it's because this coin was already available in the btc market which is why.
It may not be so volatile when it got listed in the usdt market finally this is the pair that i last tested and the one that i actually traded using this bot so as you can see it got detected in it got listed on 26th of november at 1 30 pm india time and it got detected in 68 milliseconds which is again quite good and you can.
See here i put a screenshot of trading view and you can see that the data starts from two o'clock whereas the coin is actually listed at 1 30 pm so i notice that there's a delay in trading view updating this information so it after if you check this coin after a few hours then it will show the full data but.
Initially for the first few hours you will see the data missing on trading view and you can see the price difference between open and close price is around 20 when the coin got first detected this is the first payload that is sent by the websocket and here are the trade results that i.
Posted in the below screenshot the bot uh you can see that when the coin got listed at 130 it immediately bought it at 37 and i used a i didn't use an oco order to execute the trade i instead used a just a sell order at five percent profit but you can see that the sell order is.
Placed at 130 but it never got triggered so the price it dropped so the price never hit the target 38.85 i noticed this at around 2 20 p.m and i manually closed this trade at 10 loss you can see i initially bought using 100 and sold at 90 so i lost 10 dollars in this trade before i wrap up the video here are some.
Quick tips for you to consider the first tip is to avoid a tight stop loss when a coin is nearly listed on the exchange it's generally quite volatile so if your stop loss is too tight then the order may fail when it's placed by the board so i suggest you to not put a very close stop loss second do not put hundred percent of.
Your wallet balance as the trade size when you use the bot if you have hundred dollars in your wallet i suggest you to put 90 or around 80 as the trade size in the bot leave 10 to 20 for margin the reason you have to do this is because again when a con is.
Newly listed it's very volatile and by the time the bot calculates the quantity needed to be placed for the particular price the price could drastically you know change so you have to take some amount of buffer into account to avoid any errors when the trade is executed the third point is not necessarily a tip but i think we can improve in the way we.
Handle the trade using this bot so right now it like i said there are two parts to this bot right one is the detection and the other one is trade management we're able to detect when a coin is nearly listed in milliseconds so that part works very well but i think we can create some strategies as to how we handle the trade so if you have any.
Suggestions on how we can improve the strategy you know handle the trade well then leave them in the comment section and i'll try my best to incorporate them in the next version i showed you earlier that i lost 10 percent in the first trade that i did using this bot so it is not full proof and i think it.
Still needs some improvement in the way we handle the trade as of now the bot only supports usdt market but i think in future versions it's helpful to have other markets as well let me know in the comment section if you want to use this bot for other markets too lastly just a word of caution.
Do not use the bot if you don't know what you're getting into this is just a tool it doesn't guarantee any magical profits you've seen that the first rate that i did i lost 10 percent so understand what you're getting into and some people might even be worried about some malicious code that allows me to steal sensitive information like api.
Keys so if you have those concerns verify the code thoroughly and only when you're comfortable use it at your own risk even if you have the slightest hesitation i strongly advise you to not use the bot that's it for the video like i said earlier if you have any suggestions or.
Improvements that the bot can benefit from feel free to leave them in the comment section and i'll try my best to incorporate them happy thanksgiving and i'll talk to you soon bye