Пример #1
0
 def get_quoteBucketed(self, symbol=None, count=settings.BUFFER):
     """
     OUTDATED ---> REMOVE THIS METHOD
     """
     logger.info("get_quoteBucketed is outdated, should not be used")
     """
     """
     if symbol is None:
         symbol = self.symbol
     try:
         # quote = self.bitmex.Quote.Quote_getBucketed(symbol=symbol, reverse=False, binSize=settings.TIMEFRAME, count=settings.BUFFER, partial=False).result()[0]
         quote = self.bitmex.Quote.Quote_getBucketed(
             symbol=symbol,
             reverse=True,
             binSize=settings.TIMEFRAME,
             count=count,
             partial=False).result()[0]
         if quote is None:
             raise errors.MarketEmptyError("Quote is empty")
         # logger.info("QuoteBucketed correctly imported")
         return quote
     except:
         logger.info(
             "Connection error. Couldn't retrive 'quoteBucketed'. Sleeping..."
         )
         sleep(settings.LOOP_INTERVAL)
         self.get_quoteBucketed()
Пример #2
0
    def check_if_orderbook_empty(self):
        """This function checks whether the order book is empty"""
        instrument = self.get_instrument()

        if instrument['midPrice'] is None:
            raise errors.MarketEmptyError("Orderbook is empty, cannot quote")

        return instrument
Пример #3
0
 def get_simpleCost(self, symbol=None):
     if symbol is None:
         symbol = self.symbol
     try:
         position = self.get_position(symbol)
         if position is None:
             raise errors.MarketEmptyError("Couldn't get simplecost")
         simpleCost = position['simpleCost']
         return simpleCost
     except:
         logger.info(
             "Connection error. Couldn't retrive 'simple_cost'. Sleeping..."
         )
         sleep(settings.LOOP_INTERVAL)
         self.get_simpleCost()
Пример #4
0
 def get_margin(self):
     """
     Margin is the amount of equity expressed in XBT
     """
     logger.info(
         "DEPRECATED FUNCTION USE GET_LATEST_QUOTE TO RETURN A DF !!!!")
     if self.dry_run:
         return {
             'marginBalance': float(settings.DRY_BTC),
             'availableFunds': float(settings.DRY_BTC)
         }
     try:
         margin_balance = self.bitmex.User.User_getMargin(
             currency='XBt').result()[0]['marginBalance']
         if margin_balance:
             margin_in_XBT = self.XBt_to_XBT(margin_balance)
             # logger.info("Imported margin")
             return margin_in_XBT
         else:
             raise errors.MarketEmptyError("Margin is empty")
     except:
         sleep(settings.LOOP_INTERVAL)
         self.get_margin()
Пример #5
0
 def check_if_orderbook_empty(self):
     logger.info("[ExchangeInterface][check_if_orderbook_empty]")
     """This function checks whether the order book is empty"""
     instrument = self.get_instrument()
     if instrument['midPrice'] is None:
         raise errors.MarketEmptyError("Orderbook is empty, cannot quote")
Пример #6
0
    def get_position(self, symbol=None):
        """
        simpleCost is expressed in USD
        currentQty is expressed in XBT

        "account": 25306,
        "commission": 0.00075,
        "initMarginReq": 0.3333333333333333,
        "maintMarginReq": 0.005,
        "riskLimit": 20000000000,
        "leverage": 3,
        "crossMargin": false,
        "deleveragePercentile": 1,
        "rebalancedPnl": 23624,
        "prevRealisedPnl": -272,
        "prevUnrealisedPnl": 0,
        "prevClosePrice": 10631.26,
        "openingTimestamp": "2018-03-08T00:00:00.000Z",
        "openingQty": 0,
        "openingCost": 30870,
        "openingComm": -11599,
        "openOrderBuyQty": 0,
        "openOrderBuyCost": 0,
        "openOrderBuyPremium": 0,
        "openOrderSellQty": 0,
        "openOrderSellCost": 0,
        "openOrderSellPremium": 0,
        "execBuyQty": 180,
        "execBuyCost": 1793670,
        "execSellQty": 150,
        "execSellCost": 1499190,
        "execQty": 30,
        "execCost": -294480,
        "execComm": -221,
        "currentTimestamp": "2018-03-08T01:34:51.019Z",
        "currentQty": 30,
        "currentCost": -263610,
        "currentComm": -11820,
        "realisedCost": 35370,
        "unrealisedCost": -298980,
        "grossOpenCost": 0,
        "grossOpenPremium": 0,
        "grossExecCost": 298945,
        "isOpen": true,
        "markPrice": 9976.27,
        "markValue": -300720,
        "riskValue": 300720,
        "homeNotional": 0.0030072,
        "foreignNotional": -30,
        "posState": "",
        "posCost": -298980,
        "posCost2": -298980,
        "posCross": 0,
        "posInit": 99660,
        "posComm": 299,
        "posLoss": 0,
        "posMargin": 99959,
        "posMaint": 2916,
        "posAllowance": 0,
        "taxableMargin": 0,
        "initMargin": 0,
        "maintMargin": 98219,
        "sessionMargin": 0,
        "targetExcessMargin": 0,
        "varMargin": 0,
        "realisedGrossPnl": -35370,
        "realisedTax": 0,
        "realisedPnl": -23550,
        "unrealisedGrossPnl": -1740,
        "longBankrupt": 0,
        "shortBankrupt": 0,
        "taxBase": 0,
        "indicativeTaxRate": 0,
        "indicativeTax": 0,
        "unrealisedTax": 0,
        "unrealisedPnl": -1740,
        "unrealisedPnlPcnt": -0.0058,
        "unrealisedRoePcnt": -0.0175,
        "simpleQty": 0.003,
        "simpleCost": 30,
        "simpleValue": 30,
        "simplePnl": 0,
        "simplePnlPcnt": 0,
        "avgCostPrice": 10034,
        "avgEntryPrice": 10034,
        "breakEvenPrice": 10032.5,
        "marginCallPrice": 7576,
        "liquidationPrice": 7576,
        "bankruptPrice": 7526,
        "timestamp": "2018-03-08T01:34:51.019Z",
        "lastPrice": 9976.27,
        "lastValue": -300720
        
"""
        if symbol is None:
            symbol = self.symbol
        try:
            position = self.bitmex.Position.Position_get(
                filter=json.dumps({'symbol': symbol})).result()[0][0]
            if position is None:
                raise errors.MarketEmptyError("Position is empty")
            # logger.info("Position correctly imported")
            # print(position)
            return position
        except:
            logger.info(
                "Connection error. Couldn't retrive 'position'. Sleeping...")
            sleep(settings.LOOP_INTERVAL)
            self.get_position()