Exemple #1
0
def main():

    coin1 = coin()
    print(coin1)

    coin2 = coin()
    print(coin2)
Exemple #2
0
    def __init__(self, board, l, b):
        screen = board.getscreen()
        self.__o = []
        self.__o.append([["!", " ", " ", " ", " "], [" ", "!", " ", " ", " "],
                         [" ", " ", "!", " ", " "], [" ", " ", " ", "!", " "],
                         [" ", " ", " ", " ", "!"]])
        self.__o.append([[" ", " ", "!", " ", " "], [" ", " ", "!", " ", " "],
                         [" ", " ", "!", " ", " "], [" ", " ", "!", " ", " "],
                         [" ", " ", "!", " ", " "]])
        self.__o.append([[" ", " ", " ", " ", " "], [" ", " ", " ", " ", " "],
                         ["!", "!", "!", "!", "!"], [" ", " ", " ", " ", " "],
                         [" ", " ", " ", " ", " "]])
        self.__o.append([["m", "a", "g"]])
        self.__o.append([["S"]])
        self.__beams = []
        self.__coins = []
        self.__magnet = []
        self.__speed = []

        start = 20
        while start < b - 100:
            loc = random.randint(3, l - 7)
            self.__coins.append(coin(screen, loc, start))
            start = start + random.randint(8, 12)
        start = 20
        while start < b - 100:
            obst = self.__o[random.randint(0, 2)]
            loc = random.randint(3, l - 7)
            self.__beams.append(beam(screen, loc, start, obst))
            start = start + random.randint(20, 40)
        start = 20
        board.setscreen(screen)
def initialize_coins():
    coins=[]

    # gives a dictionary which coin name as key and price as value
    prices = binance.prices()
    coinNames = list(prices.keys())
    for c in coinNames:
        # Create coin and add starting price
        tmpcoin = coin(c)
        tmpcoin.add_price(prices.get(c))
        coins.append(tmpcoin)
    return coins
def main():
    heads, tails = 0, 0

    for i in range(1000):
        new_coin = coin.coin(random.choice(['heads', 'tails']))
        toss_res = new_coin.toss()
        if toss_res == 'heads':
            heads += 1
        else:
            tails += 1

    print("Percentage of heads:", heads / 10)
    print("Percentage of tails:", tails / 10)
def run():
    try:
        count = 0
        overcount = 0

        #create coins
        btc = coin('bitcoin')
        eth = coin('ethereum')
        tron = coin('tron')
        rip = coin('ripple')
        iota = coin('iota')
        #populate dataset and add metrics when necessary
        cryptos_array = [btc, eth, tron, rip, iota]

        while overcount < 10000:

            for x in cryptos_array:
                x.main()
                count = count + 1
                if count % 500 == 0:
                    for z in cryptos_array:
                        z.advanceOptiuon()

        # ensure program is actually alive
            overcount = overcount + 1
        #    print(overcount)
        #client login issue

        # if overcount % 100 == 0:
        #     for n in cryptos_array:
        #         print(n.tally())
    except (gspread.exceptions.AuthenticationError, gspread.GSpreadException,
            gspread.exceptions.GSpreadException, gspread.RequestError,
            gspread.exceptions.RequestError):
        pass
    finally:
        fail_time = time.time() - last_time
        print("it took this many seconds to fail: " + str(fail_time))
        run()
Exemple #6
0
from coin import coin
import cpdb
import decision_maker as dm
''' Main driver class of the entire project, currently limited to the fact that 
    suitable data was only available for btc and eth, but will expand'''
''' Keep in note that this implementation requires Python 3.6.4+ and R 3.3 
    as well as required libraries in each language, I am working on a docker container
    to make this accessible on other machines when I can get high-degress of profit 
    on my own implementation.
    Currently, btc and eth remain profitable, despite current trends.
    '''

btc = coin('btc')
eth = coin('eth')
coins = ['btc', 'eth']

agenda = [btc, eth]
count = 0
n = 1000
''' Simple driver to perpetually run program and every n updates, retrain'''
while True:
    for c in agenda:
        c.feature_maker()
        count += 0.5
        if count % n == 0:
            c.portfolio.get_portfolio_value()
            for s in coins:
                dm.incremental_training(cpdb.retrieve(n))
Exemple #7
0
    def handle_message(self, message, bot_handler):
        content = False
        text = message['content']

        # detects help message
        if "help" in text:
            content = """
Name: Randy
Synopsis:
{curly braces define optional input}
------------
Coin; @randy {<times> }c{oins weight <heads>:<tails>:<clumsy>}
Examples; long:- `@randy 20 coin weight 20:10:30`, short:- `@randy 20cw2:1:3`
------------
Dice; @randy {<times> }d{ice <faces>,<stop>,<step> weight <number> <load>:<rest>:<clumsy> <operand>}
Examples; long:- `@randy 20 dice 16,24,2 weight 16 20:10:30 +89`, short:- `@randy 20d16,24,2w16 20:10:30+89`
------------
Times - the number of times the action will be performed, with dice all results will be automatically accumulated and a final result given.
Coin - the command used to define a coin flip.
Dice - the command used to define a dice roll.
Faces - the number of faces you want the die to have, becomes dice start value when stop and step are defined, with a default of 1.
Stop - defines what number to stop at when deciding the size of the dice. Both start and stop are inclusive so put the number you would expect on the dice.
Step - defines what the increments on the dice should be.
Weight - the command given to inform that you wish to edit the weightings.
Number - the number on the dice you wish to load. This must be followed by a space and then the ratio else it will default to 2:1.
Heads - the weighting you wish heads to have. Weightings should be integer ratios, larger numbers mean it is more likely lower is less likely.
Load - the weighting you wish the load number to have.
Tails - the weighting you wish tails to have.
Rest - the weighting you wish the rest of the numbers to have.
Clumsy - this is a weighting with a default of 0 that allows the potential for the item to be lost during operation.
Operand - this defines an operand  `+`, `-`, `/`, or `*` that you can perform upon the accumulated dice rolls. This is mostly useful for applying buffs or debuffs.
"""

        # prints purpose
        elif "purpose" in text:
            content = "My purpose is as a random item generator, I provide coin flips and dice rolls upon request, try `help` to to learn my commands."

        # responds to null input so you can check it's listening
        elif text == "" or text == "?":
            content = "yes?"

        else:
            command = expression.expression()
            matches = command.get_message(text)
            if matches == None:
                matches = []

            # detects coin input
            if len(matches) == 4:
                times = test.test(matches[0])
                heads = test.test(matches[1])
                tails = test.test(matches[2])
                clumsy = test.test(matches[3])
                operand = ""
                item = coin.coin()
                results = item.parseCoin(times, heads, tails, clumsy)
                slug = "You flipped a coin " + str(
                    times.value) + " times, the result was:\n"

            # detects dice input
            elif len(matches) == 10:
                times = test.test(matches[0])
                faces = test.test(matches[1])
                stop = test.test(matches[2])
                step = test.test(matches[3])
                number = test.test(matches[4])
                load = test.test(matches[5])
                rest = test.test(matches[6])
                clumsy = test.test(matches[7])
                operand = matches[8]
                value = test.test(matches[9])
                try:
                    if stop.value is None:
                        faces.ifExists(6)
                        item = die.createSimpleDie(faces.value)
                    else:
                        faces.ifExists(1)
                        stop.ifExists(6)
                        step.ifExists(1)
                        item = die.die(faces.value, stop.value, step.value)
                except TypeError as error:
                    content = str(error)
                else:
                    try:
                        results = item.parseDice(times, faces, number, load,
                                                 rest, clumsy)
                    except TypeError as error:
                        content = str(error)
                    else:
                        slug = "You rolled a D" + str(len(
                            item.weights.keys())) + " " + str(
                                times.value) + " times, the result was:\n"

            # catches any other kind of input
            else:
                content = "I'm sorry what was that? I don't understand.\nType `help` to see the commands I know."

            # parses output in message friendly way
            if content == False:
                content = ""
                acc = 0
                for item in results:
                    if isinstance(item, int):
                        acc += item
                    content += ", " + str(item)
                content = content[2:]
                content = slug + content
                if operand is None and len(matches) == 10:
                    content += " = " + str(acc)
                elif operand is not None and len(operand) != 0:
                    value.ifExists(1)
                    try:
                        if operand == "+":
                            acc += value.value
                        elif operand == "-":
                            acc -= value.value
                        elif operand == "*":
                            acc *= value.value
                        elif operand == "/":
                            acc /= value.value
                    except ZeroDivisionError:
                        content = "divide by zero? how dumb do you think I am?!"
                    else:
                        content += " " + operand + " " + str(
                            value.value) + " = " + str(acc)

        # sends completed message and ends
        bot_handler.send_reply(message, content)
        return
Exemple #8
0
# main_A_1.py

import dice, coin, game

# data
myID = 15 % 3
k = myID * 2 + 3

N = 2
pt = myID + 1
dice_prob = 0.15
coin_prob = 0.5

coin_num = coin.coin(coin_prob)

times = 0

# Who wins?
while times < k:
    times += 1
    print(str(times) + ". ")
    pc = dice.multi_dice(N, pt, dice_prob, myID)
    player = dice.multi_dice(N, pt, dice_prob, myID)
    if game.show(pc, player, coin_num):
        break
Exemple #9
0
import coin
num = int(input('digite um numero: '))
print('aumentar 10% = {}'.format(coin.coin(coin.increase(num))))
print('diminuir 10% = {}'.format(coin.coin(coin.decrease(num))))
print('metade = {}'.format(coin.coin(coin.half(num))))
print('dobro = {}'.format(coin.coin(coin.double(num))))
Exemple #10
0
    def render(self):

        os.system('clear')
        self.createBox()

        # setup initial state
        character=boy(self._width,self._height,time.time())
        self._charac=character
        self.writeObject(character,character)
        enemy=boss(4,900)
        self._en=enemy
        self.writeObject(enemy,character)
        
        for i in range(5):
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(30,230)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(230,430)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(430,630)))
            self._beamsVertical.append(beamVertical(random.randint(2,25),random.randint(630,830)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(30,230)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(230,430)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(430,630)))
            self._beamsHorizontal.append(beamHorizontal(random.randint(2,29),random.randint(630,830)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(30,230)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(230,430)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(430,630)))
            self._beamsDiagnol.append(beamDiagnol(random.randint(2,25),random.randint(630,830)))
            self._coins.append(coin(random.randint(2,28),random.randint(30,330)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(330,530)))
            self._coins.append(coin(random.randint(2,28),random.randint(530,830)))
            self._magnets.append(magnet(random.randint(2,29),random.randint(30,430)))                      
            self._magnets.append(magnet(random.randint(2,29),random.randint(430,830)))          


        # wirte initial state
        for i in self._beamsVertical:
            self.writeObject(i,character)
        for i in self._beamsHorizontal:
            self.writeObject(i,character)
        for i in self._beamsDiagnol:
            self.writeObject(i,character)
        for i in self._coins:
            self.writeObject(i,character)
        for i in self._magnets:
            self.writeObject(i,character)

        x=time.time()
        y=x
        enemy_time=x
        distToMagnet=[self._width+ self._height,-1,-1]
        while True:

            if time.time()-x > self._speed[0]:
                # update beams , coins , bullets
                for i in self._beamsVertical:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._beamsHorizontal:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._beamsDiagnol:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._coins:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._bullets:
                    self.removeObject(i)
                    i.write()
                    self.writeObject(i,character)
                for i in self._snowBalls:
                    self.removeObject(i)
                    i.write(enemy.lives)
                    self.writeObject(i,character)
                for i in self._magnets:
                    self.removeObject(i)
                    i.write()
                    if abs(i.position20()-character.position40())+abs(i.position21()-character.position41()) < distToMagnet[0]:
                        distToMagnet[0]=abs(i.position20()-character.position40())+abs(i.position21()-character.position41())
                        distToMagnet[1]=i.position20()
                        distToMagnet[2]=i.position21()
                    self.writeObject(i,character)
                # update characeter
                if distToMagnet[0]>15:
                    self.removeObject(character)
                    character.down()
                    self.writeObject(character,character)
                else:
                    self.removeObject(character)
                    character.towardsMagnet(distToMagnet[1],distToMagnet[2])
                    distToMagnet=[self._width+ self._height,-1,-1]
                    self.writeObject(character,character)

                

                x=time.time()
                if enemy.position01()>self._width-20:
                    self.removeObject(enemy)
                    enemy.write_right()
                    self.writeObject(enemy,character)
                    enemy.defense=1
                elif  x - enemy_time > 0.5:
                    if enemy.defense>0:
                        enemy.defense-=1
                    enemy_time=x
                    self.removeObject(enemy)
                    enemy.write_up_down(character.position30())
                    if character.position30() >= enemy.position00()+6 and character.position30() <= enemy.position00()+15:
                        self._snowBalls.append(snowBall(character.position30(),enemy.position01()-30))
                    elif character.position30() > enemy.position00()+15:
                        self._snowBalls.append(snowBall(enemy.position00()+12,enemy.position01()-30))
                    elif character.position30() < enemy.position00()+6:
                        self._snowBalls.append(snowBall(enemy.position00()+7,enemy.position01()-30))
                    self.writeObject(enemy,character)

                if x-character.lastTime() > 10 and x- character.liveLost() > 3:
                    character.deactivateShield()
                if self._speed[2]==1 and x-self._speed[1] > 10:
                    self._speed[0]=0.1
                self._timeLeft=int(140-(x-y))
                if 140-(x-y) < 0:
                    self.quitX()

                print(Fore.WHITE,"\033[2;2HLive:"+str(character.lives)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;10HScore:"+str(character.score)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;20HShield:"+str(int(x-character.lastTime()))+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;32HBoss:"+str(enemy.lives)+"  ",end='')
                print("\033[30;1H")
                print(Fore.WHITE,"\033[2;42HTime Remaining:"+str(int(140-(x-y)))+"  ",end='')
                print("\033[30;1H")

                self.write()
            self.detectKey(character)    
        return True
Exemple #11
0
    commented in and out. On Github, I will leave all code uncommented
    as this portion of code has zero bearing to my actual program besides
    serving as record of exactly how I created my initial model'''
import pandas as pd
from pathlib import Path
from coin import coin
import pickle

from sklearn.model_selection import train_test_split
from sklearn.preprocessing import Imputer
from xgboost import XGBClassifier
from sklearn.metrics import zero_one_loss
from sklearn.pipeline import Pipeline
from sklearn.model_selection import GridSearchCV
''' Initial data gathered from gemini (free) '''
c = coin('train')
btc_file_path = Path("D:/btc.csv")
eth_file_path = Path("D:/eth.csv")

btc_dat = pd.read_csv(btc_file_path)
eth_dat = pd.read_csv(eth_file_path)

btc_dat = btc_dat.head(100000)
eth_dat = eth_dat.head(100000)

btc_prices = btc_dat.Open
eth_prices = eth_dat.Open

btc_features = []
eth_features = []
btc_labels = []
def main():
    try:
        print("\n>> CoinAnalyze v0.7 by cloud <<\n\n")
        sendMessageTelegram("Coin Analyzer Bot v0.7 Started")

        ##### TRADE MODULE#######
        trading = 0
        tr = trade()
        if trading == 1:
            print("Trading module : On")
            sendMessageTelegram("Trading module : On")
            end = 0
        else:
            print("Trading module : Off")
            sendMessageTelegram("Trading module : Off")

        #########################
        #We initialize the different timer
        timer1hnext = (datetime.now() + timedelta(seconds=3600)).hour
        timer20mnnext = (datetime.now() + timedelta(seconds=60))
        while (int(str(timer20mnnext.minute)) % 20) != 0:
            timer20mnnext = timer20mnnext + timedelta(seconds=60)
        market = coinmarketcap()
        binancecoin = binance()
        listcoin = []
        ticker = {}
        ticker = binancecoin.checkTicker()

        symbol = binancecoin.getListSymbol(ticker)

        #We create an object by coin
        for c in symbol:
            coinC = coin(c)
            listcoin.append(coinC)

        while True:
            time.sleep(1)
            timer = datetime.now()

            ####### EVERY 1H ###############

            if timer.hour == timer1hnext:
                print(timer)

                if trading == 1:
                    msg = tr.summaryTrade()
                    print(msg)
                    sendMessageTelegram(msg)
                timer1hnext = (datetime.now() + timedelta(seconds=3600)).hour

                ### We check General coinmarketcap every 60mn

                market.checkGlobal()
                checkmarket = market.analyze_total_market_cap_eur()

                #Analyze Market
                msg = ""
                msg = msg + printcheckmarket(market, checkmarket)
                msg = msg + "\n"

                checkmarket = market.analyze_bitcoin_percentage_of_market_cap()
                msg = msg + printbtcdominance(market, checkmarket)

                print(msg)
                sendMessageTelegram(msg)
                msg = ""

            ####### EVERY 20mn ###############
            ## New Symbol check
            timer20mn = datetime.now()
            period = ['1h', '4h', '1d']

            if ((int(timer20mn.minute) % 20) == 0) and (timer20mnnext.minute
                                                        == timer20mn.minute):
                #if 1 == 1:
                if trading == 1:
                    period = ['1h', '4h', '1d']
                timer20mnnext = (datetime.now() + timedelta(seconds=12000))
                ####### ACTION ###################
                for p in period:

                    msg = ""

                    #On récupère les infos de chaque coin sur une période de 252 et on les ajoute à chaque coin pour gérer les alertes
                    listAllValues = []
                    listAllValues = binancecoin.checkAllInfoValues(p)

                    for c in listAllValues:
                        for x in listcoin:
                            end, msg = tr.checkEndTrade()

                            if end == 1:
                                print(msg)
                                sendMessageTelegram(msg)
                                trading = 0
                                period = ['4h', '1d']
                            if c['symbol'] == x.getSymbol():
                                x.setValues(c)
                                if trading == 1:
                                    stoploss = tr.stopLoss(x)
                                    if stoploss == 1:
                                        msg = "STOP LOSS (5%) for " + x.getSymbol(
                                        )
                                        print(msg)
                                        sendMessageTelegram(msg)

                                if p != '1h':
                                    #RSI must be the first test to set RSI for the PRS test
                                    #RSI alert check
                                    rsi = x.rsiAlert(p)
                                    if rsi != 0:
                                        msg = printRSIAlert(
                                            x.getSymbol(), rsi, p)
                                        print(msg)
                                        #sendMessageTelegram(msg)
                                        msg = ""

                                    #RSI DIV Alert
                                    rsidiv, price = x.rsiDivAlert(p)
                                    if rsidiv != 0:
                                        msg = msg + printRSIDIVAlert(
                                            x.getSymbol(), rsidiv, p, price)
                                        print(msg)
                                        sendMessageTelegram(msg)
                                        msg = ""
                                        #if trading == 1:
                                        #	restrade,msg = tr.buysell(rsidiv, x.getSymbol(), price)
                                        #	print msg
                                        #	sendMessageTelegram(msg)

                                    #MACD alert check
                                    macd, price = x.macdAlert(p)
                                    if macd != 0:
                                        msg = printMACDAlert(
                                            x.getSymbol(), macd, p, price)
                                        print(msg)
                                        #sendMessageTelegram(msg)
                                        msg = ""

                                    #PRS Alert
                                    prs, price = x.prsAlert(p)
                                    if prs != 0:
                                        msg = printAlert(
                                            "PRS", x.getSymbol(), prs, p,
                                            price)
                                        print(msg)
                                        #sendMessageTelegram(msg)
                                        msg = ""
                                        #if trading == 1:
                                        #	restrade,msg = tr.buysell(prs, x.getSymbol(), price)
                                        #	print msg
                                        #	sendMessageTelegram(msg)

                                    #Nightou Alert
                                    nightou, price = x.nightouAlert(p)
                                    if nightou != 0:
                                        msg = msg + printNightouAlert(
                                            x.getSymbol(), p, price)
                                        print(msg)
                                        sendMessageTelegram(msg)
                                        msg = ""
                                        if trading == 1:
                                            restrade, msg = tr.buysell(
                                                nightou, x.getSymbol(), price)
                                            print(msg)
                                            sendMessageTelegram(msg)

                                    #ADX Alert
                                    adx, price = x.adxAlert(p)
                                    if adx != 0:
                                        msg = msg + printAlert(
                                            "ADX", x.getSymbol(), adx, p,
                                            price)
                                        print(msg)
                                        #sendMessageTelegram(msg)
                                        msg = ""
                                        #if trading == 1:
                                        #	restrade,msg = tr.buysell(adx, x.getSymbol(), price)
                                        #	print msg
                                        #	sendMessageTelegram(msg)

                                    #CCI Alert
                                    cci, price = x.cciAlert(p)
                                    if cci != 0:
                                        msg = msg + printAlert(
                                            "CCI", x.getSymbol(), cci, p,
                                            price)
                                        print(msg)
                                        #sendMessageTelegram(msg)
                                        msg = ""
                                        #if trading == 1:
                                        #	restrade,msg = tr.buysell(cci, x.getSymbol(), price)
                                        #	print msg
                                        #	sendMessageTelegram(msg)

                                    #CLOUD Alert
                                    cloud, price = x.cloudStrategy(p)
                                    if cloud != 0:
                                        msg = msg + printAlert(
                                            "CLOUD", x.getSymbol(), cloud, p,
                                            price)
                                        print(msg)
                                        sendMessageTelegram(msg)
                                        msg = ""
                                        if trading == 1:
                                            restrade, msg = tr.buysell(
                                                cloud, x.getSymbol(), price)
                                            print(msg)
                                            sendMessageTelegram(msg)

                                #EMA Alert
                                ema, price = x.emaStrategy(p)
                                if ema != 0:
                                    msg = msg + printAlert(
                                        "EMA", x.getSymbol(), ema, p, price)
                                    print(msg)
                                    sendMessageTelegram(msg)
                                    msg = ""
                                    if trading == 1:
                                        restrade, msg = tr.buysell(
                                            ema, x.getSymbol(), price)
                                        print(msg)
                                        sendMessageTelegram(msg)

                ####### NEW SYMBOL #########
                ticker = binancecoin.checkTicker()
                newsymbol = []
                newsymbol = binancecoin.getNewSymbol()
                for c in newsymbol:
                    coinC = coin(c)
                    listcoin.append(coinC)

                msg = printNewSymbol(newsymbol)
                if msg != "":
                    sendMessageTelegram(msg)
                    print(msg)

    except (KeyboardInterrupt, SystemExit):
        sendMessageTelegram("Maintenance, I'll be back soon")
    return 0