Python Version Iceberg Order Sell
Teaching strategy, related article link:https://www.fmz.com/bbs-topic/5080
PythonOther
Teaching strategy, related article link:https://www.fmz.com/bbs-topic/5080
Parameters
| Name | Default | What it controls |
|---|---|---|
| TotalSellStocks | 10 | Total quantity sold (coins)) |
| AvgSellOnce | 0.3 | Average quantity per sale (Coin)) |
| FloatPoint | 10 | Single average floating point number (percentage) |
| EntrustDepth | 0.1 | Order depth (percentage) |
| MinSellPrice | 3800 | Lowest sell price (yuan) |
| Interval | 1000 | Retry on failure (milliseconds)) |
| MinStock | 0.0001 | Minimum transaction volume |
| LoopInterval | 300 | Price polling interval (milliseconds) |
Source Python
import random
def CancelPendingOrders():
while True:
orders = _C(exchange.GetOrders)
if len(orders) == 0:
return
for j in range(len(orders)):
exchange.CancelOrder(orders[j]["Id"])
if j < len(orders) - 1:
Sleep(Interval)
LastSellPrice = 0
InitAccount = None
def dispatch():
global LastSellPrice, InitAccount
account = None
ticker = _C(exchange.GetTicker)
LogStatus(_D(), "ticker:", ticker)
if LastSellPrice > 0:
if len(_C(exchange.GetOrders)) > 0:
if ticker["Last"] < LastSellPrice and ((LastSellPrice - ticker["Last"]) / ticker["Last"]) > (2 * (EntrustDepth / 100)):
Log("Too much deviation, latest transaction price:", ticker["Last"], "order price", LastSellPrice)
CancelPendingOrders()
else :
return True
else :
account = _C(exchange.GetAccount)
Log("Buy order completed, cumulative sales:", _N(InitAccount["Stocks"] - account["Stocks"]), "Average selling price:", _N((account["Balance"] - InitAccount["Balance"]) / (InitAccount["Stocks"] - account["Stocks"])))
LastSellPrice = 0
SellPrice = _N(ticker["Sell"] * (1 + EntrustDepth / 100))
if SellPrice < MinSellPrice:
return True
if not account:
account = _C(exchange.GetAccount)
if (InitAccount["Stocks"] - account["Stocks"]) >= TotalSellStocks:
return False
RandomAvgSellOnce = (AvgSellOnce * ((100.0 - FloatPoint) / 100.0)) + (((FloatPoint * 2) / 100.0) * AvgSellOnce * random.random())
SellAmount = min(TotalSellStocks - (InitAccount["Stocks"] - account["Stocks"]), RandomAvgSellOnce)
if SellAmount < MinStock:
return False
LastSellPrice = SellPrice
exchange.Sell(SellPrice, SellAmount, "Last transaction price", ticker["Last"])
return True
def main():
global InitAccount, LoopInterval
CancelPendingOrders()
InitAccount = _C(exchange.GetAccount)
Log(InitAccount)
if InitAccount["Stocks"] < TotalSellStocks:
raise Exception("Insufficient coins in the account")
LoopInterval = max(LoopInterval, 1)
while dispatch():
Sleep(LoopInterval)
Log("All commissions completed", _C(exchange.GetAccount))
Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2020-03-07. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Python-Version-Iceberg-Order-Sell.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Dynamic Balancing Strategy Python VersionPython · Other
- Exchange Wash Trading and Mutual BrushingPython · Other
- Leek Protection Program Tang Anqi Channel Position Balancing StrategyPython · Other
- Paul The Gambler Lévy Gold EditionPython · Other
- Porting OKCoin Leek Harvester Multi Variety Version Annotated Python VersionPython · Other
- Python Example Using asyncio http to Obtain Market DataPython · Other