Trade
exchange.Sell()
以限价单方式卖出。
语法
python
order_id = exchange.Sell(price, amount)参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| price | float | 是 | 卖出价格 |
| amount | float | 是 | 卖出数量 |
返回值
str: 订单ID
示例
基础用法
python
order_id = exchange.Sell(51000, 0.1)
Log("卖单已提交:", order_id)市价卖出
python
def market_sell(amount):
"""模拟市价卖出"""
depth = exchange.GetDepth()
price = depth['Bids'][0][0] # 买一价
return exchange.Sell(price, amount)
market_sell(0.1)止盈卖出
python
def take_profit_sell(buy_price, profit_percent=5):
"""止盈卖出"""
account = exchange.GetAccount()
amount = account['Stocks']
if amount <= 0:
Log("没有持仓")
return
# 计算止盈价
target_price = buy_price * (1 + profit_percent / 100)
while True:
ticker = exchange.GetTicker()
if ticker['Last'] >= target_price:
order_id = exchange.Sell(target_price, amount)
Log(f"触发止盈: {amount} @ {target_price}")
return order_id
Sleep(1000)
# 5%止盈
take_profit_sell(50000, profit_percent=5)分批卖出
python
def grid_sell(start_price, end_price, num_orders, total_amount):
"""网格卖出"""
price_step = (end_price - start_price) / (num_orders - 1)
amount_per_order = total_amount / num_orders
order_ids = []
for i in range(num_orders):
price = start_price + (i * price_step)
order_id = exchange.Sell(price, amount_per_order)
order_ids.append(order_id)
Log(f"挂单{i+1}: {amount_per_order:.6f} @ {price:.2f}")
return order_ids
grid_sell(51000, 52000, 5, 0.5)相关方法
- Buy - 买入下单
- CancelOrder - 取消订单
- GetOrder - 查询订单