openware / peatio

Open-source crypto currency exchange software (https://openware.com)
https://www.openware.com
MIT License
1.04k stars 625 forks source link

futures market feature #1888

Closed hardywu closed 1 year ago

hardywu commented 5 years ago

for pull request #1884 @ysv proposal at wiki page wiki at https://github.com/rubykube/peatio/wiki/Proposal-for-Futures-Marktet-Specs

schema change

Introduction New Data Model "Position" to record member's positions for each futures market.

#  member_id  :integer          not null
#  market_id  :string(20)       not null
#  volume     :integer          default(0), not null
#  margin     :decimal(32, 16)  default(0.0), not null
#  credit     :decimal(32, 16)  default(0.0), not null

margin store the margin value subs from quote unit account. credit store the sum of the values of the orders that build up the position in quote unit. Keep the sign of credit value of the opposite of the volume. This makes

volume * avg_price + credit = 0

i.e. A filled long order of 'BTC1903` at price 3000 USD and 10 volume, with margin_rate 10%, gives

position.volume += 3
position.credit -= 3 * 3000
position.margin += about 3 * 3000 * 0.10 (depends on the current position)

And update markets table with new columns

#  base             :string(255)      default("spot")
#  expired_at       :datetime
#  margin_rate      :decimal(32, 16)  default(0.1), not null
#  maintenance_rate :decimal(2, 2)    default(0.75), not null

base specifies whether the market is of 'spot' or 'futures'.

hardywu commented 5 years ago

@mod

Ideally this feature could be pluggable or have the ability to disable

Futures Market is enabled by setting base of the market to 'future'.

Do you think it's achievable to make a table of "Futures" orders that will be specifically Futures ?

Try to reuse the current order matching engine. A new table of "Futures' orders may requires Multiple Table Inheritance. Haven't try it yet. How would the benefits be based on your estimation?

ianeinser commented 5 years ago

@hardywu Good job Bro. Thanks for sharing

@mod

Ideally this feature could be pluggable or have the ability to disable

Futures Market is enabled by setting base of the market to 'future'.

Can both markets (spot and futures) be served at the same time since both depends on the same market data? How to enable future market in trading-ui?

Do you think it's achievable to make a table of "Futures" orders that will be specifically Futures ?

Try to reuse the current order matching engine. A new table of "Futures' orders may requires Multiple Table Inheritance. Haven't try it yet. How would the benefits be based on your estimation?

From business perspective, Peatio usage will get bigger commercial coverage since existing futures companies can also now adopt Peatio in their portfolios. On top of it, the prices of cryptocurrencies, esp. Bitcoin, are relatively higher than those of stocks.

hardywu commented 5 years ago

Can both markets (spot and futures) be served at the same time since both depends on the same market data? How to enable future market in trading-ui?

Spots and futures markets depend on different market data, but serving futures market for existing spots market is a must-to-have feature for professional traders. Both kinds of markets can share the same UI.

From business perspective, Peatio usage will get bigger commercial coverage since existing futures companies can also now adopt Peatio in their portfolios. On top of it, the prices of cryptocurrencies, esp. Bitcoin, are relatively higher than those of stocks.

I implement this feature because all traders I talked to consider spots only markets are for individual "investors" only.