Skip to content

Commit

Permalink
Merge branch 'altmarkets-development-pr' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHolyRoger committed Feb 28, 2021
2 parents 71f9671 + 9ecad98 commit 04daa85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import pandas as pd
import time
from decimal import Decimal
from typing import (
Any,
AsyncIterable,
Expand Down Expand Up @@ -42,13 +43,19 @@ def __init__(self, trading_pairs: List[str]):
super().__init__(trading_pairs)

@classmethod
async def get_last_traded_prices(cls, trading_pairs: List[str]) -> Dict[str, float]:
async def get_last_traded_prices(cls, trading_pairs: List[str]) -> Dict[str, Decimal]:
results = dict()
# Altmarkets rate limit is 100 https requests per 10 seconds
resp_json = await generic_api_request("get", Constants.TICKER_URI)
for trading_pair in trading_pairs:
resp_record = [resp_json[symbol] for symbol in list(resp_json.keys()) if symbol == convert_to_exchange_trading_pair(trading_pair)][0]['ticker']
results[trading_pair] = float(resp_record["last"])
if len(trading_pairs) == 1:
for trading_pair in trading_pairs:
ex_pair = convert_to_exchange_trading_pair(trading_pair)
resp_json = await generic_api_request("get", Constants.TICKER_SINGLE_URI.format(trading_pair=ex_pair))
results[trading_pair] = Decimal(str(resp_json['ticker']["last"]))
else:
resp_json = await generic_api_request("get", Constants.TICKER_URI)
for trading_pair in trading_pairs:
ex_pair = convert_to_exchange_trading_pair(trading_pair)
results[trading_pair] = Decimal(str(resp_json[ex_pair]["ticker"]["last"]))
return results

# Deprecated get_mid_price function - mid price is pulled from order book now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Constants:
TIMESTAMP_URI = "public/timestamp"
SYMBOLS_URI = "public/markets"
TICKER_URI = "public/markets/tickers"
TICKER_SINGLE_URI = "public/markets/{trading_pair}/tickers"
DEPTH_URI = "public/markets/{trading_pair}/depth?limit=300"
# # Private GET
ACCOUNTS_BALANCE_URI = "account/balances"
Expand Down

0 comments on commit 04daa85

Please sign in to comment.