Skip to content

Commit

Permalink
api v2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
delta575 committed Apr 28, 2017
1 parent b0b660d commit 47a5efb
Show file tree
Hide file tree
Showing 13 changed files with 874 additions and 281 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ Rename .env.example > .env

## Usage

Setup (ApiKey/Secret requiered):
###Setup Public:

from surbtc import SURBTC
client = SURBTC(API_KEY, API_SECRET)
client = SURBTC.Public()

Market Pairs:
###Setup Auth (ApiKey/Secret requiered, Test is optional (default: False)):

from surbtc import SURBTC
client = SURBTC.Auth(API_KEY, API_SECRET, TEST)

## Market Pairs:

btc-clp
btc-cop
Expand Down
4 changes: 2 additions & 2 deletions requierements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
coverage==4.3
coverage==4.3.4
python-decouple==3.0
requests==2.12.4
requests==2.13.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='surbtc',
version='0.1.0',
version='0.2.0',
description='SURBTC API Wrapper for Python 3',
url='https://github.com/delta575/python-surbtc-api',
author='Felipe Aránguiz, Sebastian Aránguiz',
Expand Down
28 changes: 26 additions & 2 deletions surbtc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
from .client import SURBTC
from . import constants as _c
from . import models as _m
from .client_auth import SURBTCAuth
from .client_public import SURBTCPublic

__all__ = SURBTC

class SURBTC(object):
# Models
models = _m
# Enum Types
BalanceEvent = _c.BalanceEvent
Currency = _c.Currency
Market = _c.Market
OrderState = _c.OrderState
OrderType = _c.OrderType
OrderPriceType = _c.OrderPriceType
QuotationType = _c.QuotationType
ReportType = _c.ReportType
# Clients
Auth = SURBTCAuth
Public = SURBTCPublic


__all__ = [
SURBTCAuth,
SURBTCPublic,
]
26 changes: 18 additions & 8 deletions surbtc/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import json
from urllib.parse import urlparse

# pip
import requests
# local
from .common import (check_response,
log_request_exception,
log_json_decode)
from .common import (check_response, log_json_decode,
log_request_exception)


class Server(object):

def __init__(self, protocol, host, version=None):
url = '{0:s}://{1:s}'.format(protocol, host)
if version:
Expand All @@ -21,6 +22,7 @@ def __init__(self, protocol, host, version=None):


class Client(object):

def __init__(self, server: Server, timeout=30):
self.SERVER = server
self.TIMEOUT = timeout
Expand All @@ -42,17 +44,25 @@ def post(self, url, headers, data):

def _request(self, method, url, headers, params=None, data=None):
try:
data = json.dumps(data) if data else data
data = self._encode_data(data)
response = requests.request(
method, url, headers=headers, params=params, data=data,
verify=True, timeout=self.TIMEOUT
)
method,
url,
headers=headers,
params=params,
data=data,
verify=True,
timeout=self.TIMEOUT)
response.raise_for_status()
return response
except requests.exceptions.RequestException as err:
log_request_exception(err)
raise

def _encode_data(self, data):
data = json.dumps(data) if data else data
return data

def _resp_to_json(self, response):
try:
json_resp = response.json()
Expand All @@ -71,4 +81,4 @@ def url_for(self, path, path_arg=None):
def url_path_for(self, path, path_arg=None):
url = self.url_for(path, path_arg)
path = urlparse(url).path
return url, path
return url, path
207 changes: 0 additions & 207 deletions surbtc/client.py

This file was deleted.

Loading

0 comments on commit 47a5efb

Please sign in to comment.