uniVocity / univocity-trader

open-source trading framework for java, supports backtesting and live trading with exchanges
577 stars 140 forks source link

Support short selling #27

Closed jbax closed 4 years ago

jbax commented 4 years ago

For live trading with stocks this is one of the common processes:

  1. need to have X amount in account.

  2. short sell up to the equivalent X amount. Additional fees may apply, also might need to close trade before end of trading session to avoid paying interest.

For Binance (and possibly others), you can only do that with a margin account. I'll open a separate issue for this.

jbax commented 4 years ago

Done. README updated.

The Strategy interface now has a tradeSide method

public interface Strategy {

  default Trade.Side tradeSide() {
    return null;
  }
}

A Strategy that only generates signals relevant for shorting has to return Trade.Side.SHORT when tradeSide() is called by the framework.

For signals relevant only for regular (long) trades, tradeSide() must return Trade.Side.LONG. If the same strategy can work for both long and short trades, simply let the default implementation do its job and return null.

NOTE: Shorting is disabled by default, to enable it, invoke enableShorting() from
AccountConfiguration;