출처: Algo-Trading-and-Market-Making.pdf (bitmex.com)
Algo Trading &
Market MakingWIFI
Network: theHive21
Password: thehive21Materials
Example market making bot
BitMEX Testnet Account
BitMEX API DocumentationBitMEX Testnet
This is a staging environment used for testing
Testnet accepts Testnet Bitcoin which have no real world value
Testnet is an exact replica of the production exchange
Always test your bot in Testnet before deploying to production
To signup on Testnet, use a verified email addressAPI Overview
BitMEX features a REST and Websocket API
Use Websocket to be pushed data in real-time
Use REST primarily for order submission, amendment, and cancellation
Most other Bitcoin exchanges feature a REST and Websocket APIREST Calls
Type this into your browser:
https://www.bitmex.com/api/v1/trade?symbol=XBTUSD&count=100&reverse=false
Use the BitMEX API Explorer to try out sample REST callsWebsocket Example
For Mac users type this into your terminal:
npm install -g wscat
After installing “wscat” type this
wscat -c wss://www.bitmex.com/realtime?subscribe=trade:XBTUSD
This pushes the live trade feed for XBTUSDAPI Keys
To authenticate your trading bot, you will need to generate API Keys
You will receive a public API Key and a private Secret
Be careful, anyone in possession of these keys can access your accountTrading Bot Setup
A comprehensive README.md file is included in the GitHub repository
I will now take you through setting up the trading bot and running it on TestnetMarket Making
The process of quoting continuous passive buy and sell prices to provide liquidity
On BitMEX market makers post two-way quotes on various products
Market makers are delta neutral, they don’t have an outright market view
Traders market make to earn rebates, currently 0.025%
Traders market make to earn their bid / ask spread
If done correctly, can be a source of consistent trading incomeFair Price
Inputs:
● Underlying Index price
● Cost of capital
Outputs:
● Bid / Ask price for the contract
Tools:
● An automated trading bot does the calculations and continuously updates
quotesFair Price Example
BitMEX Product: ETH7D (7 Days until expiry)
Underlying: ETH/XBT Price on Poloniex
ETH/XBT Spot Price = 0.05 XBT
XBT Borrow Cost Per Day: 1%
ETH Borrow Cost Per Day: 2%
ETH/XBT Fair Price = 0.05 XBT * (1 + 2% * 7) / (1 + 1% * 7) = 0.052371 XBT
Fair Price Example Cont.
ETH7D Fair Price = 0.052371 XBT
Desired Bid / Ask Spread = 2%
ETH7D Bid = 0.052371 XBT * 0.99 = 0.051847
ETH7D Ask = 0.052371 XBT * 1.01 = 0.052895
Determining Your Spread
Your spread determines your potential profit, choose it wisely.
Spread = ETH/XBT Volatility + Hedging Costs
ETH/XBT Volatility = your estimation of how much the price could move before
you hedge or receive a trade in the other direction
Hedging Costs = how much it costs in terms of bid / ask spread and commissions
to trade ETH/XBT on Poloniex
Trade Walkthrough
1. You quote a market on ETH7D, 1 contract on both the Bid and Offer, of 0.05
XBT / 0.1 XBT
2. A trader lifts your offer, you are now short 1 ETH7D contract
3. To hedge your delta, you buy 1 ETH for XBT on Poloniex at 0.085 XBT
4. Your market remains 0.05 XBT / 0.1 XBT
5. A trader hits your bid, you are now flat on ETH7D
6. To hedge your delta (you are now long 1 ETH on Poloniex), you sell 1 ETH for
XBT at 0.065 XBT.
Trade Walkthrough PNL
BitMEX Trades:
Sell 1 ETH7D @ 0.1 XBT
Buy 1 ETH7D @ 0.05 XBT
Profit = 0.05 XBT
Poloniex Trades:
Buy 1 ETH @ 0.085 XBT
Sell 1 ETH7D @ 0.065 XBT
Loss = 0.02 XBT
Net Profit: 0.03 XBT
Settlement
Sometimes you will have a BitMEX position and a hedge, and must exit that hedge
during the settlement calculation period.
The goal is to match the unwind of your hedge vs. the settlement index of the
contract.
ETH7D expires using a 30-minute Time Weighted Average Price of the ETH/XBT
price on Poloniex.
Settlement Example
BitMEX Portfolio: Short 30 ETH7D contracts
Poloniex Portfolio: Long 30 ETH vs. XBT
At 11:30 UTC on Friday, pull your BitMEX ETH7D quotes
Each minute from 11:30 to 12:00 UTC, sell 1 ETH on Poloniex, you average
execution price will match the settlement price for ETH7D on BitMEX.Post Only
As a market maker you never want to pay taker fees
To ensure you always place a passive limit order use Post Only orders
On your order submission:
‘execInst’: 'ParticipateDoNotInitiate'
Skew
The goal of market making is to buy low, sell high as quickly as possible, as much
as possible.
The more hedging you do, the less money you make.
To attract the other side, market makers will skew their quotes as they receive
trades.
General Rule: For each full size transacted, skew your quotes half your spread.Skew Example
You are quoting ETH7D at 0.05 XBT / 0.1 XBT for 1,000 contracts a side
You are lifted for 1,000 contracts, since your spread is 0.05 XBT, you move your
quotes higher 0.025 XBT
Your new market is 0.075 XBT / 0.125 XBT
You are hit for 1,000 contracts, you now move your quotes down by 0.025 XBT
Your new market is 0.05 XBT / 0.1 XBT
Skew Example Cont.
Remember on BitMEX you receive a 0.025% rebate as a market maker
BitMEX Trades:
Sell 1,000 ETH7D @ 0.1 XBT, rebate 0.025 XBT
Buy 1,000 ETH7D @ 0.075 XBT, rebate 0.01875 XBT
Market Making Profit: 2.5 XBT
Rebate: 0.04375
Total Profit: 2.9375 XBT
Skew Considerations
Optimal Conditions: Low volatility market, with very active two-way flow
Bad Conditions: High volatility trending market, with one-way flow
Every trader’s delta tolerance is different
The more sophisticated your bot, the better you can handle jump or gap risk
Basis Market Making Ask Side
ETH7D currently trades at a 10% outright premium with 7 days remaining
You can borrow Bitcoin at 1% per week
Selling ETH7D and buying ETH allows you to earn net 9% on the week
As long as you are net short ETH7D, you don’t mind quoting a two-way price
As soon as you become flat ETH7D, you will only quote offers
Basis Market Making Bid Side
ETH7D currently trades at a 10% outright discount with 7 days remaining
You can borrow Bitcoin at 1% per week
You can then use that Bitcoin to borrow ETH on margin for 2% per week
Buying ETH7D and shorting ETH allows you to earn net 7% on the week
As long as you are net long ETH7D, you don’t mind quoting a two-way price
As soon as you become flat ETH7D, you will only quote bids.
Basis Market Making
Inputs:
● Cost of capital on the home and foreign currency
● Spot price of the underlying
Outputs:
● Two-way quote depending on whether your portfolio has a net positive carry
or theta
Appendix - Useful Terms
Bid = Buy Price, You “Hit” Bids
Ask or Offer = Sell Price, You “Lift” Offers or Asks
Delta = The value of your position in either the home or foreign currency
Theta or Carry = How much money you stand to make or lose by the passage of
time
Basis = Futures Price - Spot Price
'Finance' 카테고리의 다른 글
Huobi Global - Grid Trading Rankings (0) | 2021.07.13 |
---|---|
Is the sample BitMEX market maker bot profitable? (0) | 2021.07.11 |
비트코인 MDD (0) | 2021.07.06 |
비트코인 전송 속도 (0) | 2021.07.05 |
비트코인 논문 한국어 번역판 (0) | 2021.06.25 |