示例#1
0
    def main(self):

        # Create Logger
        logger = logging.getLogger()
        logger.setLevel(logging.NOTSET)
        # Create console handler and set level to debug
        sh = logging.StreamHandler()
        sh.setLevel(logging.DEBUG)
        # Create file handler and set level to debug
        fh = logging.FileHandler('mylog.txt', mode='a')
        fh.setLevel(logging.INFO)

        # Create formatter
        #formatter = logging.Formatter('%(asctime)s %(filename)s %(message)s')
        formatter = logging.Formatter('%(asctime)s %(message)s')
        # Add formatter to handlers
        sh.setFormatter(formatter)
        fh.setFormatter(formatter)

        # Add handlers to logger
        logger.addHandler(sh)
        logger.addHandler(fh)

        # Load Config File
        config = ConfigParser()
        config.read('trading.conf')

        bithumbKey = config.get('ArbBot', 'bithumbKey')
        bithumbSecret = config.get('ArbBot', 'bithumbSecret')
        coinoneKey = config.get('ArbBot', 'coinoneKey')
        coinoneSecret = config.get('ArbBot', 'coinoneSecret')

        chat_id = config.get('ChatBot', 'chatId')
        chat_token = config.get('ChatBot', 'chatToken')

        coin_name = config.get('ArbBot', 'Coin')
        self.trade_max_volume = (float)(config.get(coin_name, 'TRADE_MAX_VOLUME'))
        self.trade_min_thresh = (float)(config.get(coin_name,'TRADE_MIN_THRESH'))

        self.dryrun = int(config.get('ArbBot', 'dryrun'))


        # Load Configuration
        self.targetCurrency  = coin_name
        self.baseCurrency    = 'KRW'
        self.paymentCurrency = 'KRW'

        # Create Exchange API Objects
        bithumb = Bithumb(bithumbKey, bithumbSecret)
        coinone = Coinone(coinoneKey, coinoneSecret)

        # Main Loop

        #check balance bithumb and coinone
        print("===check balance")
        response = bithumb.balance(self.targetCurrency)
        status = 'OK' if response['status'] == "0000" else "ERROR"
        print(status)
        bithumb.targetBalance = float(response["data"]["available_" + self.targetCurrency.lower()])
        bithumb.baseBalance   = float(response["data"]["available_" + self.baseCurrency.lower()])
        logging.info("**{} : (tBal: {:.8f}) | (pBal: {:.4f})**"
              .format("bithumb", bithumb.targetBalance, bithumb.baseBalance))


        #coinone
        response = coinone.balance()
        status = 'OK' if response['errorCode'] == "0" else "ERROR"
        print(status)
        coinone.targetBalance = float(response[self.targetCurrency.lower()]["avail"])
        coinone.baseBalance   = float(response[self.baseCurrency.lower()]["avail"])
        logging.info("**{} : (tBal: {:.8f}) | (pBal: {:.4f})**"
                     .format("coinone", coinone.targetBalance, coinone.baseBalance))

        if self.dryrun:
            bithumb.targetBalance = 100
            bithumb.baseBalance   = 100000000
            coinone.targetBalance = 100
            coinone.baseBalance   = 100000000

        while True:
            #check price the target
            response = bithumb.orderbook(self.targetCurrency)
            bithumb.askprice = float(response["data"]["asks"][0]["price"])
            bithumb.bidprice = float(response["data"]["bids"][0]["price"])
            bithumb.askqty   = float(response["data"]["asks"][0]["quantity"])
            bithumb.bidqty   = float(response["data"]["bids"][0]["quantity"])
            logging.info("**{} : ask {:.0f} bid {:.0f} askqty {:.4f} bidqty {:.4f}"
                         .format("bithumb", bithumb.askprice,bithumb.bidprice, \
                         bithumb.askqty,bithumb.bidqty ))

            response = coinone.orderbook(self.targetCurrency)
            coinone.askprice = float(response['ask'][0]['price'])
            coinone.askqty   = float(response['ask'][0]['qty'])
            coinone.bidprice = float(response['bid'][0]['price'])
            coinone.bidqty   = float(response['bid'][0]['qty'])
            logging.info("**{} : ask {:.0f} bid {:.0f} askqty {:.4f} bidqty {:.4f}"
                         .format("coinone", coinone.askprice,coinone.bidprice, \
                         coinone.askqty,coinone.bidqty ))

            #test s
            # bithumb.askprice = 950
            # coinone.bidprice = 960
            #test e

            #find the chance
            if bithumb.askprice < coinone.bidprice:
                logging.info("do trading bithumb buy coinone sell !!!")
                TradeSize, Profit = self.cal_profit(bithumb, coinone)
                self.trade_min_thresh = 10
                if TradeSize > self.trade_min_thresh and Profit > 0:
                    print("start trading1 TS[%d] Profit[%d]" % (TradeSize, Profit))
                    if self.dryrun==0:
                        bithumb.??(self.targetCurrency, TradeSize, ??)
                        coinone.??(self.targetCurrency, TradeSize, ??)
                else:
                    print("skip trading1 TS[%d] Profit[%d]" %(TradeSize, Profit))
            elif coinone.askprice < bithumb.bidprice:
                logging.info("do trading coinone buy bithumb sell !!!")
                TradeSize, Profit = self.cal_profit(coinone, bithumb)
                self.trade_min_thresh = 10
                if TradeSize > self.trade_min_thresh and Profit > 10:
                    print("start trading2 TS[%d] Profit[%d]" % (TradeSize, Profit))
                    if self.dryrun==0:
                        coinone.??(self.targetCurrency, TradeSize, ??)
                        bithumb.??(self.targetCurrency, TradeSize, ??)
                else:
                    print("skip trading2 TS[%d] Profit[%d]" % (TradeSize, Profit))
            else:
                logging.info("..")

            time.sleep(5)
示例#2
0
from bithumb import Bithumb
from configparser import ConfigParser, NoSectionError
import time

# Load Config File
config = ConfigParser()
config.read('trading.conf')

bithumbKey = config.get('ArbBot', 'bithumbKey')
bithumbSecret = config.get('ArbBot', 'bithumbSecret')

targetCurrency = 'XRP'
baseCurrency = 'KRW'

# object created
bithumb = Bithumb(bithumbKey, bithumbSecret)

#balance check
print("=== check balance ===")
walletinfo = bithumb.balance(targetCurrency)
print(walletinfo)

#check orderbook
marketinfo = bithumb.orderbook(targetCurrency)
print(marketinfo)
askprice = float(marketinfo["data"]["asks"][0]["price"])
bidprice = float(marketinfo["data"]["bids"][0]["price"])
askqty = float(marketinfo["data"]["asks"][0]["quantity"])
bidqty = float(marketinfo["data"]["bids"][0]["quantity"])
print("askprice[%d] bidprice[%d] askqty[%d] bidqty[%d]" %
      (askprice, bidprice, askqty, bidqty))
示例#3
0
from bithumb import Bithumb
from bitfinex import Bitfinex

INTERVAL = 30

watch_list = ["ETH", "LTC", "EOS", "XRP", "BCH"]

next_execute_time = int(time()) + 0.5

while True:
    current_time = (int(time()))
    sleep(next_execute_time - current_time)
    next_execute_time += INTERVAL
    bitfinex_prices = []
    bithumb_prices = []
    for symbol in watch_list:
        bithumb_prices.append(
            sum(Bithumb.get_relative_price(symbol, 'BTC')) / 2)
        bitfinex_prices.append(
            sum(Bitfinex.get_relative_price(symbol, 'BTC')) / 2)
    os.system('clear')
    print("{0:<10} | {1:<15} | {2:<15} | {3:<8} ".format(
        "Symbol", "Bitfinex", "Bithumb", "Difference"))
    print("-" * 80)
    for symbol, bitfinex_price, bithumb_price in zip(watch_list,
                                                     bitfinex_prices,
                                                     bithumb_prices):
        difference = 100.0 * (bithumb_price - bitfinex_price) / bitfinex_price
        print("{0:<10} | {1:<15.8f} | {2:<15.8f} | {3:<8.2f}% ".format(
            symbol, bitfinex_price, bithumb_price, difference))
示例#4
0
# 이 프로그램은 빗썸 api 를 테스트하는 프로그램이다.

from bithumb import Bithumb
from configparser import ConfigParser, NoSectionError
import time

# Load Config File
config = ConfigParser()
config.read('trading.conf')

bithumbKey = config.get('ArbBot', 'bithumbKey')
bithumbSecret = config.get('ArbBot', 'bithumbSecret')

targetCurrency = 'XRP'
baseCurrency = 'KRW'

# object created
bithumb = Bithumb(bithumbKey, bithumbSecret)

print("welcome to trading bot")
示例#5
0
 def test_bithumb_tickers(self):
     bithumb = Bithumb()
     result = bithumb.tickers()
     print(result)
示例#6
0
import unittest
import os, time
from bithumb import Bithumb
from configparser import ConfigParser

# Load Config File
config = ConfigParser()
config.read('trading.conf')

connect_key = config.get('ArbBot', 'bithumbKey')
secret_key = config.get('ArbBot', 'bithumbSecret')

bithumb = Bithumb(connect_key, secret_key)


# TestCase를 작성
class CustomTests(unittest.TestCase):
    def setUp(self):
        print('setup')

    def tearDown(self):
        """테스트 종료 후 파일 삭제 """
        print('tear down')

    def test_mybalance(self):
        start = time.time()
        for _ in range(16):
            result = bithumb.balance('ETH')
            print(result)
        print("time :", time.time() - start)