BitMEX / sample-market-maker

Sample BitMEX Market Making Bot
Apache License 2.0
1.7k stars 757 forks source link

Close status: 31522 #47

Closed dmh181 closed 6 years ago

dmh181 commented 6 years ago

Hi, It's just on testnet. The market maker bot started and shutted down immediately after display 6 buys and 6 sells information. Any ideas. Thanks!

Below are log and my setting.py

Log:

2018-01-15 16:31:48,213 - INFO - market_maker - BitMEX Market Maker Version: v1.1

2018-01-15 16:31:48,214 - INFO - ws_thread - Connecting to wss://testnet.bitmex.com/realtime?subscribe=quote:XBTUSD,trade:XBTUSD,instrument,order:XBTUSD,execution:XBTUSD,margin,position 2018-01-15 16:31:48,214 - INFO - ws_thread - Authenticating with API Key. 2018-01-15 16:31:48,217 - INFO - ws_thread - Started thread 2018-01-15 16:31:51,219 - INFO - ws_thread - Connected to WS. Waiting for data images, this may take a moment... 2018-01-15 16:31:51,822 - INFO - ws_thread - Got all market data. Starting. 2018-01-15 16:31:51,822 - INFO - market_maker - Using symbol XBTUSD. 2018-01-15 16:31:51,822 - INFO - market_maker - Initializing dry run. Orders printed below represent what would be posted to BitMEX. 2018-01-15 16:31:51,825 - INFO - market_maker - XBTUSD Ticker: Buy: 13731.0, Sell: 13736.0 2018-01-15 16:31:51,832 - INFO - market_maker - Start Positions: Buy: 13662.8, Sell: 13804.2, Mid: 13733.0 2018-01-15 16:31:51,834 - INFO - market_maker - Current XBT Balance: 0.000000 2018-01-15 16:31:51,835 - INFO - market_maker - Current Contract Position: 0 2018-01-15 16:31:51,835 - INFO - market_maker - Contracts Traded This Run: 0 2018-01-15 16:31:51,835 - INFO - market_maker - Total Contract Delta: 0.0000 XBT 2018-01-15 16:31:51,836 - INFO - market_maker - Creating 12 orders: 2018-01-15 16:31:51,838 - INFO - market_maker - Sell 100 @ 13804.0 2018-01-15 16:31:51,838 - INFO - market_maker - Sell 200 @ 13873.0 2018-01-15 16:31:51,838 - INFO - market_maker - Sell 300 @ 13942.5 2018-01-15 16:31:51,839 - INFO - market_maker - Sell 400 @ 14012.5 2018-01-15 16:31:51,842 - INFO - market_maker - Sell 500 @ 14082.5 2018-01-15 16:31:51,842 - INFO - market_maker - Sell 600 @ 14153.0 2018-01-15 16:31:51,842 - INFO - market_maker - Buy 100 @ 13663.0 2018-01-15 16:31:51,844 - INFO - market_maker - Buy 200 @ 13595.0 2018-01-15 16:31:51,844 - INFO - market_maker - Buy 300 @ 13527.0 2018-01-15 16:31:51,845 - INFO - market_maker - Buy 400 @ 13460.0 2018-01-15 16:31:51,845 - INFO - market_maker - Buy 500 @ 13393.0 2018-01-15 16:31:51,845 - INFO - market_maker - Buy 600 @ 13326.5 2018-01-15 16:31:51,845 - INFO - market_maker - Shutting down. All open orders will be cancelled. 2018-01-15 16:31:51,846 - ERROR - _logging - close status: 31522 2018-01-15 16:31:51,848 - INFO - ws_thread - Websocket Closed

setting.py

from os.path import join import logging

########################################################################################################################

Connection/Auth

########################################################################################################################

API URL.

BASE_URL = "https://testnet.bitmex.com/api/v1/"

BASE_URL = "https://www.bitmex.com/api/v1/" # Once you're ready, uncomment this.

The BitMEX API requires permanent API keys. Go to https://testnet.bitmex.com/api/apiKeys to fill these out.

API_KEY = "WH2ncvk3SyHUV9CWMTuFe48a" API_SECRET = "pmxBrD2iaDvaFFis9sCMbPWT-ckGh2nskevisY52cUWREIIn"

########################################################################################################################

Target

########################################################################################################################

Instrument to market make on BitMEX.

SYMBOL = "XBTUSD"

########################################################################################################################

Order Size & Spread

########################################################################################################################

How many pairs of buy/sell orders to keep open

ORDER_PAIRS = 6

ORDER_START_SIZE will be the number of contracts submitted on level 1

Number of contracts from level 1 to ORDER_PAIRS - 1 will follow the function

[ORDER_START_SIZE + ORDER_STEP_SIZE (Level -1)]

ORDER_START_SIZE = 100 ORDER_STEP_SIZE = 100

Distance between successive orders, as a percentage (example: 0.005 for 0.5%)

INTERVAL = 0.005

Minimum spread to maintain, in percent, between asks & bids

MIN_SPREAD = 0.01

If True, market-maker will place orders just inside the existing spread and work the interval % outwards,

rather than starting in the middle and killing potentially profitable spreads.

MAINTAIN_SPREADS = True

This number defines far much the price of an existing order can be from a desired order before it is amended.

This is useful for avoiding unnecessary calls and maintaining your ratelimits.

#

Further information:

Each order is designed to be (INTERVAL*n)% away from the spread.

If the spread changes and the order has moved outside its bound defined as

abs((desired_order['price'] / order['price']) - 1) > settings.RELIST_INTERVAL)

it will be resubmitted.

#

0.01 == 1%

RELIST_INTERVAL = 0.01

########################################################################################################################

Trading Behavior

########################################################################################################################

Position limits - set to True to activate. Values are in contracts.

If you exceed a position limit, the bot will log and stop quoting that side.

CHECK_POSITION_LIMITS = False MIN_POSITION = -10000 MAX_POSITION = 10000

If True, will only send orders that rest in the book (ExecInst: ParticipateDoNotInitiate).

Use to guarantee a maker rebate.

However -- orders that would have matched immediately will instead cancel, and you may end up with

unexpected delta. Be careful.

POST_ONLY = False

########################################################################################################################

Misc Behavior, Technicals

########################################################################################################################

If true, don't set up any orders, just say what we would do

DRY_RUN = True

DRY_RUN = True

How often to re-check and replace orders.

Generally, it's safe to make this short because we're fetching from websockets. But if too many

order amend/replaces are done, you may hit a ratelimit. If so, email BitMEX if you feel you need a higher limit.

LOOP_INTERVAL = 5

Wait times between orders / errors

API_REST_INTERVAL = 1 API_ERROR_INTERVAL = 10

If we're doing a dry run, use these numbers for BTC balances

DRY_BTC = 50

Available levels: logging.(DEBUG|INFO|WARN|ERROR)

LOG_LEVEL = logging.INFO

To uniquely identify orders placed by this bot, the bot sends a ClOrdID (Client order ID) that is attached

to each order so its source can be identified. This keeps the market maker from cancelling orders that are

manually placed, or orders placed by another bot.

#

If you are running multiple bots on the same symbol, give them unique ORDERID_PREFIXes - otherwise they will

cancel each others' orders.

Max length is 13 characters.

ORDERID_PREFIX = "mmbitmex"

If any of these files (and this file) changes, reload the bot.

WATCHED_FILES = [join("market_maker", f) for f in ["market_maker.py", "bitmex.py", file]]

########################################################################################################################

BitMEX Portfolio

########################################################################################################################

Specify the contracts that you hold. These will be used in portfolio calculations.

CONTRACTS = ['XBTUSD']

bendelo commented 6 years ago

That is the correct behaviour for the configuration you gave it.

dmh181 commented 6 years ago

@bendelo, could you please give more explanation. Thanks!

davidjcooper commented 6 years ago

You set dry run to true. Therefore the bot posts the orders then closes. Set dry run to false.

feysalaf commented 6 years ago

The error most probably is caused by an API which doesn't have the permission to create orders which happens in the case that you select the permission of Order Cancel in the testnet API permissions Change that to order and test it, should work