Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to implement OTOCO #611

Closed
MushiTheMoshi opened this issue Aug 31, 2024 · 3 comments
Closed

how to implement OTOCO #611

MushiTheMoshi opened this issue Aug 31, 2024 · 3 comments

Comments

@MushiTheMoshi
Copy link

MushiTheMoshi commented Aug 31, 2024

Hi there,

Thanks for the hard work done here, greatly appreciated!

Looking to implement an OTOCO order in futures api, as per read the doc is not implemented in the same, was wondering then how to implement a take-profit and stop-loss order that auto close the other when one meet condition?

Am I doing something wrong, or this is an unsupported thing. Googled a bit and seems that when quantity is the same in position and orders the expected behavior is achieved , which is not the case here, any help is much appreciated...

this is my code:

position_market, err_pos := client.NewCreateOrderService().
        Symbol(TICKER).
        Side(futures.SideTypeBuy).
        PositionSide(futures.PositionSideTypeLong).
        Type(futures.OrderTypeMarket).
        Quantity("0.03").
        WorkingType(futures.WorkingTypeMarkPrice).
        Do(context.Background())

  position_tp, err_tp := client.NewCreateOrderService().
	  Symbol(TICKER).
          Side(futures.SideTypeBuy).
          PositionSide(futures.PositionSideTypeLong).
	  Type(futures.OrderTypeTakeProfitMarket).
	  TimeInForce(futures.TimeInForceTypeGTC).
	  StopPrice(TP).
	  WorkingType(futures.WorkingTypeMarkPrice).
	  Quantity("0.03").
	  Do(context.Background())
  
  position_sl, err_sl := client.NewCreateOrderService().
	  Symbol(TICKER).
	  Side(TYPE_SIDE(SIDE != "LONG")).
          PositionSide(futures.PositionSideTypeLong).
	  Type(futures.OrderTypeTakeProfitMarket).
	  TimeInForce(futures.TimeInForceTypeGTC).
	  Quantity("0.03").
	  StopPrice(SL).
	  WorkingType(futures.WorkingTypeMarkPrice).
	  Do(context.Background())

Regards,
Julio

@xyq-c-cpp
Copy link
Collaborator

xyq-c-cpp commented Sep 3, 2024

I think your implementation is right, but you should do some tests to verify it with some real trades. @MushiTheMoshi

@MushiTheMoshi
Copy link
Author

ok, thanks for confirming, will give it a try...

@MushiTheMoshi
Copy link
Author

seems ok, thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants