Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TradeClient #23

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
56 changes: 51 additions & 5 deletions bitfinex/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/python
#-*- coding: utf-8 -*-

from __future__ import absolute_import
import requests
import json
Expand Down Expand Up @@ -28,7 +31,7 @@ class TradeClient:
"""

def __init__(self, key, secret):
self.URL = "{0:s}://{1:s}/{2:s}".format(PROTOCOL, HOST, VERSION)
self.URL = "%s://%s/%s" % (PROTOCOL, HOST, VERSION)
self.KEY = key
self.SECRET = secret
pass
Expand All @@ -39,7 +42,7 @@ def _nonce(self):
Returns a nonce
Used in authentication
"""
return str(time.time() * 1000000)
return str(int(time.time())* 1000000)

def _sign_payload(self, payload):
j = json.dumps(payload)
Expand Down Expand Up @@ -199,7 +202,7 @@ def claim_position(self, position_id):

return json_resp

def past_trades(self, timestamp=0, symbol='btcusd'):
def past_trades(self, timestamp='0.0', symbol='btcusd'):
"""
Fetch past trades
:param timestamp:
Expand All @@ -221,10 +224,9 @@ def past_trades(self, timestamp=0, symbol='btcusd'):

def place_offer(self, currency, amount, rate, period, direction):
"""

:param currency:
:param amount:
:param rate:
:param anual rate:
:param period:
:param direction:
:return:
Expand Down Expand Up @@ -281,6 +283,24 @@ def status_offer(self, offer_id):

return json_resp


def offers_history(self):
"""

:param offer_id:
:return:
"""
payload = {
"request": "/v1/offers/hist",
"nonce": self._nonce
}

signed_payload = self._sign_payload(payload)
r = requests.post(self.URL + "/offers/hist", headers=signed_payload, verify=True)
json_resp = r.json()

return json_resp

def active_offers(self):
"""
Fetch active_offers
Expand Down Expand Up @@ -340,6 +360,32 @@ def history(self, currency, since=0, until=9999999999, limit=500, wallet='exchan
return json_resp


def movements(self, currency, start=0, end=9999999999, limit=10000, method='bitcoin'):
"""
View you balance ledger entries
:param currency: currency to look for
:param since: Optional. Return only the history after this timestamp.
:param until: Optional. Return only the history before this timestamp.
:param limit: Optional. Limit the number of entries to return. Default is 500.
:param method: Optional. Return only entries that used this method. Accepted inputs are: "bitcoin",
"litecoin", "wire".
"""
payload = {
"request": "/v1/history/movements",
"nonce": self._nonce,
"currency": currency,
"since": start,
"until": end,
"limit": limit,
"method": method
}
signed_payload = self._sign_payload(payload)
r = requests.post(self.URL + "/history/movements", headers=signed_payload, verify=True)
json_resp = r.json()

return json_resp



class Client:
"""
Expand Down