Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions 23 btcmarkets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64, hashlib, hmac, urllib2, time, urllib, json
import base64, hashlib, hmac, time, urllib, urllib.request, json
from collections import OrderedDict

base_url = 'https://api.btcmarkets.net'
Expand All @@ -15,20 +15,19 @@ def request(action, key, signature, timestamp, path, data):
'timestamp': timestamp,
}

request = urllib2.Request(base_url + path, data, header)
request = urllib.request.Request(base_url + path, data, header)
if action == 'post':
response = urllib2.urlopen(request, data)
response = urllib.request.urlopen(request, data)
else:
response = urllib2.urlopen(request)
return json.load(response)
response = urllib.request.urlopen(request)
return json.loads(response.read().decode('utf-8'))


def get_request(key, secret, path):

nowInMilisecond = str(int(time.time() * 1000))
stringToSign = path + "\n" + nowInMilisecond + "\n"

signature = base64.b64encode(hmac.new(secret, stringToSign, digestmod=hashlib.sha512).digest())
signature = base64.b64encode(hmac.new(secret, stringToSign.encode('utf-8'), digestmod=hashlib.sha512).digest())

return request('get', key, signature, nowInMilisecond, path, None)

Expand All @@ -50,13 +49,13 @@ def __init__(self, key, secret):
self.secret = base64.b64decode(secret)

def trade_history(self, currency, instrument, limit, since):
data = OrderedDict([('currency', currency),('instrument', instrument),('limit', limit),('since', since)])
postData = json.dumps(data, separators=(',', ':'))
return post_request(self.key, self.secret, '/order/trade/history', postData)

def order_create(self, currency, instrument, price, volume, side, order_type, client_request_id):
data = OrderedDict([('currency', currency),('instrument', instrument),
('price', price),('volume', volume),('orderSide', side),('ordertype', order_type),
('clientRequestId', client_request_id)])
Expand All @@ -65,19 +64,19 @@ def order_create(self, currency, instrument, price, volume, side, order_type, cl


def order_history(self, currency, instrument, limit, since):
data = OrderedDict([('currency', currency),('instrument', instrument),('limit', limit),('since', since)])
postData = json.dumps(data, separators=(',', ':'))
return post_request(self.key, self.secret, '/order/history', postData)

def order_open(self, currency, instrument, limit, since):
data = OrderedDict([('currency', currency),('instrument', instrument),('limit', limit),('since', since)])
postData = json.dumps(data, separators=(',', ':'))
return post_request(self.key, self.secret, '/order/open', postData)

def order_detail(self, order_ids):
data_obj = {'orderIds':order_ids}
data_obj = {'orderIds':order_ids}
postData = json.dumps(data_obj, separators=(',', ':'))
return post_request(self.key, self.secret, '/order/detail', postData)

Expand Down
2 changes: 1 addition & 1 deletion 2 main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

#print client.order_create('AUD', 'LTC', 100000000, 100000000, 'Bid', 'Limit', '1')

print client.get_market_tick('ETH','AUD')
print(client.get_market_tick('ETH','AUD'))

Morty Proxy This is a proxified and sanitized view of the page, visit original site.