Open NeutronBlast opened 4 months ago
same here
Same issue here when calling bitmex.bitmex(test=False, api_key=bitmex_api_key, api_secret=bitmex_api_secret). My trading bot has open trades and cannot reconnect.
Just to get my thing working I made the request to V1 API manually with requests library given that the only thing that I want to get is BVOL data. Unfortunately, if you're using the SDK for orders or trades this won't help, hopefully it gets resolved soon. Leaving it open.
class Bitmex:
def __init__(self, api_key, api_secret):
self.api_key = api_key
self.api_secret = api_secret
self.exchange_name_tv = 'BITMEX'
@staticmethod
def format_ohlcv(ohlcv_data):
"""
Formats OHLCV (Open, High, Low, Close, Volume) data into a specific structure.
Parameters:
- ohlcv_data (list): List of dictionaries containing OHLCV data.
Returns:
- list: Transformed OHLCV data with specific fields (open, close, high, low, volume, time).
"""
transformed_data = [
{
'open': item['open'],
'close': item['close'],
'high': item['high'],
'low': item['low'],
'volume': item['volume'],
'time': int(datetime.fromisoformat(item['timestamp'].replace('Z', '+00:00')).timestamp() * 1000)
# 'time': int(item['timestamp'].timestamp() * 1000) # Convert to milliseconds
}
for item in ohlcv_data
]
return transformed_data
def get_ohlc(self, ticker, timeframe):
"""
Retrieves OHLCV (Open, High, Low, Close, Volume) data for a specific ticker and timeframe.
Parameters:
- ticker (str): Symbol or identifier of the financial instrument.
- timeframe (str): Timeframe for the OHLCV data (e.g., '1h', '1d').
Returns:
- list: OHLCV data in a specific format after applying formatting.
Example:
[{'open': 100, 'close': 110, 'high': 120, 'low': 90, 'volume': 1000, 'time': 1640995200000},
{'open': 110, 'close': 120, 'high': 130, 'low': 100, 'volume': 1500, 'time': 1641081600000}]
"""
path = 'api/v1/trade/bucketed'
method = "GET"
payload = {
"binSize": f"{timeframe}",
"partial": False,
"symbol": f"{ticker}",
"count": 100,
"reverse": True
}
url = f"{os.getenv('BITMEX_API_URL')}{path}"
try:
response = requests.request(method, url, params=payload, timeout=10)
response = response.json()
return self.format_ohlcv(response)
except (requests.exceptions.ConnectionError, requests.exceptions.JSONDecodeError) as e:
raise ExchangeConnectionError("Failed to establish a connection to Bitmex. There is an error on their "
"end") from e
except (requests.exceptions.ReadTimeout, requests.exceptions.Timeout) as e:
raise ExchangeRequestTimeOut("Connection with Bitmex has timed out") from e
# client = bitmex.bitmex(test=False, api_key=self.api_key, api_secret=self.api_secret)
# result = client.Trade.Trade_getBucketed(binSize=timeframe, symbol=ticker, reverse=True, count=500).result()
# result = self.format_ohlcv(result[0])
Call
class TestBitmex(unittest.TestCase):
def setUp(self):
# Load dotenv and create a Bitmex object
load_dotenv()
self.bitmex = Bitmex(os.getenv('BITMEX_API_KEY'),
os.getenv('BITMEX_API_SECRET'))
def test_get_ohlc(self):
result = self.bitmex.get_ohlc('.BVOL24H', "1d")
print(result)
# print(len(result))
if __name__ == '__main__':
unittest.main()
I have built one you can place orders to and from if useful too
I have built one you can place orders to and from if useful too
I would find that very useful if you are able to share.
I have built one you can place orders to and from if useful too
I would find that very useful if you are able to share.
Try this: https://github.com/henry1034/BitMexRestApi
Don't know how well it works but it does what I need at the moment. I added in @NeutronBlast's data functions too but haven't tested them
I have built one you can place orders to and from if useful too
I would find that very useful if you are able to share.
Try this: https://github.com/henry1034/BitMexRestApi
Don't know how well it works but it does what I need at the moment. I added in @NeutronBlast's data functions too but haven't tested them
Thanks a lot!
Name: 'XBT' is not of type 'number' Description: This error is generated when I'm going to use
Trade_getBucketed
in order to get OHLCV data. I've been using Bitmex API for months and I never had issues with this method but it started generating errors today. This my usage:Call:
Traceback of the error: