Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fee logging #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ As you can see in this example you have saved $681.90 in fees and spent that ins
* Permissions: "Trading"
0. Copy `settings.conf.example` to `settings.conf`
0. Update the `CLIENT_KEY` and `CLIENT_SECRET` in the `[production]` section.
0. Add fiat to your Gemini account.
0. Add fiat to your Gemini account.

### Sandbox

Expand All @@ -79,7 +79,7 @@ usage: gemini_bot.py [-h] [-s] [-w WARN_AFTER] [-j] [-c CONFIG_FILE] [-l LOGLEVE
BTCUSD BUY 0.00125 BTC (buy 0.00125 BTC)
ETHBTC SELL 0.00125 BTC (sell 0.00125 BTC worth of ETH)
ETHBTC SELL 0.1 ETH (sell 0.1 ETH)


positional arguments:
market_name (e.g. BTCUSD, ETHBTC, etc)
Expand Down Expand Up @@ -107,7 +107,7 @@ You can run this manually for one-off buys or sells.

```
cd gemini_bot
/path/to/gemini_bot/venv/bin/python gemini_bot.py --sandbox BTCUSD BUY 5 BTC
/path/to/gemini_bot/venv/bin/python gemini_bot.py --sandbox BTCUSD BUY 5 USD
```

This will call the sandbox Gemini API to place a "Maker-or-Cancel" buy order for USD$5 worth of Bitcoin.
Expand All @@ -121,7 +121,7 @@ The best way to run this script is via a cronjob as this gives us the Dollar Cos
I would suggest using the full paths to the python venv python, `gemini_bot.py`, and the `settings.conf` file as below. This usually gets around many common cron issues.

```
05 */2 * * * /path/to/geminibot/bot/venv/bin/python gemini_bot.py /path/to/geminibot/bot/gemini_bot.py --config /var/lib/geminibot/bot/settings.conf BTCUSD BUY 5.00 BTC
05 */2 * * * /path/to/geminibot/bot/venv/bin/python gemini_bot.py /path/to/geminibot/bot/gemini_bot.py --config /var/lib/geminibot/bot/settings.conf BTCUSD BUY 5.00 USD
```

This will buy USD$5 worth of BTC every other hour at 5min past the hour.
4 changes: 2 additions & 2 deletions gemini_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def new_order(self, market: str, side: str, amount: Decimal, price: Decimal):
return self._make_authenticated_request("POST", "/order/new", payload=payload)


def order_status(self, order_id: str):
def order_status(self, order_id: str, include_trades: bool):
payload = {
"order_id": order_id,
"include_trades": False,
"include_trades": include_trades,
}
return self._make_authenticated_request("POST", "/order/status", payload=payload)
8 changes: 6 additions & 2 deletions gemini_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ def place_order(price):
)
time.sleep(wait_time)
total_wait_time += wait_time
order = gemini_api_conn.order_status(order_id=order_id)
order = gemini_api_conn.order_status(order_id=order_id, include_trades=True)

# Order status is no longer pending!
trades = order.get("trades")
fee_amount = sum([Decimal(t['fee_amount']) for t in trades])
fee_currency = trades[0]['fee_currency'] # safe, since only one currency was used
logging.info(
f"{market_name} {order_side} order of {amount} {amount_currency} "
f"complete @ {midmarket_price} {quote_currency}"
f"complete @ {midmarket_price} {quote_currency} "
f"fee: {fee_amount} {fee_currency}"
)

sys.exit(0)