frostybot-js icon indicating copy to clipboard operation
frostybot-js copied to clipboard

Stop-Limit/Stop-Market Long/Short Entry Orders + Erroneous SL order side

Open Ichibot200 opened this issue 3 years ago • 6 comments

Pardon me if I am mistaken, but currently, FrostyBot Allows for Limit or Market orders only. But there should be options for Stop-Limit and Stop-Market orders as well.

This change should allow posting Long or Short orders in Binance Futures as Stop-Limit or Stop-Market Orders.

I have made some initial modifications that I see would make it possible.

The command syntax for new order would be like this: trade:stub:long price=10.1 stopprice=10 base=100 symbol=*/USDT --- for Long Stop-Limit Order trade:stub:short price=9.9 stopprice=10 base=100 symbol=*/USDT --- for Short Stop-Limit Order trade:stub:long stopprice=10 base=100 symbol=*/USDT --- for Long Stop-Limit Order trade:stub:short stopprice=10 base=100 symbol=*/USDT --- for Short Stop-Market Order

Perhaps there have to be more changes in the core script library, that I do not know yet. Let's make the necessary adjustments and merge this PR for improved FrostyBot functionality.

From my commits README and install script can be omitted.

Ichibot200 avatar Jun 10 '21 20:06 Ichibot200

Good day

Stop limit, stop market and take profit orders are already supported. Please read the wiki for more information.

On Thu, 10 Jun 2021, 22:09 Ichibot200, @.***> wrote:

Pardon me if I am mistaken, but currently, FrostyBot Allows for Limit or Market orders only. But there should be options for Stop-Limit and Stop-Market orders as well.

This change should allow posting Long or Short orders in Binance Futures as Stop-Limit or Stop-Market Orders.

I have made some initial modifications that I see would make it possible.

The command syntax for new order would be like this: trade:stub:long price=10.1 stopprice=10 base=100 symbol=/USDT* --- for Long Stop-Limit Order trade:stub:short price=9.9 stopprice=10 base=100 symbol=/USDT* --- for Short Stop-Limit Order trade:stub:long stopprice=10 base=100 symbol=/USDT* --- for Long Stop-Limit Order trade:stub:short stopprice=10 base=100 symbol=/USDT* --- for Short Stop-Market Order

Perhaps there have to be more changes in the core script library, that I do not know yet. Let's make the necessary adjustments and merge this PR for improved FrostyBot functionality.

From my commits README and install script can be omitted.

You can view, comment on, or merge this pull request online at:

https://github.com/CryptoMF/frostybot-js/pull/79 Commit Summary

  • Installation from my branch
  • Installation guide from my own branch
  • Added stopPrice param
  • Added STOP and STOP_MARKET mapping

File Changes

Patch Links:

  • https://github.com/CryptoMF/frostybot-js/pull/79.patch
  • https://github.com/CryptoMF/frostybot-js/pull/79.diff

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CryptoMF/frostybot-js/pull/79, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMPQ2CFHXEJ3XSUULFYNK3TSELWFANCNFSM46PHVL2A .

CryptoMF avatar Jun 10 '21 20:06 CryptoMF

Wiki seems to be very cryptic. I still don't get what kind of parameters I need to add for those to work.

When Market price is about 39792 On my branch I tried: frostybot trade:long stub=testnet price=39794.1 stopprice=39794 base=0.5 symbol=BTC/USDT When Market price was about 39792

but I get: "2021-06-11 09:48:55 | NOTICE | Order added to queue: {symbol: BTC/USDT, type: STOP, side: buy, amount: 0.500, stopPrice: 39794, params: {}}", "2021-06-11 09:48:56 | WARNING | Unhandled Exception: InvalidOrder: binance createOrder() requires a stopPrice extra param for a STOP order at binance.createOrd er (binance.js:2076:23))", "2021-06-11 09:48:56 | WARNING | Unhandled Exception: TypeError: Cannot read property 'type' of undefined at frostybot_queue_module.submit (mod.queue.js:111:36))",

Perhaps there should be some more examples in the wiki?

EDIT: These messages were response on my dev branch. On frostybot-js/stable or frostybot-js/developement I just get LIMIT type order placed. "Stop limit, stop market and take profit orders are already supported." Indeed, but for stoploss and takeprofit trades only. I cannot rfind any reference as to whether this is explicitly supported for long and short trades.

This is a limitation is the Binance API. Even stop market orders must be placed with a price for some reason. From the Frostybot side, the existance of a stopprice parameter implies that you would like to place a stop limit order. This wortks on every exchange except Binance Spot if I recall correctly. In fact, I'm current using stop orders quite regularly on Binance Futures.

Ichibot200 avatar Jun 11 '21 09:06 Ichibot200

image After last commits I am getting somewhere with this. :) It's a success...

Strange is that if I define base=0.5 it converts the amount to 0, but if I use base=0.500 it works well.

Ichibot200 avatar Jun 11 '21 11:06 Ichibot200

image Perhaps not exactly related to this topic, but If I have Market price at 39792, Long position opened and I post stoploss order below market price, FrostyBot thinks that it should have STOP_MARKET order with buy side??? I believe it should be sell side. Take Profit is posted correctly. And another issue is that, once Position is closed on the testnet exchange, the FrostyBot Positions tab still thinks that I have position opened. It seems as if the cache is not cleared properly at the right moment. After longer period of time it vanishes from cache.

Ichibot200 avatar Jun 11 '21 12:06 Ichibot200

image Perhaps not exactly related to this topic, but If I have Market price at 39792, Long position opened and I post stoploss order below market price, FrostyBot thinks that it should have STOP_MARKET order with buy side??? I believe it should be sell side. Take Profit is posted correctly. And another issue is that, once Position is closed on the testnet exchange, the FrostyBot Positions tab still thinks that I have position opened. It seems as if the cache is not cleared properly at the right moment. After longer period of time it vanishes from cache.

Hi there

This is because the determination for the order side is done using the current market price, not the position entry price. If you're testing this on the Binance testnet then I can assure you you're going to have a lot of weird problems.

CryptoMF avatar Jun 14 '21 03:06 CryptoMF

Yes perhaps that is correct for takeprofit and stoploss orders indeed. But... What I am looking for is Stop(-Limit) entry for long and short positions in Binance Futures. So far Frostybot enabled me to have only Limit Entry. My modifications, as robust as they might be, allowed me to get the Stop Entry working. Yet latest discovery is that, if I tried Market entry, it threw an error that a parameter stopPrice is missing... I will probably fix it some time.

Currently my biggest concern is why stoploss order side gets flipped. I have been digging the codebase a little and I see lots of switches and conditions that determine the side parameter. For now it is rather confusing (most probably because I am really new to this code :) )

Ichibot200 avatar Jun 27 '21 21:06 Ichibot200