Skip to content

Commit

Permalink
Added direct calls, changed code of conduct, added some to API and fi…
Browse files Browse the repository at this point in the history
…xed .json issues.
  • Loading branch information
EmersonDove committed Mar 23, 2021
1 parent 94f82f2 commit 6a9841b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
13 changes: 8 additions & 5 deletions Blankly/API_Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def __init__(self, exchange_name, authenticated_API):
self.__calls = authenticated_API
self.__ticker_manager = None

def get_calls(self):
return self.__calls

"""
Get all currencies in an account
"""
Expand Down Expand Up @@ -62,7 +65,7 @@ def market_order(self, product_id, side, funds, **kwargs):
return Purchase(order, response,
self.__ticker_manager.get_ticker(product_id, override_default_exchange_name="coinbase_pro"))

def limit_order(self, size, price, side, id, ):
def limit_order(self, size, price, side, id):
"""
Used for buying or selling limit orders
"""
Expand Down Expand Up @@ -107,8 +110,8 @@ def get_product_history(self, product_id, epoch_start, epoch_stop, granularity):
while need > 300:
# Close is always 300 points ahead
window_close = window_open + 300 * granularity
open_iso = self.__utils.ISO8601_from_epoch(window_open)
close_iso = self.__utils.ISO8601_from_epoch(window_close)
open_iso = Blankly.Utils.ISO8601_from_epoch(window_open)
close_iso = Blankly.Utils.ISO8601_from_epoch(window_close)
# output = self.__calls.get_product_historic_rates(product_id, open_iso, close_iso, granularity)
history = history + self.__calls.get_product_historic_rates(product_id, open_iso, close_iso,
granularity)
Expand All @@ -118,8 +121,8 @@ def get_product_history(self, product_id, epoch_start, epoch_stop, granularity):
time.sleep(1)

# Fill the remainder
open_iso = self.__utils.ISO8601_from_epoch(window_open)
close_iso = self.__utils.ISO8601_from_epoch(epoch_stop)
open_iso = Blankly.Utils.ISO8601_from_epoch(window_open)
close_iso = Blankly.Utils.ISO8601_from_epoch(epoch_stop)
return history + self.__calls.get_product_historic_rates(product_id, open_iso, close_iso, granularity)

# def create_ticker(self, callback, currency_id, log=''):
Expand Down
2 changes: 2 additions & 0 deletions Blankly/BlanklyBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self):
self.coin_id = ""
self.default_ticker = None
self.Ticker_Manager = None
self.direct_calls = None
self.process = Process(target=self.main)

def setup(self, exchange_type, coin, coin_id, user_preferences, initial_state, interface):
Expand All @@ -57,6 +58,7 @@ def setup(self, exchange_type, coin, coin_id, user_preferences, initial_state, i
self.Interface = interface
# Coin id is the currency and which market its on
self.coin_id = coin_id
self.direct_calls = interface.get_calls()

# Create the ticker for this kind of currency. Callbacks will occur in the "price_event" function
self.Ticker_Manager = Blankly.TickerManager(self.exchange_type)
Expand Down
17 changes: 12 additions & 5 deletions Blankly/Coinbase_Pro/Coinbase_Pro_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def get_account(self, account_id):
"currency": "USD"
}
"""
return requests.get(self.__api_url + 'accounts/' + account_id, auth=self.__auth)
return requests.get(self.__api_url + 'accounts/' + account_id, auth=self.__auth).json()

""" PAGINATED """
def get_account_history(self, account_id, **kwargs):
Expand Down Expand Up @@ -485,7 +485,7 @@ def place_order(self, product_id, side, order_type, **kwargs):
'side': side,
'type': order_type}
params.update(kwargs)
return requests.post(self.__api_url + 'orders', data=json.dumps(params), auth=self.__auth)
return requests.post(self.__api_url + 'orders', data=json.dumps(params), auth=self.__auth).json()


def place_limit_order(self, product_id, side, price, size,
Expand Down Expand Up @@ -909,7 +909,7 @@ def create_report(self, report_type, start_date, end_date, product_id=None,
params['account_id'] = account_id
if email is not None:
params['email'] = email
return requests.post(self.__api_url + "reports", data=json.dumps(params), auth=self.__auth)
return requests.post(self.__api_url + "reports", data=json.dumps(params), auth=self.__auth).json()

def get_report(self, report_id):
""" Get report status.
Expand All @@ -923,7 +923,7 @@ def get_report(self, report_id):
dict: Report details, including file url once it is created.
"""
return requests.get(self.__api_url + "reports/" + report_id, auth=self.__auth)
return requests.get(self.__api_url + "reports/" + report_id, auth=self.__auth).json()

def get_trailing_volume(self):
""" Get your 30-day trailing volume for all products.
Expand All @@ -945,10 +945,17 @@ def get_trailing_volume(self):
]
"""
return requests.get(self.__api_url + "users/self/trailing-volume", auth=self.__auth)
return requests.get(self.__api_url + "users/self/trailing-volume", auth=self.__auth).json()

def get_coinbase_accounts(self):
""" Get a list of your coinbase accounts.
Returns:
list: Coinbase account details.
"""
print(self.__api_url)
return requests.get(self.__api_url + 'coinbase-accounts', auth=self.__auth).json()



Expand Down
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ threatening, offensive, or harmful.

Project maintainers have the right and responsibility to immediately remove
without any sort of dispute any issues or pull requests that do not align
with their corresponding templates. Absolutely no leniancy shall be accepted
with their corresponding templates. Absolutely no leniency shall be accepted
with these terms.

## Scope
Expand All @@ -62,7 +62,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
reported by contacting the project team at #TODO. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
9 changes: 8 additions & 1 deletion Examples/Basic_Bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ def main(self, args=None):

# Example on how to interact with API
# print(self.Interface.get_product_history(self.coin_id, 1611029486, 1616123507, 10000))
print(self.Interface.get_fees())
print("Interface call: " + str(self.Interface.get_fees()))

# You can also bypass the interface and make calls directly to the exchange:
try:
# Because this is direct, some exchanges have different commands, so this demo is wrapped in try/except
print("Direct call: " + str(self.direct_calls.get_fees()))
except AttributeError:
print("Chosen exchange doesn't have that function")

while True:
# This demonstrates a way to change the state. The default script just reports the state on this currency.
Expand Down

0 comments on commit 6a9841b

Please sign in to comment.