Пример #1
0
def get_stats():
	coin = CoinbaseExchange()

	start = datetime.datetime(2016, 1, 1)
	end = datetime.datetime(2016, 6, 10)
	gran = 60 * 60 * 24

	stats = coin.getProductHistoricRates(start.isoformat(), end.isoformat(), gran)

	return stats
Пример #2
0
class TestCBEPublic(unittest.TestCase):
    def setUp(self):
        self.cbe = CoinbaseExchange()

    def test_getProducts(self):
        with my_vcr.use_cassette('public-getProducts.json'):
            correct = [{
                u'quote_currency': u'USD',
                u'display_name': u'BTC/USD',
                u'quote_increment': 0.01,
                u'base_max_size': 10000,
                u'base_currency': u'BTC',
                u'id': u'BTC-USD',
                u'base_min_size': 0.01
            }]
            self.assertEqual(self.cbe.getProducts(), correct)

    def test_getProductOrderBook_1(self):
        with my_vcr.use_cassette('public-getProductOrderBook-1.json'):
            correct = 10306972
            self.assertEqual(
                self.cbe.getProductOrderBook(level=1)['sequence'], correct)

    def test_getProductOrderBook_2(self):
        with my_vcr.use_cassette('public-getProductOrderBook-2.json'):
            correct = 10306974
            self.assertEqual(
                self.cbe.getProductOrderBook(level=2)['sequence'], correct)

    def test_getProductOrderBook_3(self):
        with my_vcr.use_cassette('public-getProductOrderBook-3.json'):
            correct = 10306989
            self.assertEqual(
                self.cbe.getProductOrderBook(level=3)['sequence'], correct)

    def test_getProductTicker(self):
        with my_vcr.use_cassette('public-getProductTicker.json'):
            correct = 220334
            self.assertEqual(self.cbe.getProductTicker()['trade_id'], correct)

    def test_getProductTrades(self):
        with my_vcr.use_cassette('public-getProductTrades.json'):
            correct = u'2015-02-15 18:59:44.240795+00'
            self.assertEqual(self.cbe.getProductTrades()[0]['time'], correct)

    def test_getProductStats(self):
        with my_vcr.use_cassette('public-getProductStats.json'):
            correct = u'19382.09151854'
            self.assertEqual(self.cbe.getProductStats()['volume'], correct)

    def test_getCurrencies(self):
        with my_vcr.use_cassette('public-getCurrencies.json'):
            correct = "USD"
            self.assertEqual(self.cbe.getCurrencies()[0]['id'], correct)

    def test_getTime(self):
        with my_vcr.use_cassette('public-getTime.json'):
            correct = 1424034007.831
            self.assertEqual(self.cbe.getTime()['epoch'], correct)
class TestCBEUtils(unittest.TestCase):
	def setUp(self):
		self.cbe = CoinbaseExchange()

	def test_convertTimeToPython(self):
		json_return = u'2015-02-15 18:59:44.240795+00'
		python_time = pytz.utc.localize( datetime(year=2015, month=2, day=15, hour=18, minute=59, second=44, microsecond=240795) )
		self.assertEqual( ConvertTime(json_return), python_time )

	def test_injectPythonTimes(self):
		with my_vcr.use_cassette('public-getProductTrades-Time.json'):
			python_time = ConvertTime( self.cbe.getProductTrades()[0]['time'] )
			self.assertEqual( self.cbe.getProductTrades()[0]['python_time'], python_time )
class TestCBEPublic(unittest.TestCase):
	def setUp(self):
		self.cbe = CoinbaseExchange()

	def test_getProducts(self):
		with my_vcr.use_cassette('public-getProducts.json'):
			correct = [{u'quote_currency': u'USD', u'display_name': u'BTC/USD', u'quote_increment': 0.01, u'base_max_size': 10000, u'base_currency': u'BTC', u'id': u'BTC-USD', u'base_min_size': 0.01}]
			self.assertEqual( self.cbe.getProducts(), correct )

	def test_getProductOrderBook_1(self):
		with my_vcr.use_cassette('public-getProductOrderBook-1.json'):
			correct = 10306972
			self.assertEqual( self.cbe.getProductOrderBook(level=1)['sequence'], correct )

	def test_getProductOrderBook_2(self):
		with my_vcr.use_cassette('public-getProductOrderBook-2.json'):
			correct = 10306974
			self.assertEqual( self.cbe.getProductOrderBook(level=2)['sequence'], correct )

	def test_getProductOrderBook_3(self):
		with my_vcr.use_cassette('public-getProductOrderBook-3.json'):
			correct = 10306989
			self.assertEqual( self.cbe.getProductOrderBook(level=3)['sequence'], correct )
					
	def test_getProductTicker(self):
		with my_vcr.use_cassette('public-getProductTicker.json'):
			correct = 220334
			self.assertEqual( self.cbe.getProductTicker()['trade_id'], correct )

	def test_getProductTrades(self):
		with my_vcr.use_cassette('public-getProductTrades.json'):
			correct = u'2015-02-15 18:59:44.240795+00'
			self.assertEqual( self.cbe.getProductTrades()[0]['time'], correct )

	def test_getProductStats(self):
		with my_vcr.use_cassette('public-getProductStats.json'):
			correct = u'19382.09151854'
			self.assertEqual( self.cbe.getProductStats()['volume'], correct)

	def test_getCurrencies(self):
		with my_vcr.use_cassette('public-getCurrencies.json'):
			correct = "USD"
			self.assertEqual( self.cbe.getCurrencies()[0]['id'], correct )

	def test_getTime(self):
		with my_vcr.use_cassette('public-getTime.json'):
			correct = 1424034007.831
			self.assertEqual( self.cbe.getTime()['epoch'], correct )
Пример #5
0
class TestCBEUtils(unittest.TestCase):
    def setUp(self):
        self.cbe = CoinbaseExchange()

    def test_convertTimeToPython(self):
        json_return = u'2015-02-15 18:59:44.240795+00'
        python_time = pytz.utc.localize(
            datetime(year=2015,
                     month=2,
                     day=15,
                     hour=18,
                     minute=59,
                     second=44,
                     microsecond=240795))
        self.assertEqual(ConvertTime(json_return), python_time)

    def test_injectPythonTimes(self):
        with my_vcr.use_cassette('public-getProductTrades-Time.json'):
            python_time = ConvertTime(self.cbe.getProductTrades()[0]['time'])
            self.assertEqual(self.cbe.getProductTrades()[0]['python_time'],
                             python_time)
	def setUp(self):
		self.cbe = CoinbaseExchange()
from cbe import CoinbaseExchange
import json
import numpy as np
import pandas as pd
import time as timer
from datetime import datetime
from dateutil.relativedelta import *
from sklearn.externals import joblib
model = joblib.load('sgd_simple.pkl')
# simple and naive algorithm that assumes you start with one btc and
# must then sell high and buy low in order to profit.
cb = CoinbaseExchange()



price = []
time = []
prediction = 0.0
starttime=timer.time()
buy = False
sell = False
hold = False
bought_at = 0
sold_at = 0
profit = 0
total_profit = 0
sell_price = 0
num_buy = 0
num_sell = 0

# depends on the last 360 ten second ticks, so we need to get that data
Пример #8
0
#naive program to test model
from cbe import CoinbaseExchange
import json
import numpy as np
import pandas as pd
import time as timer
from sklearn.externals import joblib
model = joblib.load('brr_simple.pkl')

cb = CoinbaseExchange()

json_ticker = cb.getProductTicker()

price = []
time = []
prediction = 0.0
starttime=timer.time()
buy = False
sell = False
hold = False
profit = 0
total_profit = 0
sell_price = 0
num_buy = 1
num_sell = 0

#this will need to be own subprocess or method
while True:
    json_ticker = cb.getProductTicker()
    actual = float(json_ticker['price'])
Пример #9
0
 def setUp(self):
     self.cbe = CoinbaseExchange()