Example #1
0
 def test_encode_decode_subgrammar(self):
     H, G, tr_pcfg = self.H, self.G, self.tr_pcfg
     for i in range(10):
         Hprime = tr_pcfg.encode_grammar(G)
         self.assertEqual(len(Hprime), hny_config.HONEY_VAULT_GRAMMAR_SIZE)
         Gprime = tr_pcfg.decode_grammar(Hprime)
         self.assertEqual(Gprime, G, "G and Gprime are not equal.\n" \
                                     "G: {}\nGprime: {}\nDifference: o-n = {}, n-o = {}" \
                          .format(json.dumps(G.G, indent=4), json.dumps(Gprime.G, indent=4),
                                  list(diff(G.G, Gprime.G)), list(diff(Gprime.G, G.G))))
Example #2
0
 def test_encode_decode_subgrammar(self):
     H, G, tr_pcfg = self.H, self.G, self.tr_pcfg
     for i in range(10):
         Hprime = tr_pcfg.encode_grammar(G)
         self.assertEqual(len(Hprime), hny_config.HONEY_VAULT_GRAMMAR_SIZE)
         Gprime = tr_pcfg.decode_grammar(Hprime)
         self.assertEqual(Gprime, G, "G and Gprime are not equal.\n" \
                                     "G: {}\nGprime: {}\nDifference: o-n = {}, n-o = {}" \
                          .format(json.dumps(G.G, indent=4), json.dumps(Gprime.G, indent=4),
                                  list(diff(G.G, Gprime.G)), list(diff(Gprime.G, G.G))))
Example #3
0
 def test_encode_decode_subgrammar(self):
     H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
     tr_pcfg = pcfg.TrainedGrammar()
     G = tr_pcfg.decode_grammar(H)
     for i in range(10):
         Hprime = tr_pcfg.encode_grammar(G)
         Gprime = tr_pcfg.decode_grammar(Hprime)
         self.assertEqual(Gprime, G, "G and Gprime are not equal.\n"\
                          "G: {}\nGprime: {}\Difference: o-n = {}, n-o = {}"\
                          .format(G.nonterminals(), Gprime.nonterminals(),
                                  diff(G, Gprime), diff(Gprime, G)))
Example #4
0
 def test_encode_decode_subgrammar(self):
     H = random.randints(0, MAX_INT, hny_config.HONEY_VAULT_GRAMMAR_SIZE)
     tr_pcfg = pcfg.TrainedGrammar()
     G = tr_pcfg.decode_grammar(H)
     for i in range(10):
         Hprime = tr_pcfg.encode_grammar(G)
         Gprime = tr_pcfg.decode_grammar(Hprime) 
         self.assertEqual(Gprime, G, "G and Gprime are not equal.\n"\
                          "G: {}\nGprime: {}\Difference: o-n = {}, n-o = {}"\
                          .format(G.nonterminals(), Gprime.nonterminals(), 
                                  diff(G, Gprime), diff(Gprime, G)))
Example #5
0
 def checkSellOrder(self):
     sellOrderState = True
     while sellOrderState:
         order = self.checkOrder(self.order['symbol'], self.order['sellID'])
         if (order['status'] == "FILLED"):
             sellOrderState = False
             priceDifference = hlp.diff(self.order['buyPrice'],
                                        order['price'])
             print('[SOLD] Order ID:', self.order['orderID'], '- Ticker:',
                   self.order['symbol'], '- Difference:', priceDifference)
             hlp.addLog('[SOLD] Order ID:' + self.order['orderID'] +
                        '- Ticker:' + self.order['symbol'] +
                        '- Buy price:' + self.order['buyPrice'] +
                        '- Sell Price:' + order['price'] + '- Difference:' +
                        priceDifference)
         time.sleep(10)
     return
Example #6
0
    def run(self):
        sellingState = True
        highestPrice = float(self.order['buyPrice'])

        self.order['sellID'] = self.sellLimit(self.order['symbol'],
                                              self.order['amount'],
                                              self.maxSellPrice)
        while sellingState:
            currentPrice = float(self.getBidPrice(self.order['symbol']))

            priceDifference = hlp.diff(self.order['buyPrice'], currentPrice)

            print(self.order['symbol'], '- Buy price:', self.order['buyPrice'],
                  '- Current price:', currentPrice, '- Min profit price:',
                  self.minSellPrice, '- Difference:', priceDifference)

            if (currentPrice > float(highestPrice)):
                highestPrice = currentPrice

            if ((highestPrice * self.trailDeviation) <= currentPrice
                    and float(self.minSellPrice) <= currentPrice):
                # SELL WITH PROFIT YAY :)
                self.cancelOrder(self.order['symbol'], self.order['sellID'])
                #self.order['sellPrice'] = hlp.formatFloat(currentPrice)
                #self.order['sellID'] = self.sellLimit(self.order['symbol'], self.order['amount'], self.order['sellPrice'])
                self.order['sellID'] = self.sellMarket(self.order['symbol'],
                                                       self.order['amount'])
                self.checkSellOrder(self.order['sellID'])
                sellingState = False

            if (currentPrice <= float(self.stopLossPrice)):
                # CANCEL MAX PROFIT ORDER AND THEN SELL FOR STOP LOSS [RIP MONEY] :(
                self.cancelOrder(self.order['symbol'], self.order['sellID'])
                self.order['sellID'] = self.sellMarket(self.order['symbol'],
                                                       self.order['amount'])
                self.checkSellOrder(self.order['sellID'])
                sellingState = False

            time.sleep(2)
Example #7
0
 def test_diff(self):
     A = {'a': 1, 'b': 3}
     B = {'a': 2, 'c': 3, 'd': {'4': 5}}
     print(list(diff(A, B)))
     print(list(diff(B, A)))
Example #8
0
 def getSpread(self, symbol):
     spread = hlp.diff(self.getBidPrice(symbol), self.getAskPrice(symbol))
     return float(spread)
Example #9
0
 def test_diff(self):
     A = {'a': 1, 'b': 3}
     B = {'a': 2, 'c': 3, 'd':{'4': 5}}
     print list(diff(A, B))
     print list(diff(B, A))