Skip to content

Commit

Permalink
Merge pull request #11 from sndmndss/simulations
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
sndmndss authored Jun 4, 2024
2 parents a8c9a41 + ca460be commit c14ae2a
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
mypyrightconfig.json
14 changes: 7 additions & 7 deletions bpx/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self,
public_key: str,
secret_key: str,
window: int = 5000,
proxy: dict = None,
proxy: dict = {},
debug: bool = False,
default_http_client: SyncHttpClient = http_client
):
Expand All @@ -26,19 +26,19 @@ def get_balances(self, window: int = None):
return self.http_client.get(url, headers=headers)

def get_deposits(self, limit: int = 100, offset: int = 0,
__from: int = None, to: int = None, window: int = None):
from_: int = None, to: int = None, window: int = None):

url, headers, params = super().get_deposits(limit, offset, window, __from, to)
url, headers, params = super().get_deposits(limit, offset, window, from_, to)
return self.http_client.get(url, headers=headers, params=params)

def get_deposit_address(self, blockchain: str, window: int = None):
url, headers, params = super().get_deposit_address(blockchain, window)
return self.http_client.get(url, headers=headers, params=params)

def get_withdrawals(self, limit: int = 100, offset: int = 0,
__from: int = None, to: int = None, window: int = None):
from_: int = None, to: int = None, window: int = None):

url, headers, params = super().get_withdrawals(limit, offset, __from, to, window)
url, headers, params = super().get_withdrawals(limit, offset, from_, to, window)
return self.http_client.get(url, headers=headers, params=params)

def withdrawal(self, address: str,
Expand All @@ -56,13 +56,13 @@ def get_order_history_query(self, symbol: str, limit: int = 100, offset: int = 0
def get_fill_history_query(self, symbol: str,
limit: int = 100,
offset: int = 0,
__from: int = None,
from_: int = None,
to: int = None,
window: int = None):
url, headers, params = super().get_fill_history_query(symbol,
limit,
offset,
__from,
from_,
to,
window)
return self.http_client.get(url, headers=headers, params=params)
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions bpx/__async/account.py → bpx/async_/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ async def get_deposit_address(self, blockchain: str, window: int = None):
return await self.http_client.get(url, headers=headers, params=params)

async def get_withdrawals(self, limit: int = 100, offset: int = 0,
__from: int = None,to: int = None, window: int = None):
from_: int = None,to: int = None, window: int = None):

url, headers, params = super().get_withdrawals(limit, offset, __from, to, window)
url, headers, params = super().get_withdrawals(limit, offset, from_, to, window)
return await self.http_client.get(url, headers=headers, params=params)

async def withdrawal(self, address: str,
Expand All @@ -54,13 +54,13 @@ async def get_order_history_query(self, symbol: str, limit: int = 100, offset: i
async def get_fill_history_query(self, symbol: str,
limit: int = 100,
offset: int = 0,
__from: int = None,
from_: int = None,
to: int = None,
window: int = None):
url, headers, params = super().get_fill_history_query(symbol,
limit,
offset,
__from,
from_,
to,
window)
return await self.http_client.get(url, headers=headers, params=params)
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions bpx/base/base_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_balances(self, window: int):
url = self.BPX_API_URL + 'api/v1/capital'
return url, headers

def get_deposits(self, limit: int, offset: int, window: int, __from=None, to=None):
def get_deposits(self, limit: int, offset: int, window: int, from_=None, to=None):
if limit > 1000 or limit < 0:
raise LimitValueError
if offset < 0:
Expand All @@ -35,8 +35,8 @@ def get_deposits(self, limit: int, offset: int, window: int, __from=None, to=Non
'limit': limit,
'offset': offset,
}
if __from:
params['from'] = __from
if from_:
params['from'] = from_
if to:
params['to'] = to
headers = self._headers(params, 'depositQueryAll', window=window)
Expand All @@ -51,14 +51,14 @@ def get_deposit_address(self, blockchain: str, window: int):
url = self.BPX_API_URL + 'wapi/v1/capital/deposit/address'
return url, headers, params

def get_withdrawals(self, limit: int, offset: int, __from: int, to: int, window: int):
def get_withdrawals(self, limit: int, offset: int, from_: int, to: int, window: int):
if limit > 1000 or limit < 0:
raise LimitValueError
if offset < 0:
raise NegativeValueError(offset)
params = {'limit': limit, 'offset': offset}
if __from:
params['from'] = __from
if from_:
params['from'] = from_
if to:
params['to'] = to
headers = self._headers(params, 'withdrawalQueryAll', window=window)
Expand Down Expand Up @@ -97,7 +97,7 @@ def get_order_history_query(self, symbol: str, limit: int, offset: int, window:
def get_fill_history_query(self, symbol: str,
limit: int,
offset: int,
__from: int,
from_: int,
to: int,
window: int):
if limit > 1000 or limit < 0:
Expand All @@ -109,11 +109,11 @@ def get_fill_history_query(self, symbol: str,
'limit': limit,
'offset': offset,
}
if __from:
if __from < 0:
raise NegativeValueError(__from)
if from_:
if from_ < 0:
raise NegativeValueError(from_)
else:
params['from'] = __from
params['from'] = from_
if to:
if to < 0:
raise NegativeValueError(to)
Expand Down
13 changes: 13 additions & 0 deletions bpx/simulations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bpx.public import Public
import json

default_public: Public = Public()

Expand Down Expand Up @@ -44,3 +45,15 @@ def get_approximate_balance_in_usdc(balance: dict,
else:
balance_usdc += float(balance[symbol][status]) * close_price
return balance_usdc


def save_data_json(data: dict, name: str = "data"):
file_format = ".json"
file_name = name+file_format if file_format not in name else name
with open(file_name, "w") as f:
json.dump(data, f, indent=6)



save_data_json({"me":{"name": "data", "yeh": "mef"}}, "file.json")
save_data_json({"he":{"name": "data", "yeh": "mef"}}, "file.json")
2 changes: 1 addition & 1 deletion examples/async/account_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from bpx.__async.account import Account
from bpx.async_.account import Account
import asyncio

public_key = "<KEY>"
Expand Down
2 changes: 1 addition & 1 deletion examples/async/public_example.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from bpx.__async.public import Public
from bpx.async_.public import Public


async def pubblic_example():
Expand Down
3 changes: 2 additions & 1 deletion examples/public_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def public_example():
depth = public.get_depth("SOL_USDC")
print("Depth for SOL_USDC:", depth)

klines = public.get_klines("SOL_USDC", "1m")
klines_timestamp = 1715692417
klines = public.get_klines("SOL_USDC", "1m", klines_timestamp)
print("K-lines for SOL_USDC:", klines)

status = public.get_status()
Expand Down
135 changes: 134 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bpx-py"
version = "1.1.4"
version = "1.1.5"
description = "Backpack API SDK tool"
authors = ["sndmndss <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -29,6 +29,8 @@ python = "^3.8"
requests = "^2.31.0"
aiohttp = "^3.9.5"
cryptography = "^42.0.5"
pylint = "^3.2.2"
pep8 = "^1.7.1"



Expand Down
Loading

0 comments on commit c14ae2a

Please sign in to comment.