예제 #1
0
    def place_orders(self) -> None:
        # implement your custom strategy here
        # my strategy
        for i in range(0, 10):
            i += 1
            bitmex_usd = bitmex.BitMEX(base_url=settings.BASE_URL,
                                       symbol="XBTUSD",
                                       apiKey=settings.API_KEY,
                                       apiSecret=settings.API_SECRET,
                                       orderIDPrefix=settings.ORDERID_PREFIX,
                                       postOnly=settings.POST_ONLY,
                                       timeout=settings.TIMEOUT)
            bitmex_u18 = bitmex.BitMEX(base_url=settings.BASE_URL,
                                       symbol="XBTU18",
                                       apiKey=settings.API_KEY,
                                       apiSecret=settings.API_SECRET,
                                       orderIDPrefix=settings.ORDERID_PREFIX,
                                       postOnly=settings.POST_ONLY,
                                       timeout=settings.TIMEOUT)
            buy_orders = []
            sell_orders = []
            # get ticker data
            # ticker data structure ticker = {
            #         "last": instrument['lastPrice'],
            #         "buy": bid,
            #         "sell": ask,
            #         "mid": (bid + ask) / 2
            #     }
            usd_ticker = bitmex_usd.ticker_data()
            u18_ticker = bitmex_u18.ticker_data()
            current_time = datetime.datetime.fromtimestamp(int(time.time()))
            logger.info("datetime: %s, last price of XBTUSD is %.*f" %
                        (current_time, usd_ticker['last']))
            logger.info("last price of XBTU18 is %.*f" % u18_ticker['last'])
            time.sleep(1)
            usd_ticker_after = bitmex_usd.ticker_data()
            u18_ticker_after = bitmex_u18.ticker_data()
            after_datetime = datetime.datetime.fromtimestamp(int(time.time()))
            logger.info("datetime: %s, last price of XBTUSD is %.*f" %
                        (after_datetime, usd_ticker_after['last']))
            logger.info("last price of XBTU18 is %.*f" %
                        u18_ticker_after['last'])
            delta_usd = (usd_ticker_after['last'] -
                         usd_ticker['last']) * 100 / usd_ticker
            delta_u18 = (u18_ticker_after['last'] -
                         u18_ticker['last']) * 100 / u18_ticker
            if (delta_usd - delta_u18) > 5:
                buy_orders.append({
                    'price': u18_ticker_after['sell'],
                    'orderQty': 100,
                    'side': "Buy"
                })

            # populate buy and sell orders, e.g.
            # buy_orders.append({'price': 999.0, 'orderQty': 100, 'side': "Buy"})
            # sell_orders.append({'price': 1001.0, 'orderQty': 100, 'side': "Sell"})

            self.converge_orders(buy_orders, sell_orders)
예제 #2
0
파일: bmbot.py 프로젝트: n1nj4z33/bmbot
 def run(self):
     bm = bitmex.BitMEX(base_url=self.app.lineEdit.text(),
                        apiKey=self.app.lineEdit_2.text(),
                        apiSecret=self.app.lineEdit_3.text(),
                        symbol=self.app.lineEdit_4.text(),
                        orderIDPrefix='')
     self.signal.emit('Жду открытия позиции...')
     while True:
         position = bm.position(self.app.lineEdit_4.text())
         if position['isOpen']:
             quantity = position['currentQty']
             self.signal.emit('Позиция отрылась по цене {}'.format(
                 position['avgEntryPrice']))
             for order in bm.open_orders():
                 self.signal.emit('Отменяю ордер {}'.format(
                     order['orderID']))
                 bm.cancel(order['orderID'])
             if quantity > 0:
                 price = position['avgEntryPrice'] + int(
                     self.app.lineEdit_5.text())
                 self.signal.emit('Продаю по цене {}'.format(price))
                 bm.sell(quantity, price)
                 return
             elif quantity < 0:
                 price = position['avgEntryPrice'] - int(
                     self.app.lineEdit_5.text())
                 self.signal.emit('Покупаю по цене {}'.format(price))
                 bm.buy(-quantity, price)
                 return
         time.sleep(5)
예제 #3
0
 def __init__(self, dry_run=False, settings=None, logger="orders"):
     self.dry_run = dry_run
     # let's only use the symbol from the settings
     #if len(sys.argv) > 1:
     #    self.symbol = sys.argv[1]
     #else:
     #    self.symbol = self.settings.SYMBOL
     self.settings = settings
     self.symbol = self.settings.SYMBOL
     self.exchange_id = 'bitmex'
     if self.settings.BACKTEST:
         self.bitmex = BitMEXbacktest(settings=self.settings)
     else:
         self.bitmex = bitmex.BitMEX(
             base_url=self.settings.BASE_URL,
             symbol=self.symbol,
             apiKey=self.settings.API_KEY,
             apiSecret=self.settings.API_SECRET,
             orderIDPrefix=self.settings.ORDERID_PREFIX,
             postOnly=self.settings.POST_ONLY,
             settings=self.settings,
             timeout=self.settings.TIMEOUT)
     if self.settings.PAPERTRADING:
         self.paper = paper_trading.PaperTrading(settings=self.settings,
                                                 logger=logger)
         self.paper.provide_exchange(self.bitmex)
         self.paper.reset()
     self.orderIDPrefix = self.settings.ORDERID_PREFIX
     self.rate_limit = 1
     self.rate_limit_remaining = 0
     self.last_order_time = None
     self.live_orders = []
     self.cancelled_orders = []
예제 #4
0
 def __init__(self, dry_run=False):
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL, symbol=self.symbol,
                                 apiKey=settings.API_KEY, apiSecret=settings.API_SECRET,
                                 orderIDPrefix=settings.ORDERID_PREFIX, postOnly=settings.POST_ONLY)
예제 #5
0
 def __init__(self, dry_run=False):
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL, symbol=self.symbol, login=settings.LOGIN,
                                 password=settings.PASSWORD, otpToken=settings.OTPTOKEN, apiKey=settings.API_KEY,
                                 apiSecret=settings.API_SECRET, orderIDPrefix=settings.ORDERID_PREFIX)
예제 #6
0
 def __init__(self, dry_run=False, curr_symbol=settings.SYMBOL, api_key=settings.API_KEY, api_secret=settings.API_SECRET):
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = curr_symbol
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL, symbol=self.symbol,
                                 apiKey=api_key, apiSecret=api_secret,
                                 orderIDPrefix=settings.ORDERID_PREFIX, postOnly=settings.POST_ONLY,
                                 timeout=settings.TIMEOUT)
예제 #7
0
 def __init__(self):
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.REAL_BASE_URL, symbol=self.symbol, login=settings.REAL_LOGIN,
                                 password=settings.REAL_PASSWORD, otpToken=settings.OTPTOKEN, apiKey=settings.REAL_API_KEY,
                                 apiSecret=settings.REAL_API_SECRET, orderIDPrefix=settings.REAL_ORDERID_PREFIX, shouldWSAuth=False)
     self.period = settings.BACKTEST_PERIOD
     self.number_per_day = 1440 // self.period
 def __init__(self, dry_run=False):
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL,
                                 symbol=self.symbol,
                                 api_key=settings.API_KEY,
                                 api_secret=settings.API_SECRET,
                                 order_id_prefix=settings.ORDERID_PREFIX,
                                 post_only=settings.POST_ONLY,
                                 timeout=settings.TIMEOUT)
예제 #9
0
 def __init__(self, dry_run=False):
     logger.info("[ExchangeInterface][__init__]")
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL,
                                 symbol=self.symbol,
                                 apiKey=settings.API_KEY,
                                 apiSecret=settings.API_SECRET,
                                 orderIDPrefix=settings.ORDERID_PREFIX,
                                 postOnly=settings.POST_ONLY,
                                 timeout=settings.TIMEOUT)
예제 #10
0
 def __init__(self, dry_run=False):
     print("====main.py start====")
     self.is_change_value = 0
     self.my_elemensts = [self.is_change_value]
     self.dry_run = dry_run
     self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(base_url=settings.BASE_URL,
                                 symbol=self.symbol,
                                 apiKey=settings.API_KEY,
                                 apiSecret=settings.API_SECRET,
                                 orderIDPrefix=settings.ORDERID_PREFIX,
                                 postOnly=settings.POST_ONLY,
                                 timeout=settings.TIMEOUT)
     self.get_indicator = get_indicator.Get_Indicator()
     self.run()
예제 #11
0
 def __init__(self, dry_run=False):
     self.dry_run = dry_run
     if len(sys.argv) > 1:
         self.symbol = sys.argv[1]
     else:
         self.symbol = settings.SYMBOL
     self.bitmex = bitmex.BitMEX(
         base_url=settings.BASE_URL,
         symbol=self.symbol,
         apiKey=settings.API_KEY,
         apiSecret=settings.API_SECRET,
         orderIDPrefix=settings.ORDERID_PREFIX,
         postOnly=settings.POST_ONLY,
         timeout=settings.TIMEOUT,
         n_retries=settings.N_RETRIES,
         retry_delay=settings.RETRY_DELAY
     )
예제 #12
0
    def __init__(self, dry_run=False, **kwargs):
        self.dry_run = dry_run
        self.symbol = kwargs.get('symbol', settings.SYMBOL)
        self.futures_symbol = kwargs.get('futures_symbol',
                                         settings.FUTURES_SYMBOL)

        base_url = kwargs.get('BASE_URL', settings.BITMEX_BASE_URL)
        apiKey = kwargs.get('API_KEY', settings.BITMEX_API_KEY)
        apiSecret = kwargs.get('API_SECRET', settings.BITMEX_API_SECRET)
        orderIDPrefix = kwargs.get('ORDERID_PREFIX', settings.ORDERID_PREFIX)
        postOnly = kwargs.get('POST_ONLY', settings.POST_ONLY)

        logger.info("%s" % self.symbol)
        self.bitmex = bitmex.BitMEX(symbol=self.symbol,
                                    futures_symbol=self.futures_symbol,
                                    base_url=base_url,
                                    apiKey=apiKey,
                                    apiSecret=apiSecret,
                                    orderIDPrefix=orderIDPrefix,
                                    postOnly=postOnly,
                                    timeout=settings.TIMEOUT)
예제 #13
0
    config = {
        # Don't use models (Python classes) instead of dicts for #/definitions/{models}
        'use_models': True,
        # This library has some issues with nullable fields
        'validate_responses': False,
        # Returns response in 2-tuple of (body, response); if False, will only return body
        'also_return_response': False,
    }

    API_KEY = api_keys.bmx_api_key
    API_SECRET = api_keys.bmx_api_secret

    bm = bitmex.BitMEX(base_url='https://www.bitmex.com/api/v1/',
                       symbol='XBTUSD',
                       login=None,
                       password=None,
                       otpToken=None,
                       apiKey=API_KEY,
                       apiSecret=API_SECRET,
                       orderIDPrefix='jose')
else:  # testing stuff
    HOST = "https://testnet.bitmex.com"
    # SPEC_URI = HOST + "/api/explorer/swagger.json"

    # See full config options at http://bravado.readthedocs.io/en/latest/configuration.html
    config = {
        # Don't use models (Python classes) instead of dicts for #/definitions/{models}
        'use_models': True,
        # This library has some issues with nullable fields
        'validate_responses': False,
        # Returns response in 2-tuple of (body, response); if False, will only return body
        'also_return_response': False,
예제 #14
0
import csv
import sys
from datetime import datetime
from market_maker import bitmex
import settings

connector = bitmex.BitMEX(base_url=settings.BASE_URL,
                          symbol=settings.SYMBOL,
                          apiKey=settings.API_KEY,
                          apiSecret=settings.API_SECRET,
                          shouldWSAuth=False)

count = 1  # max API will allow
query = {'reverse': 'true', 'start': 0, 'count': count}

query['symbol'] = settings.SYMBOL

csvwriter = None
preData = None

while True:
    data = connector.ticker_data(symbol=settings.SYMBOL)
    data['timestamp'] = datetime.now()
    data['symbol'] = settings.SYMBOL
    if csvwriter is None:
        csvwriter = csv.DictWriter(sys.stdout, data.keys())
        csvwriter.writeheader()

    if preData is None:
        csvwriter.writerow(data)
        preData = data