uniVocity / univocity-trader

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

Support margin accounts #28

Open jbax opened 4 years ago

jbax commented 4 years ago

Margin works like this:

  1. account balance is X

  2. deposit some or all X into a margin account

  3. optionally borrow extra amounts via margin account (2x, 5x, 100x, whatever) - with interest

  4. buy/sell whatever you have: margin amount + borrowed amount

  5. close the trade by selling/buying back.

  6. close the loan and pay whatever interest was charged.

Interest might be charged per hour/day, etc. Binance charges anything from 0.01% per day to 0.3% depending on the asset. Interactive Brokers charges roughly 4% to 2%/year depending on amount borrowed, also charges interest daily.

Need to first incorporate interest calculation to simulations, then move on to live trading - consider that the exchange may not provide an API to open and close margin accounts (binance does).