Example #1
0
def get_fee_info():
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    try:
        ret = json.dumps(api.get_myfee)
    except Exception as err:
       print('Error: '+ str(err))
    else:
       print(ret)
Example #2
0
def tick(pair):
    try:
        pair = str(pair)
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
        data = json.dumps(api.ticker(pair))
        print(data)
    except Exception as err:
        print("Error: %s" % err)
        return False
Example #3
0
def get_deposit_addresses_(currency):
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    try:
        ret = api.get_deposit_addresses(currency)
    except Exception as err:
       print('Error: ' + str(err))
    else:
       #ret = json.loads(ret)
       print(ret)
Example #4
0
def cancel_order_(order_id):
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    try:
        ret = api.cancel_order(str(order_id))
    except Exception as er:
        print(er)
        return False
    else:
        return("Success")
Example #5
0
def valid_pair(pair):
    try:
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
        last = json.dumps(api.ticker(pair)['last'])
    except Exception as err:
        print("Valid pair: %s" %err)
        return False
    else:
        return True
Example #6
0
def convert_price(amount,pair):
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    #amount = float(amount)
    #pair = str(pair)
    try:
        ret = api.convert(amount,pair)
    except Exception as err:
        print(err)
        return False
    else:
        return(ret)
Example #7
0
def current_orders_(pair):
    try:
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
        if pair == 'null':
            orders = api.open_orders('')
        else:
            orders = api.open_orders(pair)
    except Exception as err:
        print(err)
    else:
        orders = json.dumps(orders)
        return(orders)
Example #8
0
def coltick(col,pair):
    try:
        col = str(col)
        pair = str(pair)
        api = cexio.Api('conf.username', 'conf.api_key', 'conf.api_secret')
        last = json.dumps(api.ticker(pair)['last'])
        ask = json.dumps(api.ticker(pair)['ask'])
        bid = json.dumps(api.ticker(pair)['bid'])
        print("Last: %s Ask: %s Bid %s " % (last, ask, bid))
    except Exception as err:
        print("Error: %s" % err)
        pass
Example #9
0
def orderBook(pair):
    try:
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
        if pair == 'null':
            book = api.order_book('1', 'BTC/USD')
        else:
            book = order_book = api.order_book('1',pair)
    except Exception as err:
        print(err)
    else:
        book = json.dumps(book)
        return(book)
Example #10
0
def balances():
    try:
        #api = cexapi.API(conf.username, conf.api_key, conf.api_secret)
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
        try:
            bal = json.dumps(api.balance)
        except Exception as err:
            print(err)
            return False
        #print(bal)
        #bal = json.dumps(bal)
        return(bal)
    except Exception as err:
        print("Error: %s" % err)
        return False
Example #11
0
def placeOrder(otype, pair, amount, price):
    pair = str(pair)
    debug = True
    try:
        api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    except Exception as err:
        print(err)
        return False
    else:
        if float(amount) > float(0):
            if float(price) and float(price) > float(0.0):
                if valid_pair(pair):
                    try:
                        if otype == 'buy':
                            ret = api.buy_limit_order(amount, price, pair)
                        if otype == 'sell':
                            ret = api.sell_limit_order(amount, price, pair)
                    except Exception as err:
                        print(err)
                        return False
                    else:
                        ret = json.dumps(ret)
                        order_info = json.loads(ret)
                        if debug: print(ret)
                        try:
                            order_type = order_info['type']
                            order_id = order_info['id']
                            order_time = order_info['time']
                            order_price = order_info['price']
                            order_amount = order_info['amount']
                            order_pending = order_info['pending']
                            order_complete = order_info['complete']
                        except Exception as err:
                            print(err)
                            return False
                        else:
                            print("Sucess. Order ID: %s posted at %s  " % (order_id,order_time,))
                            print("Type: %s Amount: %s at %s Complete: %s Pending: %s" %(order_type,order_amount,order_price,order_complete,order_pending))
                            return True
                else:
                    print("Invalid pair, not executing")
                    return False
            else:
                print("Invalid price, not exectuting")
                return False
        else:
            print("Invalid amount, not executing")
            return False
Example #12
0
def get_trade_hist(since, pair):
    """
    since - return trades with tid >= since (optional parameter, 1000 or all existing (if less than 1000), elements are returned if omitted)
    """
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    if valid_pair(pair):
        try:
            #ret = json.dumps(api.trade_history(since, pair))
            ret = api.trade_history(since, pair)
        except Exception as err:
            print(err)
            return False
        else:
            return(ret)
    else:
        print("Invalid pair specified")
        return False
Example #13
0
def price_stats(hours, limit, pair):
    api = cexio.Api(conf.username, conf.api_key, conf.api_secret)
    if valid_pair(pair):
        try:
            ret = json.dumps(api.price_stats(hours, limit, pair))
        except Exception as err:
            print(err)
            return False
        else:
            ret = json.loads(ret)
            plist = []         
            for i in ret:
                price = str(i['price'])
                timestamp = str(i['tmsp'])
                plist.append("Price: "+price+" Time: "+timestamp)
            return list(plist)

    
    else:
        print("Invalid Pair")
        return False
Example #14
0
	server = smtplib.SMTP('smtp.gmail.com', 587)
	#server.helo()
	server.starttls()
	server.login(guser, gpass)
	server.sendmail(sent_from, to, email_text)

	server.close()

	print ('Email Sent')
#	print ('SMS Sent')
##############################################################################################################
'''

##############################################################################################################
## CEX API ##   https://github.com/matveyco/cex.io-api-python
myapi = cexio.Api(username, api_key, api_secret)


# Print open orders
o_orders = myapi.open_orders('BTC/USD')
print ("Open Orders:")
print (o_orders)
print ("\n")

##--------------------------------------------------------------- Ticker Symbols ---------------------------------------------------------------------##
#----------BTC/USD-----------#
btc_usd659 = "Ticker (BTC/USD)"
last_price = (myapi.ticker()['last'])
#----------ETH/USD-----------#
etc_usd103 = "Ticker (ETH/USD)"
et1 = (myapi.ticker("ETH/USD")['last'])
Example #15
0
from urllib.request import urlopen
import argparse
import time
import sys
#import cexapi
import conf
import time
import json
# TODO: Fix this so it is using a real config file!
import conf
import sys
#from termcolor import colored
debug=False
import cexio
#cexio = cex
api = cexio.Api(conf.username, conf.api_key, conf.api_secret)



import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG, filename='cex-tool.log')


def timeStamp():
    return time.time()

def coltick(col,pair):
    try:
        col = str(col)
        pair = str(pair)
        api = cexio.Api('conf.username', 'conf.api_key', 'conf.api_secret')
Example #16
0
    def __init__(self, quantity, username, key, secret):
        self.quantity = quantity
        self.commission = .2

        import cexio
        self.api = cexio.Api(username, key, secret)