-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from sndmndss/simulations
Add new simulated features
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from bpx.public import Public | ||
|
||
default_public: Public = Public() | ||
|
||
|
||
def get_volume(filled_orders: list[dict]) -> float | int: | ||
prices = [float(item['price']) * float(item["quantity"]) for item in filled_orders] | ||
return sum(prices) | ||
|
||
|
||
def get_fees(filled_orders: list[dict]) -> float | int: | ||
fees = [float(item['price']) * float(item["fee"]) | ||
if item["feeSymbol"] != 'USDC' else float(item["fee"]) for item in filled_orders] | ||
return sum(fees) | ||
|
||
|
||
def get_approximate_balance_in_usdc(balance: dict, | ||
time_interval: str = "1m", | ||
public: Public = default_public) -> float: | ||
usdc_symbol = "USDC" | ||
balance_usdc = 0 | ||
close_price = 0 | ||
for symbol in balance: | ||
if symbol != usdc_symbol: | ||
k_lines = public.get_klines(f"{symbol}_{usdc_symbol}", time_interval) | ||
close_price = float(k_lines[-1]['close']) | ||
|
||
for status in balance[symbol]: | ||
if symbol == usdc_symbol: | ||
balance_usdc += float(balance[symbol][status]) | ||
else: | ||
balance_usdc += float(balance[symbol][status]) * close_price | ||
return balance_usdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from bpx.simulations import * | ||
from bpx.account import Account | ||
from bpx.public import Public | ||
|
||
|
||
public_key = "<KEY>" | ||
secret_key = "<KEY>" | ||
|
||
|
||
account = Account(public_key, secret_key, debug=True) | ||
|
||
fills = account.get_fill_history_query("SOL_USDC", limit=1000) | ||
print(get_fees(fills)) | ||
print(get_volume(fills)) | ||
|
||
|
||
balance = account.get_balances() | ||
print(get_approximate_balance_in_usdc(balance)) |