Esempio n. 1
0
    def test_order_info(self):
        """Test the order_info method"""

        kraken = Kraken()

        # Get a closed order id.
        closed_order_file = os.path.join(DATA_DIR, 'kraken', 'closed-order-id')
        if os.path.exists(closed_order_file):
            with open(closed_order_file) as f:
                order_id = f.readline().rstrip()
        else:
            raise IOError('Testing the order_info method requires an order '
                          'id. Plead add a closed order id to the file '
                          '\'exchanges/data/kraken/closed-order-id\'.')

        # If the API keys are not set, we cannot query
        # private user data.
        key = kraken.public_key
        kraken.public_key = None
        self.assertRaises(ValueError, kraken.order_info, order_id)
        kraken.public_key = key
        time.sleep(3)

        # Get the information about some order. Verify that the
        # status is closed.
        # TODO: More in depth validation once we define what an
        # OrderInformation should contain.
        order_info = kraken.order_info(order_id)
        self.assertTrue(isinstance(order_info, OrderInformation))
        self.assertEqual(order_info.status, 'closed')
        time.sleep(3)
Esempio n. 2
0
    def test_latest_ticker(self):
        """Test the latest_ticker method"""

        kraken = Kraken()

        # Get the latest trade. I cannot find a way to validate
        # the result, so I just assume that if it returns a
        # trade everything is ok.
        trade = kraken.latest_trade('XETHZEUR')
        self.assertTrue(isinstance(trade, Trade))

        time.sleep(3)

        # Querying a non existent asset pair should fail.
        self.assertRaises(RuntimeError, lambda: kraken.latest_trade('FAKE'))
Esempio n. 3
0
    def test_server_time(self):
        """Test the server_time method"""

        # On a normal query, the time should be close to the
        # current time. There is a lot of jitter on the time
        # returned by the server, so we judge that a
        # difference of 1 minute is ok.
        kraken = Kraken()
        server_time = kraken.server_time()
        current_time = time.time()
        self.assertTrue(abs(server_time - current_time) < 60)

        time.sleep(3)

        # Set the timeout limit to a very low value to be
        # sure it is raised.
        kraken.timeout = 1e-16
        self.assertRaises(Timeout, kraken.server_time)
        kraken.timeout = 5.0

        time.sleep(3)

        # Change the url to get and HTTP error.
        kraken.url = kraken.url[:-1]
        self.assertRaises(HTTPError, kraken.server_time)
Esempio n. 4
0
    def test_trades_history(self):
        """Test the trades_history method"""

        kraken = Kraken()

        asset = 'XXBTZEUR'
        since = 1470092400  # 2016-08-02 01:00:00 - unix timestamp
        trades_history = kraken.trades_history(asset, since)

        # The first was filled shortly after 'since'
        tolerance = 10  # 10ms in unix timestamp
        self.assertTrue(trades_history[0].time - since < tolerance)
        self.assertEqual(len(trades_history), 1000)

        # The rest are ordered
        for i, trade in enumerate(trades_history[1:], 1):
            self.assertTrue(trade.time > trades_history[i - 1].time)

        # By looking at /Trades?pair=XXBTZEUR&since=1470092400000000000
        # in a web browser we can create a specific test with only
        # 3 orders between 'since' and 'until'
        until = 1470092421.1177
        gt_prices_volumes = [(538.05000, 1.07597000), (538.05000, 0.00020000),
                             (538.05000, 0.05610236)]
        trades_history = kraken.trades_history(asset, since, until)
        for i, trade in enumerate(trades_history):
            self.assertEqual(trade.asset_pair, asset)
            self.assertEqual(trade.price, gt_prices_volumes[i][0])
            self.assertEqual(trade.volume, gt_prices_volumes[i][1])

        until = 1470150000  # 16hs of diff.
        trades_history = kraken.trades_history(asset, since, until)

        # First and last within boundaries
        self.assertTrue(len(trades_history) > 1000)
        self.assertTrue(trades_history[0].time - since < tolerance)
        self.assertTrue(until - trades_history[-1].time < tolerance)

        # The rest are ordered
        for i, trade in enumerate(trades_history[1:], 1):
            self.assertTrue(trade.time > trades_history[i - 1].time)

        time.sleep(1)

        # Querying a non existent asset pair should fail.
        self.assertRaises(RuntimeError,
                          lambda: kraken.trades_history('FAKE', 123456))
Esempio n. 5
0
from exchanges import Kraken, Bitstamp, Bitfinex
import numpy as np
import matplotlib.pyplot as plt
import time
import csv

k = Kraken()
B = Bitstamp()
Bf = Bitfinex()

#read all data:
data = []
with open("ticker.csv") as csvfile:
    readCSV = csv.reader(csvfile, delimiter=',')
    for out in readCSV:
        data.append(out)

data = data[-250:-1]
bitst = []
krak = []
bitfi = []
x = []
for row in data:
    krak.append(float(row[1]))
    bitst.append(float(row[2]))
    bitfi.append(float(row[3]))
    x.append(float(row[0]))

if len(data) < 10:
    print 'too little data, need at least 100 entries... exiting...'
    #exit()
Esempio n. 6
0
from exchanges import Kraken, Bitstamp, Bitfinex, Poloniex, Bittrex
import requests as req
import json as json

kraken = Kraken()
bitstamp = Bitstamp()
bitfinex = Bitfinex()
poloniex = Poloniex()
bittrex = Bittrex()
#print(kraken.availableTickers)
#print(kraken.pairsByTicker)
#print(bitstamp.availableTickers)
#print(bitfinex.availableTickers)
#print(poloniex.availableTickers)
#print(bittrex.availableTickers)
print(kraken.getCurrentPrice("BTC", "ETH"))
print(bitstamp.getCurrentPrice("BTC", "ETH"))
print(bitfinex.getCurrentPrice("BTC", "ETH"))
print(poloniex.getCurrentPrice("BTC", "ETH"))
print(bittrex.getCurrentPrice("BTC", "ETH"))
Esempio n. 7
0
import hmac
import hashlib
import time
import websocket
import json
import csv
import ssl
from exchanges import CrossPairings, Kraken, Bitstamp, Bitfinex, Poloniex, Bittrex

kraken = Kraken()
bitstamp = Bitstamp()
bitfinex = Bitfinex()
poloniex = Poloniex()
bittrex = Bittrex()

exchangesDict = {
    "Kraken": kraken,
    "Bitstamp": bitstamp,
    "Bitfinex": bitfinex,
    "Poloniex": poloniex,
    "Bittrex": bittrex
}
crossPairing = CrossPairings()
crossPairing.addExchanges(exchangesDict)
exchanges = crossPairing.getExchanges("BTC", "USD")

#with open("trado2.csv", 'a') as fp:
#	while True:
#		for exch in exchanges:
#			a = csv.writer(fp, delimiter=',')
#			a.writerow([time.time(), exch, exchangesDict[exch].getCurrentPrice("BTC","USD")])
Esempio n. 8
0
from exchanges import Kraken, Bitstamp, Bitfinex
import numpy as np
import matplotlib.pyplot as plt
import time
import csv
import random
import operator

k = Kraken()
B = Bitstamp()
Bf = Bitfinex()

print '\nlogging data... '
print 'press ctrl + c to skip to analysing...'
try:
    while True:
        kp = k.getCurrentPrice('BTC', 'USD')
        Bp = B.getCurrentPrice('BTC', 'USD')
        Bfp = Bf.getCurrentPrice('BTC', 'USD')
        out = [time.time(), kp, Bp, Bfp]
        with open("ticker.csv", 'a') as fp:
            a = csv.writer(fp, delimiter=',')
            a.writerow(out)
        time.sleep(1)  # reduce CPU usage, ticker rarely updates faster than 1s
except KeyboardInterrupt:
    pass
# print 'analysing'
#
# #read all data:
# data=[]
# with open("ticker.csv") as csvfile: