Qiita記事をごらんください。
This program is an auto-arbitrage trade for Bitflyer, Bitcoin Exchange Point.
Trade target is price gaps between Bitcoin spot trading and futures.
This program was recently published, please report bugs
Trade method using price gaps of two or + markets with sililar financial instrument.
Market A 110yen/BTC, Market B 100yen/BTC
If we BUY 1BTC at Market B and SELL 1BTC at Market A, we can earn 110-100=10yen.
This profit is ensured with reason that these two market treat same financial instrument and price will be same after a while.
Spot trading and Futures will be the same price at SQ time, so this fact enables arbitrage trade.
This method said to be low risk and low return (only theoretically, not practically).
screenshot shows...
- logging time
- Trade Pair
[spot_trading][futures]:size
- besk_ask, besk bid, each size
- showing expectable profit(normal is minus value = no arbitrage oppotunity)
See file LICENSE
. 2 licenses included by part.
USE THIS PROGRAM AT YOUR OWN RISK.
Python 3.6.4
Adjust PC time accurately for avoiding time gap with Bitflyer server time.
install requests
and six
pip install requests
pip install six
Get Bitflyer API KEY and SECRET for auto-trading.
Set API Authorization below.
KEEP API KEYS AND SECRET IN SAFE PLACE
Prepare money for trade.
Set levarage at x1 for avoiding loss-cut.
Money balance is X for spot trading, 1.8X for futures.
Get extra BTC for commission.
max position 20,000 yen for each side.
spot trading : 20,000 yen
futures : 38,000 yen(18,000 for deposit)
0.003 BTC for commission
- Install Python 3.6.4
- Download or git clone this repository.
- Get API KEY and SECRET. Prepare money on your account.
- Rename
config_default.json
toconfig.json
- Set items of
config.json
(APIKEY aren APISECRET are requisite) - Run
main.py
List of config.json
setting
adjust maturity_time, itayose_time, sq_time, reboot_time
to your time_zone,
default time is for Tokyo,Japan (UTC+9).
items | descriptions |
---|---|
demo_mode | true :virtual trade, false :real trade |
demo_trade_interval | trade interval of demo mode. not real trade |
message_language | EN :English JP :Japanese |
api_key | Set Bitflyer API KEY |
api_secret | Set Bitflyer API SECRET |
swap_point_rate | Futures Swap point rate |
position_value | Trade amount at one trade(BTC). For each assets(ex.spot trading, futures) |
max_position_value | Max trade amount(BTC) For each assets(ex.spot trading, futures) |
expect_profit_threshold | Do arbitrage trade when expect profit(yen) is more than this value |
close_pair_before_sq | When spot trading price > futures price , close position |
closing_margin_time | If above condition is kept for this value[sec], close position.(close_pair_before_sq shoulf be true) |
maturity_time | Maturity time of futures |
maturity_time_margin | Buffer time of maturity time[sec] for avoiding problems of time gap between PC and server |
itayose_time | spot trading itayose time |
sq_time | SQ settlement time |
std_stream_logging_interval | Showing interval of regular log |
arbitrage_loop_cooling_time | Arbitrage trade interval during continuous trade oppotunity |
websocket_retry_after | Retry Websocket connection after this value[sec] |
arbitrage_debug_mode | Get virtual arbitrage oppotunity data.Set DEMOMODE to use it, or real trade with fake data |
maturity_debug_mode | Make the program run virtual maturity, iyayose and reboot time |
debug_maturity_start | For debug, virtual maturity time |
debug_itayose_start | For debug, virtual itayose time |
debug_reboot_start | For debug, virtual reboot time |
Program modules are made along multiprocessing.
(Futures best bid) - (Spot trading best ask) - 2 x (commission) - swap point = expect profit
If expect profit > expect_profit_threshold
, the program regards it as an arbitrade oppotunity.
This oppotunity often occures when BTC price goes down rapidly, or when maturity time comes close.
config.json
is read when boot and reboot.
Dynamic setting change isn't supported.
yyyymmdd.log
for level-info log.
yyyymmdd_high_level
for level-warning log for tracing trade log.
Product_code is the identifier of each Bitflyer board.
ex. BTC_JPY : spot_trading, BTCJPY24AUG2018: Futures with maturity date(August 24)
r2 arbitrager, Arbitrager BETWEEN BTC Exchange points.