:seo_title: Zaif Trading Bot in Python: AI Agent and Algorithmic Trading with LumiBot
.. Generated by scripts/generate_ccxt_exchange_pages.py from docsrc/_data/. Edit the data, not this page.
Zaif Trading Bot in Python
==========================
.. meta::
:description: Build a Zaif trading bot in Python with LumiBot and CCXT. Create Zaif API keys, connect them, and run a regular or AI agent strategy.
:keywords: Zaif trading bot, Zaif API, Zaif Python, agentic trading Zaif, AI trading bot Zaif, algorithmic trading Zaif, ccxt zaif
This guide shows how to build a Zaif trading bot in Python with LumiBot, for both AI agent trading and algorithmic trading. LumiBot connects to Zaif through CCXT, the open source library that talks to more than 100 crypto exchanges. You will create a Zaif account and API key, connect it, and run two examples: a simple algorithmic trading bot and an agentic trading bot where an AI agent makes the calls.
Zaif at a glance
----------------
.. list-table::
:widths: 35 65
* - CCXT exchange id
- ``zaif``
* - Markets
- Spot
* - Testnet (sandbox)
- No
* - Credentials
- API key, API secret
* - Live data streams
- None listed; LumiBot uses REST
* - CCXT request spacing
- about 100 ms between requests
* - Official site
- https://zaif.jp
* - API docs
- https://techbureau-api-document.readthedocs.io/ja/latest/index.html
* - Fees
- https://zaif.jp/fee?lang=en
What is Zaif?
-------------
Zaif is a crypto exchange. It offers an order book exchange, an easy buy and sell desk, coin accumulation plans and automated trading, with prices in yen.
Sign up for Zaif
----------------
#. Create an account with your email address and a strong password, in the Zaif app or browser.
#. Enter your details and finish identity verification as Zaif asks.
#. Set up two-step verification with an authenticator app such as Google Authenticator. Zaif requires it to log in and to manage API keys.
`Open a Zaif account `_
Create a Zaif API key
---------------------
#. Log in to Zaif.
#. Open the API key page (https://zaif.jp/api_keys) from your account information.
#. Create a new key and give it only the rights it needs (see below).
#. Register your bot's IP address under IP address restriction.
#. Confirm with your two-step code, then save the key and secret somewhere safe.
**Which permissions to turn on:** Give the key info and trade rights. Zaif asks you to keep key rights to the minimum and not to grant withdraw unless you really need it, so leave withdraw off. Zaif warns that an API key can trade without the login two-step check, so a leaked key can cause direct losses.
.. warning::
Never turn on withdrawals for a Zaif trading bot key. Bind the key to your server's IP address when Zaif lets you, keep the secret out of your code and out of Git, and delete the key if it ever leaks.
Connect Zaif to LumiBot
-----------------------
The simplest way: put these lines in a ``.env`` file next to your strategy. LumiBot loads the file, sees ``TRADING_BROKER=zaif`` and connects to Zaif for you, so your strategy needs no broker code.
.. code-block:: bash
TRADING_BROKER=zaif
ZAIF_API_KEY=your_apiKey
ZAIF_API_SECRET=your_secret
LumiBot reads exactly the fields CCXT needs for Zaif (``apiKey``, ``secret``). If one is missing, LumiBot stops at start-up and names the variable you still need.
You can also build the broker in code. This is handy when one script talks to more than one exchange, or when you need extra CCXT options. The keys in the config are CCXT's own credential names for Zaif:
.. code-block:: python
import os
ZAIF_CONFIG = {
"exchange_id": "zaif",
"apiKey": os.environ.get("ZAIF_API_KEY"),
"secret": os.environ.get("ZAIF_API_SECRET"),
"sandbox": False, # no sandbox for this exchange
}
from lumibot.brokers import Ccxt
broker = Ccxt(ZAIF_CONFIG)
# then: MyStrategy(broker=broker, ...)
Either way, LumiBot turns on CCXT's built-in rate limiting for you.
Testing on Zaif
---------------
Zaif has no sandbox, so test with a very small amount. With environment variables, leave ``ZAIF_SANDBOX`` unset. In a code config, set ``"sandbox": False``.
Algorithmic trading example: a simple Zaif bot
----------------------------------------------
This bot buys about 15000 JPY of BTC on Zaif once and then holds it. It is a starting point to check that your keys, balances and orders work. If the exchange's minimum order is larger, raise the amount. Zaif accepts only limit orders through CCXT, so the example places a limit order just above the last price.
.. code-block:: python
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class ZaifBuyOnce(Strategy):
"""Buy a small amount of BTC once, then hold it."""
def initialize(self):
self.sleeptime = "1H"
self.set_market("24/7") # crypto trades all day, every day
def on_trading_iteration(self):
coin = Asset("BTC", asset_type=Asset.AssetType.CRYPTO)
if self.get_position(coin) is not None:
return # already holding BTC
price = self.get_last_price(coin, quote=self.quote_asset)
if price:
quantity = round(15000 / price, 6) # about 15000 JPY worth
# This exchange takes only limit orders through CCXT.
order = self.create_order(coin, quantity, "buy", limit_price=price * 1.002, quote=self.quote_asset)
self.submit_order(order)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = ZaifBuyOnce(quote_asset=Asset("JPY", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
Agentic trading example: an AI agent that trades on Zaif
--------------------------------------------------------
Agentic trading means an AI agent reads the market and decides what to do. In this example one LumiBot agent looks at prices and your Zaif account, then places the orders itself. There is no Python logic in between: you set the rules in plain English in the prompt, such as what it may trade and how big each order can be. This follows the same pattern as LumiBot's AI trading team examples.
.. code-block:: python
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class ZaifAITrader(Strategy):
"""One AI agent researches the market and places the trades itself."""
def initialize(self):
self.sleeptime = "4H"
self.set_market("24/7")
self.agents.create(
name="trader",
model="openai/gpt-6-luna",
reasoning_effort="high",
allow_trading=True,
system_prompt=(
"You manage a small crypto account on Zaif. "
"You may trade BTC and ETH against JPY (asset_type 'crypto', quote_symbol 'JPY'), or hold cash. "
"Before every order, call account_portfolio, account_positions and "
"market_last_price for that exact symbol in the same run. "
"Keep each order under 10% of the account value. "
"Explain each decision in one short paragraph."
),
)
def on_trading_iteration(self):
self.agents["trader"].run(
task_prompt="Review recent BTC/JPY and ETH/JPY prices and your current holdings, then decide whether to buy, sell or hold.",
context={"exchange": "Zaif", "quote": "JPY", "date": self.get_datetime().isoformat()},
)
if __name__ == "__main__":
# LumiBot reads TRADING_BROKER and the keys from your .env file.
strategy = ZaifAITrader(quote_asset=Asset("JPY", asset_type=Asset.AssetType.CRYPTO))
strategy.run_live()
The agent needs a model key such as ``OPENAI_API_KEY`` in your environment. See the :doc:`AI agents quickstart ` for models, tools and memory.
What you can trade on Zaif through CCXT
---------------------------------------
.. list-table::
:header-rows: 1
:widths: 40 60
* - Market
- Listed by CCXT
* - Spot
- Yes
* - Margin
- Not listed by CCXT
* - Perpetual swaps
- No
* - Dated futures
- No
* - Options
- No
CCXT lists these order features for Zaif: limit orders, editing open orders, canceling orders.
Zaif tips
---------
* Zaif's API takes limit orders only. Every order needs a price, and Zaif says market orders by API are still under review. Use limit orders in your strategy.
* Zaif's smallest BTC/JPY order is 0.001 BTC (its public API lists this as item_unit_min), so the example uses about 15,000 yen. Keep every BTC order at 0.001 BTC or more.
* Zaif writes pairs like ``btc_jpy``. In LumiBot and CCXT use ``BTC/JPY``.
* Delete keys you no longer use, and change or delete keys when someone with access leaves.
Frequently asked questions
--------------------------
**Can I build a Zaif trading bot in Python?**
Yes. Install LumiBot (``pip install lumibot``), set your Zaif keys and use the ``zaif`` CCXT exchange id as shown above.
**Does Zaif have a testnet?**
No testnet is set up for Zaif in LumiBot. Start with a small amount, and in a code config set ``"sandbox": False``.
**Which API permissions does a Zaif bot need?**
Give the key info and trade rights. Zaif asks you to keep key rights to the minimum and not to grant withdraw unless you really need it, so leave withdraw off. Zaif warns that an API key can trade without the login two-step check, so a leaked key can cause direct losses.
**Can an AI agent trade on Zaif by itself?**
Yes. The agentic example above gives one agent permission to trade. You control what it may trade and how much through its prompt.
**Can I trade Zaif perpetual futures with LumiBot?**
CCXT does not list perpetual swaps for Zaif, so use spot markets.
**Is LumiBot free?**
Yes. LumiBot is open source on GitHub at https://github.com/Lumiwealth/lumibot. You pay only your exchange's trading fees and, for AI agents, your model provider.
Run it in the cloud with BotSpot
--------------------------------
Do not want to keep a computer running for your Zaif bot? BotSpot is the hosted home for LumiBot strategies and AI trading agents: build with AI, backtest, connect a broker, and watch every trade with logs and alerts.
`Try BotSpot `_
Related guides
--------------
* :doc:`CCXT crypto trading with LumiBot `
* :doc:`AI agents quickstart `
* :doc:`Alpaca trading bot `
* :doc:`Bequant trading bot `
* :doc:`Binance US trading bot `
* :doc:`Bit2C trading bot `
Sources
-------
* `Zaif API document: Trading API `_ (read 2026-10-23)
* `Zaif notice: preventing damage from unauthorized access `_ (read 2026-10-23)
* `Zaif Support: recommended environment and security measures `_ (read 2026-10-23)
* `Zaif Support: market orders FAQ `_ (read 2026-10-23)
* `Zaif Support: getting started `_ (read 2026-10-23)
* `Zaif home page `_ (read 2026-10-23)
* Exchange id, URLs, markets, credentials and stream support: CCXT 4.5.64 metadata, generated 2026-10-23