Пример #1
0
def _get_content(url):
    page = requests.get(url)
    if page.status_code != 200:
        core.info("req bitcointalk status code : {0}".format(page.status_code))
        return ""
    result = page.content
    with open("page.html", 'wb+') as wf:
        wf.write(result)
    return result
Пример #2
0
def _get_content(url):
    page = requests.get(url)
    if page.status_code != 200:
        core.info("req bitcointalk status code : {0}".format(page.status_code))
        return ""
    result = page.content
    with open("page.html", 'wb+') as wf:
        wf.write(result)
    return result
Пример #3
0
def run():
	exchange_yunbi = yunbi_wrapper(_get_value('yunbi','apikey'), _get_value('yunbi','secret'))
	exchange_bittrex = bittrex_wrapper(_get_value('bittrex','apikey'), _get_value('bittrex', 'secret'))
	exchange_poloniex = poloniex_wrapper(_get_value('poloniex','apikey'), _get_value('poloniex','secret'))

	ex_pair = exchange_pair('fct',exchange_yunbi, exchange_bittrex, exchange_poloniex)
	info = ex_pair.run()

	if info != None and len(info) > 0:
		core.info(info)
Пример #4
0
def start():
    maxid = _get_max_id()

    while True:
        maxid = maxid + 1
        try:
            _get_info_by_id(maxid)
        except Exception, e:
            core.info('Exception = ' + str(e))

        time.sleep(0.5)
Пример #5
0
def _insert(uid, name, posts, activity, position, register_time, last_active, msn, yim, email, trust):
    core.info("uid={0},name={1},posts={2},activity={3},position={4},register_time={5},last_active={6},msn={7},yim={8},email={9},trust={10}".format(uid, name, posts, activity, position, register_time, last_active, msn, yim, email, trust))
    print uid, " ok"
    conn = sqlite3.connect(DB_FILE)
    sql = "INSERT INTO {0} (id,name,posts,activity,position,register_time,last_active,msn,yim,email,trust) \
          VALUES ({1},'{2}',{3},{4},'{5}','{6}','{7}','{8}','{9}','{10}',{11})".format(TABLE_NAME,uid, name, posts, activity, position, register_time, last_active, msn, yim, email, int(trust))
 
    conn.execute(sql)
 
    conn.commit()
    conn.close()
Пример #6
0
def start():
    maxid = _get_max_id()
 
    while True:
        maxid = maxid + 1
        try:
            _get_info_by_id(maxid)
        except Exception,e:
            core.info('Exception = ' + str(e))
             
        time.sleep(0.5)
Пример #7
0
    def _record(self, currency, new_price, old_price, bids, asks):
        rate = round((new_price - old_price) / old_price, 3) * 100

        print(currency)
        # print('bids = ',bids)
        # print('asks = ',asks)

        bid_volume_offset = {}
        for bid_order in bids:
            for p_offset in price_offset:
                if bid_order['price'] > new_price * (1 - p_offset):
                    if p_offset in bid_volume_offset:
                        bid_volume_offset[p_offset] += bid_order[
                            'volume'] * bid_order['price']
                    else:
                        bid_volume_offset[p_offset] = bid_order[
                            'volume'] * bid_order['price']

        ask_volume_offset = {}
        for ask_order in asks:
            for p_offset in price_offset:
                if ask_order['price'] < new_price * (1 + p_offset):
                    if p_offset in ask_volume_offset:
                        ask_volume_offset[p_offset] += ask_order[
                            'volume'] * ask_order['price']
                    else:
                        ask_volume_offset[p_offset] = ask_order[
                            'volume'] * ask_order['price']

        # deal with edge condition
        for p_offset in price_offset:
            if bids[-1]['price'] > new_price * (1 - p_offset):
                bid_volume_offset[p_offset] = 0
            if asks[-1]['price'] < new_price * (1 + p_offset):
                ask_volume_offset[p_offset] = 0

        for k, v in bid_volume_offset.iteritems():
            bid_volume_offset[k] = round(v, 2)

        for k, v in ask_volume_offset.iteritems():
            ask_volume_offset[k] = round(v, 2)

        msg = str.format('\nname={0},last_price={1},new_pair={2},offset={3}',
                         currency, old_price, new_price, rate) + '\n'
        msg += str.format('bid volume = {0}\n', bid_volume_offset)
        msg += str.format('ask volume = {0}\n', ask_volume_offset)

        core.info(msg)

        core.pushover(push_over_id, msg)
Пример #8
0
def run():
	core.log('='*50 + 'arbitrage run ' + '='*50)

	try:
		# exchange_bittrex = bittrex_wrapper(conf.get_account_value('bittrex','apikey'), conf.get_account_value('bittrex', 'secret'))
		exchange_poloniex = poloniex_wrapper(conf.get_account_value('poloniex','apikey'), conf.get_account_value('poloniex','secret'), "USDT")
		exchange_yunbi = yunbi_wrapper(conf.get_account_value('yunbi','apikey'), conf.get_account_value('yunbi','secret'))

		ex_pair = exchange_pair('zec', exchange_yunbi, exchange_poloniex, 6.91)
		message = ex_pair.run()

		if len(message) > 0:
			core.info('message = ' + message)
			_send_sms(message)

	except Exception,e:
		core.info('Exception = ' + str(e))
Пример #9
0
def _insert(uid, name, posts, activity, position, register_time, last_active,
            msn, yim, email, trust):
    core.info(
        "uid={0},name={1},posts={2},activity={3},position={4},register_time={5},last_active={6},msn={7},yim={8},email={9},trust={10}"
        .format(uid, name, posts, activity, position, register_time,
                last_active, msn, yim, email, trust))
    print uid, " ok"
    conn = sqlite3.connect(DB_FILE)
    sql = "INSERT INTO {0} (id,name,posts,activity,position,register_time,last_active,msn,yim,email,trust) \
          VALUES ({1},'{2}',{3},{4},'{5}','{6}','{7}','{8}','{9}','{10}',{11})".format(
        TABLE_NAME, uid, name, posts, activity, position, register_time,
        last_active, msn, yim, email, int(trust))

    conn.execute(sql)

    conn.commit()
    conn.close()
Пример #10
0
	def _record(self, currency, new_price, old_price, bids, asks):
		rate = round((new_price - old_price) / old_price, 3) * 100

		print(currency)
		# print('bids = ',bids)
		# print('asks = ',asks)
		
		bid_volume_offset = {}
		for bid_order in bids:
			for p_offset in price_offset:
				if bid_order['price'] > new_price * (1 - p_offset):
					if p_offset in bid_volume_offset:
						bid_volume_offset[p_offset] += bid_order['volume'] * bid_order['price']
					else:
						bid_volume_offset[p_offset] = bid_order['volume'] * bid_order['price']

		ask_volume_offset = {}
		for ask_order in asks:
			for p_offset in price_offset:
				if ask_order['price'] < new_price * (1 + p_offset):
					if p_offset in ask_volume_offset:
						ask_volume_offset[p_offset] += ask_order['volume'] * ask_order['price']
					else:
						ask_volume_offset[p_offset] = ask_order['volume'] * ask_order['price']

		# deal with edge condition
		for p_offset in price_offset:
			if bids[-1]['price'] > new_price * (1 - p_offset):
				bid_volume_offset[p_offset] = 0
			if asks[-1]['price'] < new_price * (1 + p_offset):
				ask_volume_offset[p_offset] = 0

		for k,v in bid_volume_offset.iteritems():
			bid_volume_offset[k] = round(v,2)

		for k,v in ask_volume_offset.iteritems():
			ask_volume_offset[k] = round(v,2)

		msg = str.format('\nname={0},last_price={1},new_pair={2},offset={3}', currency, old_price, new_price, rate) + '\n'
		msg += str.format('bid volume = {0}\n', bid_volume_offset)
		msg += str.format('ask volume = {0}\n', ask_volume_offset)
		
		core.info(msg)

		core.pushover(push_over_id, msg)
Пример #11
0
def run():
    core.log('=' * 50 + 'arbitrage run ' + '=' * 50)

    try:
        # exchange_bittrex = bittrex_wrapper(conf.get_account_value('bittrex','apikey'), conf.get_account_value('bittrex', 'secret'))
        exchange_poloniex = poloniex_wrapper(
            conf.get_account_value('poloniex', 'apikey'),
            conf.get_account_value('poloniex', 'secret'), "USDT")
        exchange_yunbi = yunbi_wrapper(
            conf.get_account_value('yunbi', 'apikey'),
            conf.get_account_value('yunbi', 'secret'))

        ex_pair = exchange_pair('zec', exchange_yunbi, exchange_poloniex, 6.91)
        message = ex_pair.run()

        if len(message) > 0:
            core.info('message = ' + message)
            _send_sms(message)

    except Exception, e:
        core.info('Exception = ' + str(e))
Пример #12
0
	def run(self):
		# self._btc_cny_rate = self._ex_yunbi.btc_cny_rate();

		# init sell price, we need it beacause there exist min_order limit
		self._price = self._ex_A.ticker_pairs([self._currency])[self._currency]
		self._sell_price = self._price * 0.5

		self._balance_A = self._ex_A.balance([self._ex_A.default_currency, self._currency])
		self._balance_B = self._ex_B.balance([self._ex_B.default_currency, self._currency])
		old_merged_balance = self._merge_balance(self._balance_A, self._balance_B)

		message = ""

		if self._check_fix_amount(old_merged_balance[self._currency]) == True:
			message = str.format("fix amount, current = {0}, target = {1}", old_merged_balance[self._currency], self._fix_amount)
			# if do fix amount, then restart because we need the new balance
			return message

		print 'balance = ' + self._get_brief_info(old_merged_balance,self._ex_A.default_currency, self._currency)
		
		start_time = time.time()

		A_bids, A_asks = self._ex_A.order_book(self._currency)
		B_bids, B_asks = self._ex_B.order_book(self._currency)

		if time.time() - start_time > MAX_ORDER_TIME:
			raise Exception(str.format("get order timeout: {0}", time.time() - start_time))

		make_it = False

		# A-sell,B-buy
		max_volume, max_income = self._check_bid_ask(A_bids, B_asks, self._ex_A.tx_sell_fee, self._ex_B.tx_buy_fee)
		if max_income > 0:
			max_buy_volume = self._money_to_volume(B_asks, self._balance_B[self._ex_B.default_currency], self._ex_B.tx_buy_fee)
			target_volume = min(self._balance_A[self._currency], max_volume, max_buy_volume)
			target_income = self._volume_to_money(A_bids, target_volume, self._ex_A.tx_sell_fee) - self._volume_to_money(B_asks,target_volume,self._ex_B.tx_buy_fee)
			core.info(str.format("max_income={0},max_volume={1},max_buy_volume={2},target_volume={3},target_income={4}",max_income,max_volume,max_buy_volume,target_volume,target_income))
			if target_income > MIN_EXPECT_PROFIT	:
				message = str.format('max_volume={0},max_income={1},target_volume={2},target_income={3}', max_volume, max_income, target_volume, target_income)
					
				if TAG_BUY_SELL:
					self._ex_A.sell(self._currency, target_volume, self._sell_price)
					self._ex_B.buy(self._currency,target_volume)
				make_it = True



		# A-buy,B-sell
		max_volume, max_income = self._check_bid_ask(B_bids, A_asks, self._ex_B.tx_sell_fee, self._ex_A.tx_buy_fee)
		if max_income > 0:
			max_buy_volume = self._money_to_volume(A_asks, self._balance_A[self._ex_A.default_currency], self._ex_A.tx_buy_fee)
			target_volume = min(self._balance_B[self._currency], max_volume, max_buy_volume)
			target_income = self._volume_to_money(B_bids, target_volume, self._ex_B.tx_sell_fee) - self._volume_to_money(A_asks,target_volume,self._ex_A.tx_buy_fee)
			core.info(str.format("max_income={0},max_volume={1},max_buy_volume={2},target_volume={3},target_income={4}",max_income,max_volume,max_buy_volume,target_volume,target_income))
			if target_income > MIN_EXPECT_PROFIT:
				message = str.format('max_volume={0},max_income={1},target_volume={2},target_income={3}', max_volume, max_income, target_volume, target_income)
				
				if TAG_BUY_SELL:
					self._ex_B.sell(self._currency, target_volume, self._sell_price)
					self._ex_A.buy(self._currency,target_volume)
				make_it = True

		

		if make_it:
			new_balance_A = self._ex_A.balance([self._ex_A.default_currency, self._currency])
			new_balance_B = self._ex_B.balance([self._ex_B.default_currency, self._currency])
			new_merged_balance = self._merge_balance(new_balance_A, new_balance_B)

			core.info(old_merged_balance)
			core.info(new_merged_balance)

			old_info = self._get_brief_info(old_merged_balance,self._ex_A.default_currency, self._currency)
			new_info = self._get_brief_info(new_merged_balance,self._ex_A.default_currency, self._currency)
			message += str.format('\n{0} => \n{1}\n{2}', old_info, new_info,time.time() - start_time)

		return message
Пример #13
0
def _get_content():
	page = requests.get('https://bitcointalk.org/index.php?board=159.0')
	if page.status_code != 200:
		core.info("req bitcointalk status code : {0}".format(page.status_code))
		return ""
	return page.content
Пример #14
0
def _findit(desc, topic, time_str, content_str, url):
    content = "{0}\n{1}\n{2}\n{3}\n{4}".format(desc, topic, url, time_str,
                                               content_str)
    core.info(content)
    # print content
    core.pushover(PUSHOVER_APP_ID, content)
Пример #15
0
    def run(self):
        # self._btc_cny_rate = self._ex_yunbi.btc_cny_rate();

        # init sell price, we need it beacause there exist min_order limit
        self._price = self._ex_A.ticker_pairs([self._currency])[self._currency]
        self._sell_price = self._price * 0.5

        self._balance_A = self._ex_A.balance(
            [self._ex_A.default_currency, self._currency])
        self._balance_B = self._ex_B.balance(
            [self._ex_B.default_currency, self._currency])
        old_merged_balance = self._merge_balance(self._balance_A,
                                                 self._balance_B)

        message = ""

        if self._check_fix_amount(old_merged_balance[self._currency]) == True:
            message = str.format("fix amount, current = {0}, target = {1}",
                                 old_merged_balance[self._currency],
                                 self._fix_amount)
            # if do fix amount, then restart because we need the new balance
            return message

        print 'balance = ' + self._get_brief_info(
            old_merged_balance, self._ex_A.default_currency, self._currency)

        start_time = time.time()

        A_bids, A_asks = self._ex_A.order_book(self._currency)
        B_bids, B_asks = self._ex_B.order_book(self._currency)

        if time.time() - start_time > MAX_ORDER_TIME:
            raise Exception(
                str.format("get order timeout: {0}",
                           time.time() - start_time))

        make_it = False

        # A-sell,B-buy
        max_volume, max_income = self._check_bid_ask(A_bids, B_asks,
                                                     self._ex_A.tx_sell_fee,
                                                     self._ex_B.tx_buy_fee)
        if max_income > 0:
            max_buy_volume = self._money_to_volume(
                B_asks, self._balance_B[self._ex_B.default_currency],
                self._ex_B.tx_buy_fee)
            target_volume = min(self._balance_A[self._currency], max_volume,
                                max_buy_volume)
            target_income = self._volume_to_money(
                A_bids, target_volume,
                self._ex_A.tx_sell_fee) - self._volume_to_money(
                    B_asks, target_volume, self._ex_B.tx_buy_fee)
            core.info(
                str.format(
                    "max_income={0},max_volume={1},max_buy_volume={2},target_volume={3},target_income={4}",
                    max_income, max_volume, max_buy_volume, target_volume,
                    target_income))
            if target_income > MIN_EXPECT_PROFIT:
                message = str.format(
                    'max_volume={0},max_income={1},target_volume={2},target_income={3}',
                    max_volume, max_income, target_volume, target_income)

                if TAG_BUY_SELL:
                    self._ex_A.sell(self._currency, target_volume,
                                    self._sell_price)
                    self._ex_B.buy(self._currency, target_volume)
                make_it = True

        # A-buy,B-sell
        max_volume, max_income = self._check_bid_ask(B_bids, A_asks,
                                                     self._ex_B.tx_sell_fee,
                                                     self._ex_A.tx_buy_fee)
        if max_income > 0:
            max_buy_volume = self._money_to_volume(
                A_asks, self._balance_A[self._ex_A.default_currency],
                self._ex_A.tx_buy_fee)
            target_volume = min(self._balance_B[self._currency], max_volume,
                                max_buy_volume)
            target_income = self._volume_to_money(
                B_bids, target_volume,
                self._ex_B.tx_sell_fee) - self._volume_to_money(
                    A_asks, target_volume, self._ex_A.tx_buy_fee)
            core.info(
                str.format(
                    "max_income={0},max_volume={1},max_buy_volume={2},target_volume={3},target_income={4}",
                    max_income, max_volume, max_buy_volume, target_volume,
                    target_income))
            if target_income > MIN_EXPECT_PROFIT:
                message = str.format(
                    'max_volume={0},max_income={1},target_volume={2},target_income={3}',
                    max_volume, max_income, target_volume, target_income)

                if TAG_BUY_SELL:
                    self._ex_B.sell(self._currency, target_volume,
                                    self._sell_price)
                    self._ex_A.buy(self._currency, target_volume)
                make_it = True

        if make_it:
            new_balance_A = self._ex_A.balance(
                [self._ex_A.default_currency, self._currency])
            new_balance_B = self._ex_B.balance(
                [self._ex_B.default_currency, self._currency])
            new_merged_balance = self._merge_balance(new_balance_A,
                                                     new_balance_B)

            core.info(old_merged_balance)
            core.info(new_merged_balance)

            old_info = self._get_brief_info(old_merged_balance,
                                            self._ex_A.default_currency,
                                            self._currency)
            new_info = self._get_brief_info(new_merged_balance,
                                            self._ex_A.default_currency,
                                            self._currency)
            message += str.format('\n{0} => \n{1}\n{2}', old_info, new_info,
                                  time.time() - start_time)

        return message
Пример #16
0
import sys
import os

import sqlite3
sys.path.insert(0, os.path.abspath('../..'))

import core.conf as conf
import core.core as core
import time

DB_FILE = "../ens.db"
TABLE_NAME = "domain"

print 'Content-Type: text/html\n'

core.info("receive msg...")

conn = sqlite3.connect(DB_FILE)
valid_time = time.time() - 3 * 24 * 60 * 60
now = time.time()
cursor = conn.execute(
    "SELECT domain,enable_time,from_type,sitescore,sitedesc from {0} where enable_time > {1} and enable_time < {2} and watched=0 and valid=1 order by enable_time"
    .format(TABLE_NAME, valid_time, now))

data = cursor.fetchall()

result = []
for row in data:
    item = {
        "domain": row[0],
        "enable_time": {1},
Пример #17
0
import sys
import os

import sqlite3
sys.path.insert(0, os.path.abspath('../..'))

import core.conf as conf
import core.core as core
import time

DB_FILE = "../ens.db"
TABLE_NAME = "domain"

print 'Content-Type: text/html\n'

core.info("receive msg...")

conn = sqlite3.connect(DB_FILE)
valid_time = time.time() - 3*24*60*60
now = time.time()
cursor = conn.execute("SELECT domain,enable_time,from_type,sitescore,sitedesc from {0} where enable_time > {1} and enable_time < {2} and watched=0 and valid=1 order by enable_time".format(TABLE_NAME, valid_time, now))

data = cursor.fetchall()

result = []
for row in data:
	item = {"domain":row[0],"enable_time":{1},"from_type":{2},"sitescore":{3},"sitedesc":{4}}
	result.append(item)

print result
conn.close()
Пример #18
0
#!/usr/bin/env python

import cgi
import sys
import os

import sqlite3
sys.path.insert(0, os.path.abspath('../..'))

import core.conf as conf
import core.core as core
import time

DB_FILE = "../ens.db"
TABLE_NAME = "domain"

print 'Content-Type: text/html\n'

core.info("receive valid msg...")

form = cgi.FieldStorage()
domain = form['domain'].value or ''

conn = sqlite3.connect(DB_FILE)
cursor = conn.execute("UPDATE {0} SET `valid`=0 where `domain`='{1}'".format(TABLE_NAME, domain))
conn.commit()
conn.close()

print {"errorcode":0}
Пример #19
0
def _findit(desc,topic, time_str, content_str, url):
	content = "{0}\n{1}\n{2}\n{3}\n{4}".format(desc,topic, url,time_str, content_str)
	core.info(content)
	# print content
	core.pushover(PUSHOVER_APP_ID, content)
Пример #20
0
def _get_content():
    page = requests.get('https://bitcointalk.org/index.php?board=159.0')
    if page.status_code != 200:
        core.info("req bitcointalk status code : {0}".format(page.status_code))
        return ""
    return page.content
Пример #21
0
def _findit(item):
	content = str(item)
	core.info(content)
	core.pushover(PUSHOVER_APP_ID, content)