Exemplo n.º 1
0
    def __init__(self, params):

        self.high = params['high']
        self.vp  = params['vp']

        self.qt = QuantTrader(self.high)

        self.parameters = {
            'symbol': params['symbol'],
            'price': self.high[-1]
        }
Exemplo n.º 2
0
 def operation(self, high):
     """
     framework functions that will always
     run no matter what strategy is being called
     """
     logging.info('-- Starting Defualt Operations --')
     logging.info('-- Checking Price Jump --')
     QuantTrader(high, 'TSLA').price_jump(ref='pj')
Exemplo n.º 3
0
    def build_strategy(self):

        print(
            'Welcome to the SlowBull, its a quiet day but we see overall growth'
        )
        logging.info(
            'Welcome to the SlowBull, its a quiet day but we see overall growth'
        )
        QuantTrader(self.high, 'TSLA').Volatility(self.vp)
Exemplo n.º 4
0
def onn_open(ws):
    global strm, back_log, ticker

    print('Connecting')
    strm.connection_log('Connecting')
    try:
        BackLog = QuantTrader(ticker, price=0, profit=0)
        back_log = BackLog.Back_logger()
        strm.log('Back Log Success')
    except:
        strm.log('Back log failed')

    auth_data = {"action": "auth", "params": API_KEY}
    ws.send(json.dumps(auth_data))
    channel_data = {"action": "subscribe", "params": "AM.TSLA"}
    ws.send(json.dumps(channel_data))

    print("Connected")
    strm.connection_log('Connected at %s' % (strm.localize_time()))
    strm.log('Connected at %s' % (strm.localize_time()))
Exemplo n.º 5
0
class Strategy(ABC):
    """
    Strategy interface declares all the operation that all the concrete products
    must implement
    """

    def __init__(self, params):

        self.high = params['high']
        self.vp  = params['vp']

        self.qt = QuantTrader(self.high)

        self.parameters = {
            'symbol': params['symbol'],
            'price': self.high[-1]
        }

    @abstractmethod
    def build_strategy(self):
        pass

    def operation(self):
        """
        framework functions that will always
        run no matter what strategy is being called
        """

        status = self.qt.price_jump()
        print(status)
        if status:
            self.parameters['ref'] = 'pj'
            order = order_factory.get_order(self.parameters)
            order.build_order()
            order.show_order()
            order.send_order()

    def run(self):

        logging.info('-- Building Strategy --')
        self.build_strategy()
        self.operation()
Exemplo n.º 6
0
 def build_strategy(self):
     print('Welcome to raging bull where we got chronic volatitlity')
     QuantTrader(self.high, 'TSLA').stop_drop_and_roll(ref='sdrws')
Exemplo n.º 7
0
 def build_strategy(self):
     print(
         'Welcome to GrizzlyBear where we got chronic volatitlity, and falling fast'
     )
     QuantTrader(self.high, 'TSLA').climb_the_ladder(ref='ctlws')
Exemplo n.º 8
0
def on_message(ws, message):
    global strm, back_log

    # ======================================================
    #          GENERIC  INFORMATION

    # ------    DO Not edit this     ------
    strm.previous_tick = strm.current_tick
    message = a.clean_and_load(message)
    strm.current_tick = json.loads(
        message)  # strm.current_tick is the manipulatable data
    # ---------------------------------------
    latest_candle = strm.candle_builder(
    )  # Handling of stream data --> into candles
    if latest_candle == None:
        return

# =======================================================
#         START STRATEGY HERE

    qt = QuantTrader(ticker, strm._high, profit=strm.profit)

    position = a.get_position_for(qt.ticker.upper())
    account = a.get_account()
    buying_power = account['buying_power'].split('.')[0]

    # =======================================================
    #               Back log volatility buy
    # =======================================================
    if back_log != None:
        back_log = qt.Back_logger()
        back_log_order = qt.Back_log_volatility(back_log)
        print(f'Back log is :{back_log_order}')
        back_log = None
        pass
# =======================================================

    strm.log('-- Running Strategies --')
    strm.log(f'Stream VP : {round(strm.vp,ndigits=3)}')

    # WITH NOT POSITION
    if not position:
        strm.log('There are no shares for %s' % qt.ticker)

        # Running sma1
        qt.Volatility(volatility=strm.vp, ref='sma1', parameter=1)

        # Checking chronic volatility
        if strm.rolling_v_10 != None and strm.rolling_v_10 > .5:
            qt.stop_drop_and_roll(ref='sdr')
            qt.climb_the_ladder(ref='ctl')

        # Checking for sudden increase in price
        if strm.rolling_high_30 != None:
            qt.price_jump(ref='pj')

# WITH A POSITION
    else:

        # ============   Grabbing Share Information   ============
        si = a.share_info(qt.ticker.upper())
        # =======================================================

        strm.log('%s Shares of %s @ avg_cost: %s' %
                 (si['qty_pos'], qt.ticker.upper(), si['avg_price']))
        print(f'stream vp : {strm.vp}')

        # Running sma1 -- PERFECT
        qt.Volatility(volatility=strm.vp, ref='sma1ws', parameter=1)

        # Checking chronic volatility
        if strm.rolling_v_10 != None and strm.rolling_v_10 > .5:
            strm.log('Chronic Volatility')
            qt.stop_drop_and_roll(ref='sdrws')
            qt.climb_the_ladder(ref='ctlws')

        # Checking for sudden increase in price
        if strm.rolling_high_30 != None:
            qt.price_jump(ref='pjws')

# THis works for both

    if strm.rolling_v_10 != None:
        if strm.vp > 1 and strm.rolling_v_10 > .5:
            strm.log('DT')
            strm.log(
                f'Double standard SMA_1: {strm.vp} roll: {strm.rolling_v_10}\n'
            )
            return

# =======================================================
#               OUTRO
# =======================================================

    try:
        positions = a.get_position()
        open_orders = a.get_orders()

        strm.log(f'Number Of Positions Held ::{len(positions)}')
        strm.log(f'Open orders: {len(open_orders)}\n  '
                 f'---------------------------------------------\n')

        print(f'Number Of Positions Held :: {len(positions)}')
        print(f'Open orders: {len(open_orders)}\n'
              f' ---------------------------------------------\n')
    except:
        # loop only used for the collapsing ability
        pass