Metadata-Version: 2.4
Name: gamegains-sdk
Version: 0.1.3
Summary: Official Python SDK for the GameGains perpetual-futures trading API.
Author: GameGains
License: MIT
Project-URL: repository, https://github.com/Command0e/gamegains-sdk-py.git
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: eth-account>=0.13.0
Requires-Dist: httpcore>=1.0.9
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic<2.13,>=2.11.2
Dynamic: license-file

# GameGains Python SDK

[![PyPI version](https://img.shields.io/pypi/v/gamegains-sdk.svg)](https://pypi.org/project/gamegains-sdk/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Official Python SDK for the [GameGains](https://gamegains.gg) perpetual-futures trading API. HMAC + EIP-712 signing are built in — you provide keys, the SDK signs every request.

```bash
pip install gamegains-sdk
```

## Quickstart

### Public (unauthenticated) data

```python
from gamegains_sdk import GameGains

gg = GameGains(server_url="https://api.gamegains.gg")
info = gg.markets.get_exchange_info()          # chain_id, settlement_address, symbols
price = gg.market_data.get_oracle_price(market="AK47-REDLINE-FT")
print(price.mark_price, price.is_stale)
```

### Authenticated (auto-signed) requests

Every authenticated request is signed with your API **secret** using HMAC-SHA256. Provide the key on the client and the secret via `set_api_secret` (or the `GG_API_SECRET` env var); the SDK's request hook does the rest.

```python
from gamegains_sdk import GameGains, set_api_secret

gg = GameGains(server_url="https://api.gamegains.gg", gg_apikey="gg_pk_...")
set_api_secret("gg_sk_...")                    # shown once at key creation

acct = gg.account.get_account()                # signed automatically
print(acct.collateral.total)
```

## Signing helpers (EIP-712 + cancel intents)

Orders, API keys, and cancels are authorized by your **wallet** signature. The SDK ships the exact signers (byte-identical to the gateway) so a self-custody / linked wallet can sign locally:

```python
from gamegains_sdk import (
    sign_order_intent, sign_api_key_create,
    sign_cancel_intent, sign_cancel_all_intent, sign_amend_intent,
)

info = gg.markets.get_exchange_info()
chain_id, settlement = int(info.chain_id), info.settlement_address

# Place an order
sig = sign_order_intent(
    private_key, chain_id, settlement,
    trader=address, symbol="AK47-REDLINE-FT", side="long", order_type="limit",
    price=30.71, size_usd=100, leverage=2, nonce=nonce, expiry=expiry,
)
# ...pass sig as the order body's `signature` field to gg.orders.create_order(...)

# Close a position: a reduce-only order on the OPPOSITE side, sized to the position
sig = sign_order_intent(..., side="short", order_type="market",
                        price=0, size_usd=position_notional, reduce_only=True)

# Cancel a resting order (linked wallets must pre-sign — see below)
c = sign_cancel_intent(private_key, order_id=order_id)   # -> {"signature", "timestamp"}
```

`sign_cancel_intent` / `sign_cancel_all_intent` / `sign_cancel_batch_intent` produce a `personal_sign` over the raw keccak of the cancel payload — pass the returned `{signature, timestamp}` in the DELETE request body. **Custodial** keys may omit it (the gateway signs); **linked** wallets must supply it.

## Full API reference

See [`docs/`](https://github.com/Command0e/gamegains-sdk-py/blob/master/docs/) for every resource and model. Errors raise `gamegains_sdk.errors.*`; retries and timeouts are configurable per call.

## License

MIT — see [LICENSE](https://github.com/Command0e/gamegains-sdk-py/blob/master/LICENSE).
