예제 #1
0
    def __init__(self, quantity, key, secret):
        self.quantity = quantity
        self.commission = .2

        from bitfinex.client import Client, TradeClient
        self.privateWrapper = TradeClient(key, secret)
        self.publicWrapper = Client()
예제 #2
0
def paper_trade():
	try:
		client = Client()
		symbols = client.symbols()
		symbol = 'btcusd'
		lastprice = client.ticker(symbol)['last_price']
		print (lastprice)
		threading.Timer(0.5, paper_trade).start()
	except:
		print('couldnt get price data')
		threading.Timer(0.5, paper_trade).start()
예제 #3
0
def paper_trade():
    try:
        client = Client()
        symbols = client.symbols()
        symbol = 'btcusd'
        lastprice = client.ticker(symbol)['last_price']
        print(lastprice)
        threading.Timer(0.5, paper_trade).start()
    except:
        print('couldnt get price data')
        threading.Timer(0.5, paper_trade).start()
예제 #4
0
 def getprices(self):
     try:
         client = Client()
         symbols = client.symbols()
         btcsymbol = 'btc'
         ethsymbol = 'eth'
         symbol = 'btcusd'
         lastprice = client.ticker(symbol)['last_price']
         btcresponse = client.lends(btcsymbol)
         ethresponse = client.lends(ethsymbol)
         self.newbtclent = float(btcresponse[0]['amount_lent'])
         self.newbtcused = float(btcresponse[0]['amount_used'])
         self.newethlent = float(ethresponse[0]['amount_lent'])
         self.newethused = float(ethresponse[0]['amount_used'])
         self.keepgoing = 1
     except:
         print('unable to get price data')
예제 #5
0
	def getprices(self):
		try:
			client = Client()
			symbols = client.symbols()
			btcsymbol = 'btc'
			ethsymbol = 'eth'
			symbol = 'btcusd'
			lastprice = client.ticker(symbol)['last_price']
			btcresponse = client.lends(btcsymbol)
			ethresponse = client.lends(ethsymbol)
			self.newbtclent = float(btcresponse[0]['amount_lent'])
			self.newbtcused = float(btcresponse[0]['amount_used'])
			self.newethlent = float(ethresponse[0]['amount_lent'])
			self.newethused = float(ethresponse[0]['amount_used'])
			self.keepgoing = 1
		except:
			print ('unable to get price data')
예제 #6
0
 def __init__(self, currency, item = BTC, depth = 50):
     try:
         from bitfinex.client import Client
     except ImportError:
         import sys
         print "Couldn't find module bitfinex. Download and install from:"
         print "https://github.com/scottjbarr/bitfinex"
         print "Or run:\n pip install bitfinex"
         sys.exit(1)
         
     super(BitfinexMarket, self).__init__(self.MARKET_NAME, currency, item)
     self.client = Client()
     self.depth = depth
예제 #7
0
class BitfinexMarket(BaseMarket):
    MARKET_NAME = "Bitfinex"

    def __init__(self, currency, item = BTC, depth = 50):
        try:
            from bitfinex.client import Client
        except ImportError:
            import sys
            print "Couldn't find module bitfinex. Download and install from:"
            print "https://github.com/scottjbarr/bitfinex"
            print "Or run:\n pip install bitfinex"
            sys.exit(1)
            
        super(BitfinexMarket, self).__init__(self.MARKET_NAME, currency, item)
        self.client = Client()
        self.depth = depth

    def getTicker(self):
        logger.debug("getting ticker")

        raise NotImplementedError()

    def _getCurrencyPair(self):
        return "%s%s"%(self.currency2.name.lower(), self.currency1.name.lower())

    def getDepth(self):
        logger.debug("getting depth")

        parameters = {'limit_asks': self.depth, 'limit_bids': self.depth}
        
        d = self.client.order_book(self._getCurrencyPair(), parameters)

        ret = {
            'asks': self._depthToOrders(d[u'asks'], Order.ASK),
            'bids': self._depthToOrders(d[u'bids'], Order.BID),
        }
        return ret

    def _depthToOrders(self, depth, order_type):
        from datetime import datetime
        orders = []

        for d in depth:
            # TODO: change the low-level stream to use Amount instead of numbers
            # this means also changing the "hash" of Amount.
            amount = Amount(Decimal(d[u'amount']), self.currency2)
            price = ExchangeRate(self.currency2, self.currency1, Decimal(d[u'price']))
            order = Order(self, datetime.fromtimestamp(d[u'timestamp']), order_type, amount, price)
            orders.append(order)

        return orders
예제 #8
0
class BFX(object):
    def __init__(self, quantity, key, secret):
        self.quantity = quantity
        self.commission = .2

        from bitfinex.client import Client, TradeClient
        self.privateWrapper = TradeClient(key, secret)
        self.publicWrapper = Client()

    def getCommission(self):
        return self.commission

    def getSpotPrice(self, ticker='btcusd'):
        return self.publicWrapper.ticker(ticker)['last_price']

    def goLong(self):
        price = self.getSpotPrice()
        order = self.privateWrapper.place_order(self.quantity, price, 'buy',
                                                'exchange market')
        import time
        time.sleep(.25)
예제 #9
0
 def __init__(self, api_key, api_secret):
     Client.__init__(self)
예제 #10
0
 def setUp(self):
     self.client = Client()
예제 #11
0
class BitfinexTest(unittest.TestCase):
    def setUp(self):
        self.client = Client()

    def test_should_have_server(self):
        self.assertEqual("https://api.bitfinex.com/v1", self.client.server())

    def test_should_have_url_for_foo(self):
        expected = "https://api.bitfinex.com/v1/foo"
        self.assertEqual(expected, self.client.url_for("foo"))

    def test_should_have_url_for_path_arg(self):
        expected = "https://api.bitfinex.com/v1/foo/bar"
        actual = self.client.url_for('foo/%s', path_arg="bar")
        self.assertEqual(expected, actual)

    def test_should_have_url_with_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo?a=1&b=2"
        actual = self.client.url_for('foo', parameters={'a': 1, 'b': 2})
        self.assertEqual(expected, actual)

    def test_should_have_url_for(self):
        expected = self.client.url_for("foo")
        self.assertEqual("https://api.bitfinex.com/v1/foo", expected)

    def test_should_have_url_for_with_path_arg(self):
        expected = "https://api.bitfinex.com/v1/foo/bar"
        path = "foo/%s"
        self.assertEqual(expected, self.client.url_for(path, path_arg='bar'))
        self.assertEqual(expected, self.client.url_for(path, 'bar'))

    def test_should_have_url_for_with_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo?a=1"
        self.assertEqual(expected,
                         self.client.url_for("foo", parameters={'a': 1}))
        self.assertEqual(expected, self.client.url_for("foo", None, {'a': 1}))

    def test_should_have_url_for_with_path_arg_and_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo/bar?a=1"
        path = "foo/%s"
        self.assertEqual(
            expected,
            self.client.url_for(path, path_arg='bar', parameters={'a': 1}))
        self.assertEqual(expected, self.client.url_for(path, 'bar', {'a': 1}))

    @httpretty.activate
    def test_should_have_symbols(self):
        # mock out the request
        mock_body = '["btcusd","ltcusd","ltcbtc"]'
        url = self.client.url_for('symbols')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = ["btcusd", "ltcusd", "ltcbtc"]
        self.assertEqual(expected, self.client.symbols())

    @httpretty.activate
    def test_should_have_ticker(self):
        # mock out the request
        mock_body = '{"mid":"562.56495","bid":"562.15","ask":"562.9799","last_price":"562.25","timestamp":"1395552658.339936691"}'
        url = self.client.url_for('ticker/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "mid": 562.56495,
            "bid": 562.15,
            "ask": 562.9799,
            "last_price": 562.25,
            "timestamp": 1395552658.339936691
        }

        self.assertEqual(expected, self.client.ticker('btcusd'))

    @httpretty.activate
    def test_should_have_today(self):
        # mock out the request
        mock_body = '{"low":"550.09","high":"572.2398","volume":"7305.33119836"}'
        url = self.client.url_for('today/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {"low": 550.09, "high": 572.2398, "volume": 7305.33119836}

        self.assertEqual(expected, self.client.today('btcusd'))

    @httpretty.activate
    def test_should_have_stats(self):
        # mock out the request
        mock_body = '[{"period":1,"volume":"7410.27250155"},{"period":7,"volume":"52251.37118006"},{"period":30,"volume":"464505.07753251"}]'
        url = self.client.url_for('stats/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = [{
            "period": 1,
            "volume": 7410.27250155
        }, {
            "period": 7,
            "volume": 52251.37118006
        }, {
            "period": 30,
            "volume": 464505.07753251
        }]

        self.assertEqual(expected, self.client.stats('btcusd'))

    @httpretty.activate
    def test_should_have_lendbook(self):
        # mock out the request
        mock_body = '{"bids":[{"rate":"5.475","amount":"15.03894663","period":30,"timestamp":"1395112149.0","frr":"No"},{"rate":"2.409","amount":"14.5121868","period":7,"timestamp":"1395497599.0","frr":"No"}],"asks":[{"rate":"6.351","amount":"15.5180735","period":5,"timestamp":"1395549996.0","frr":"No"},{"rate":"6.3588","amount":"626.94808249","period":30,"timestamp":"1395400654.0","frr":"Yes"}]}'
        url = self.client.url_for('lendbook/%s', 'btc')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [{
                "rate": 5.475,
                "amount": 15.03894663,
                "period": 30,
                "timestamp": 1395112149.0,
                "frr": False
            }, {
                "rate": 2.409,
                "amount": 14.5121868,
                "period": 7,
                "timestamp": 1395497599.0,
                "frr": False
            }],
            "asks": [{
                "rate": 6.351,
                "amount": 15.5180735,
                "period": 5,
                "timestamp": 1395549996.0,
                "frr": False
            }, {
                "rate": 6.3588,
                "amount": 626.94808249,
                "period": 30,
                "timestamp": 1395400654.0,
                "frr": True
            }]
        }

        self.assertEqual(expected, self.client.lendbook('btc'))

    @httpretty.activate
    def test_should_have_lendbook_with_parameters(self):
        # mock out the request
        mock_body = '{"bids":[{"rate":"5.475","amount":"15.03894663","period":30,"timestamp":"1395112149.0","frr":"No"},{"rate":"2.409","amount":"14.5121868","period":7,"timestamp":"1395497599.0","frr":"No"}],"asks":[]}'
        parameters = {'limit_bids': 2, 'limit_asks': 0}
        url = self.client.url_for('lendbook/%s', 'btc', parameters)
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [{
                "rate": 5.475,
                "amount": 15.03894663,
                "period": 30,
                "timestamp": 1395112149.0,
                "frr": False
            }, {
                "rate": 2.409,
                "amount": 14.5121868,
                "period": 7,
                "timestamp": 1395497599.0,
                "frr": False
            }],
            "asks": []
        }

        self.assertEqual(expected, self.client.lendbook('btc', parameters))

    @httpretty.activate
    def test_should_have_order_book(self):
        # mock out the request
        mock_body = '{"bids":[{"price":"562.2601","amount":"0.985","timestamp":"1395567556.0"}],"asks":[{"price":"563.001","amount":"0.3","timestamp":"1395532200.0"}]}'
        url = self.client.url_for('book/%s', 'btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [{
                "price": 562.2601,
                "amount": 0.985,
                "timestamp": 1395567556.0
            }],
            "asks": [{
                "price": 563.001,
                "amount": 0.3,
                "timestamp": 1395532200.0
            }]
        }

        self.assertEqual(expected, self.client.order_book('btcusd'))

    @httpretty.activate
    def test_should_have_order_book_with_parameters(self):
        # mock out the request
        mock_body = '{"bids":[{"price":"562.2601","amount":"0.985","timestamp":"1395567556.0"}],"asks":[]}'
        parameters = {'limit_asks': 0}
        url = self.client.url_for('book/%s', 'btcusd', parameters)
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [{
                "price": 562.2601,
                "amount": 0.985,
                "timestamp": 1395567556.0
            }],
            "asks": []
        }

        self.assertEqual(expected,
                         self.client.order_book('btcusd', parameters))
예제 #12
0
def callback_inline1(call):
    if call.data == "Poloniex":
        x = (polo('returnTicker')['BTC_ETH']['highestBid'])
        y = (polo('returnTicker')['USDT_REP']['highestBid'])
        z = (polo('returnTicker')['BTC_DOGE']['highestBid'])
        x1 = (polo('returnTicker')['BTC_XBC']['highestBid'])
        y2 = (polo('returnTicker')['ETH_ETC']['highestBid'])
        z2 = (polo('returnTicker')['BTC_MAID']['highestBid'])

        mes = '<b>BTC_ETH</b>: ' + str(x) + '\n<b>USDT_REP</b>: ' + str(
            y) + '<b>\nBTC_DOGE</b>: ' + str(z) + '<b>\nBTC_XBC</b>: ' + str(
                x1) + '<b>\nETH_ETC</b>: ' + str(
                    y2) + '<b>\nBTC_MAID</b>: ' + str(z2)
        z = bot.send_message(call.message.chat.id, mes, parse_mode='HTML')
    if call.data == "Kraken":

        url = 'https://api.kraken.com/0/public/Ticker?pair='
        XXBTZUSD = url + 'XXBTZUSD'
        r = requests.get(XXBTZUSD)
        x = r.json()
        h = []
        for i in x['result']['XXBTZUSD'].keys():
            h.append(x['result']['XXBTZUSD'][i])
        z = []
        for i in range(0, len(h)):
            try:
                w = '\n'.join(h[i])
                z.append(w)

            except:
                print(1)
        w = '\n'.join(z)
        mes = '<b>XXBTZUSD</b>: ' + str(w)
        z = bot.send_message(call.message.chat.id, mes, parse_mode='HTML')

    if call.data == "Bitfinex":
        client = Client()
        symbols = client.symbols()
        btcusd = client.ticker(symbols[0])
        ltcusd = client.ticker(symbols[1])
        ltcbtc = client.ticker(symbols[2])
        ethusd = client.ticker(symbols[3])
        ethbtc = client.ticker(symbols[4])
        etcbtc = client.ticker(symbols[5])
        etcusd = client.ticker(symbols[6])
        rrtusd = client.ticker(symbols[7])

        mes = '<b>btc_usd</b>: ' + str(
            btcusd['last_price']) + '\n<b>ltc_usd</b>: ' + str(
                ltcusd['last_price']) + '<b>\nltc_btc</b>: ' + str(
                    ltcbtc['last_price']) + '<b>\neth_usd</b>: ' + str(
                        ethusd['last_price']) + '<b>\neth_btc</b>: ' + str(
                            ethbtc['last_price']) + '<b>\netc_btc</b>: ' + str(
                                etcbtc['last_price']
                            ) + '<b>\netc_btc</b>: ' + str(
                                etcusd['last_price']
                            ) + '<b>\nrrt_usd=</b>: ' + str(
                                rrtusd['last_price'])
        z = bot.send_message(call.message.chat.id, mes, parse_mode='HTML')
    if call.data == "Bittrex":
        url = 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-ltc'
        z = []
        r = requests.get(url)
        x = r.json()
        for i in x['result'][0]:
            e = x['result'][0][i]
            k = str(i) + ' : ' + str(e)
            z.append(k)
        w = '\n'.join(z)
        mes = '<b>btc-ltc</b>: ' + str(w)
        z = bot.send_message(call.message.chat.id, mes, parse_mode='HTML')

    if call.data == "Yobit":
        url = 'https://yobit.net/api/2/ltc_btc/ticker'

        feed = requests.get(url)
        x = feed.json()
        z = []
        for i in x['ticker']:
            e = x['ticker'][i]
            k = str(i) + ' : ' + str(e)
            z.append(k)
        w = '\n'.join(z)
        mes = '<b>ltc_btc</b>: ' + str(w)
        z = bot.send_message(call.message.chat.id, mes, parse_mode='HTML')
예제 #13
0
from bitfinex.client import Client

client = Client()

symbols = client.symbols()
print(symbols)

symbol = 'btcusd'

print(client.ticker(symbol))
print(client.today(symbol))
print(client.stats(symbol))

parameters = {'limit_asks': 2, 'limit_bids': 2}

print(client.lendbook('btc', parameters))
print(client.order_book(symbol, parameters))
예제 #14
0
import logging
import gdax
import requests
from random import *
from bitfinex.client import Client
from bittrex.bittrex import Bittrex

# Enable logging
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO)

logger = logging.getLogger(__name__)

gdax_client = gdax.PublicClient()
bitf_client = Client()
bittrex_client = Bittrex(None, None)


def help(bot, update):
    result = "Supported Commands\n"
    result = result + "(GDAX Price Lookup) /gdax <FIRST-H-PAIR> <SECOND-H-PAIR>\n"
    result = result + "(Bittrex Price Lookup) /btrx <FIRST-H-PAIR> <SECOND-H-PAIR>\n"
    result = result + "(Bitfinex Price Lookup) /bitf <FIRST-H-PAIR> <SECOND-H-PAIR>\n"
    result = result + "(Kraken Price Lookup) /krkn <FIRST-H-PAIR> <Second-H-PAIR>\n"
    result = result + "(Random Coin BTRX) /rcoin\n"
    result = result + "Example: /gdax ETH USD\n"
    update.message.reply_text(result)


def gdax(bot, update):
예제 #15
0
from bitfinex.client import Client

client = Client('apiKey','apiSecret')


orders=[]

for price in range(3, 6):
    print (price)
    payload = { "symbol": 'IOTUSD', "amount": '100', "price": str(price), "exchange": 'bitfinex', "side": 'buy', "type": 'limit' }
    orders.append(payload)


apiResponse = client.place_multiple_orders(orders)

print(apiResponse)
예제 #16
0
class BitfinexTest(unittest.TestCase):

    def setUp(self):
        self.client = Client()


    def test_should_have_server(self):
        self.assertEqual("https://api.bitfinex.com/v1", self.client.server())


    def test_should_have_url_for_foo(self):
        expected = "https://api.bitfinex.com/v1/foo"
        self.assertEqual(expected, self.client.url_for("foo"))


    def test_should_have_url_for_path_arg(self):
        expected = "https://api.bitfinex.com/v1/foo/bar"
        actual = self.client.url_for('foo/%s', path_arg="bar")
        self.assertEqual(expected, actual)


    def test_should_have_url_with_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo?a=1&b=2"
        actual = self.client.url_for('foo', parameters={'a': 1, 'b': 2})
        self.assertEqual(expected, actual)


    def test_should_have_url_for(self):
        expected = self.client.url_for("foo")
        self.assertEqual("https://api.bitfinex.com/v1/foo", expected)


    def test_should_have_url_for_with_path_arg(self):
        expected = "https://api.bitfinex.com/v1/foo/bar"
        path = "foo/%s"
        self.assertEqual(expected, self.client.url_for(path, path_arg='bar'))
        self.assertEqual(expected, self.client.url_for(path, 'bar'))


    def test_should_have_url_for_with_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo?a=1"
        self.assertEqual(expected, self.client.url_for("foo", parameters={'a': 1}))
        self.assertEqual(expected, self.client.url_for("foo", None, {'a': 1}))


    def test_should_have_url_for_with_path_arg_and_parameters(self):
        expected = "https://api.bitfinex.com/v1/foo/bar?a=1"
        path = "foo/%s"
        self.assertEqual(expected, self.client.url_for(path, path_arg='bar', parameters={'a': 1}))
        self.assertEqual(expected, self.client.url_for(path, 'bar', {'a': 1}))


    @httpretty.activate
    def test_should_have_symbols(self):
        # mock out the request
        mock_body = '["btcusd","ltcusd","ltcbtc"]'
        url = self.client.url_for('symbols')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = ["btcusd","ltcusd","ltcbtc"]
        self.assertEqual(expected, self.client.symbols())


    @httpretty.activate
    def test_should_have_ticker(self):
        # mock out the request
        mock_body = '{"mid":"562.56495","bid":"562.15","ask":"562.9799","last_price":"562.25","timestamp":"1395552658.339936691"}'
        url = self.client.url_for('ticker/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "mid": 562.56495,
            "bid": 562.15,
            "ask": 562.9799,
            "last_price": 562.25,
            "timestamp": 1395552658.339936691
        }

        self.assertEqual(expected, self.client.ticker('btcusd'))


    @httpretty.activate
    def test_should_have_today(self):
        # mock out the request
        mock_body = '{"low":"550.09","high":"572.2398","volume":"7305.33119836"}'
        url = self.client.url_for('today/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "low": 550.09,
            "high": 572.2398,
            "volume": 7305.33119836
        }

        self.assertEqual(expected, self.client.today('btcusd'))


    @httpretty.activate
    def test_should_have_stats(self):
        # mock out the request
        mock_body = '[{"period":1,"volume":"7410.27250155"},{"period":7,"volume":"52251.37118006"},{"period":30,"volume":"464505.07753251"}]'
        url = self.client.url_for('stats/%s', path_arg='btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = [
            {"period": 1, "volume": 7410.27250155},
            {"period": 7, "volume": 52251.37118006},
            {"period": 30,"volume": 464505.07753251}
        ]

        self.assertEqual(expected, self.client.stats('btcusd'))


    @httpretty.activate
    def test_should_have_lendbook(self):
        # mock out the request
        mock_body = '{"bids":[{"rate":"5.475","amount":"15.03894663","period":30,"timestamp":"1395112149.0","frr":"No"},{"rate":"2.409","amount":"14.5121868","period":7,"timestamp":"1395497599.0","frr":"No"}],"asks":[{"rate":"6.351","amount":"15.5180735","period":5,"timestamp":"1395549996.0","frr":"No"},{"rate":"6.3588","amount":"626.94808249","period":30,"timestamp":"1395400654.0","frr":"Yes"}]}'
        url = self.client.url_for('lendbook/%s', 'btc')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [
                {"rate": 5.475, "amount": 15.03894663, "period": 30, "timestamp": 1395112149.0, "frr": False},
                {"rate": 2.409, "amount": 14.5121868, "period": 7, "timestamp": 1395497599.0, "frr": False}
            ],
            "asks": [
                {"rate": 6.351, "amount": 15.5180735, "period": 5, "timestamp": 1395549996.0, "frr": False},
                {"rate": 6.3588, "amount": 626.94808249, "period": 30, "timestamp": 1395400654.0, "frr": True}
            ]
        }

        self.assertEqual(expected, self.client.lendbook('btc'))


    @httpretty.activate
    def test_should_have_lendbook_with_parameters(self):
        # mock out the request
        mock_body = '{"bids":[{"rate":"5.475","amount":"15.03894663","period":30,"timestamp":"1395112149.0","frr":"No"},{"rate":"2.409","amount":"14.5121868","period":7,"timestamp":"1395497599.0","frr":"No"}],"asks":[]}'
        parameters = {'limit_bids': 2, 'limit_asks': 0}
        url = self.client.url_for('lendbook/%s', 'btc', parameters)
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [
                {"rate": 5.475, "amount": 15.03894663, "period": 30, "timestamp": 1395112149.0, "frr": False},
                {"rate": 2.409, "amount": 14.5121868, "period": 7, "timestamp": 1395497599.0, "frr": False}
            ],
            "asks": [
            ]
        }

        self.assertEqual(expected, self.client.lendbook('btc', parameters))


    @httpretty.activate
    def test_should_have_order_book(self):
        # mock out the request
        mock_body = '{"bids":[{"price":"562.2601","amount":"0.985","timestamp":"1395567556.0"}],"asks":[{"price":"563.001","amount":"0.3","timestamp":"1395532200.0"}]}'
        url = self.client.url_for('book/%s', 'btcusd')
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [
                {"price": 562.2601, "amount": 0.985, "timestamp": 1395567556.0}
            ],
            "asks": [
                {"price": 563.001, "amount": 0.3, "timestamp": 1395532200.0}
            ]
        }

        self.assertEqual(expected, self.client.order_book('btcusd'))


    @httpretty.activate
    def test_should_have_order_book_with_parameters(self):
        # mock out the request
        mock_body = '{"bids":[{"price":"562.2601","amount":"0.985","timestamp":"1395567556.0"}],"asks":[]}'
        parameters = {'limit_asks': 0}
        url = self.client.url_for('book/%s', 'btcusd', parameters)
        httpretty.register_uri(httpretty.GET, url, body=mock_body, status=200)

        expected = {
            "bids": [
                {"price": 562.2601, "amount": 0.985, "timestamp": 1395567556.0}
            ],
            "asks": []
        }

        self.assertEqual(expected, self.client.order_book('btcusd', parameters))
예제 #17
0
 def setUp(self):
     self.client = Client()
예제 #18
0
from sqlalchemy import *
import time
import numpy as np
from decimal import Decimal
# using bitfinex APIs to get today's_ticker
from bitfinex.client import Client, TradeClient
client = Client()
trade = TradeClient('K4HJultQmdvroWCnNy5OMcXx7QfGoQgZw0vrkWmuV1Y',
                    'dFt4tsMFszh2vTGGvHqFEP3fkaaSniJ4zDA4pSWyJOM')

# we are inporting the Databse that is being created by bitfinex-boat

engine = create_engine('sqlite:////home/metal-machine/Desktop/all_ticker.db')
metadata = MetaData(engine)
tickers = Table('ticker', metadata, autoload=True)


def find_nearest(array, value):
    """ gets the numpy array and timestamp as input and retunrs the nearest value"""

    idx = np.abs(array - value).argmin()
    return array[idx]


def ohlc_past(hours):
    """This function returns the seconds as input and retrun the required ohlc_4"""

    seconds = 3600 * hours  # converting hours into seconds
    time_delta = float('{:7f}'.format(time.time() - seconds))
    time_stamp = tickers.select(tickers.c.timestamp)
    timestamp_array = np.array([i[1] for i in time_stamp.execute()])