1. The premise:The first time I learned how to write a strategy, I was commissioned by Ice Mountain: This article mainly refers to the strategy of the dam:https://www.fmz.com/strategy/188435In general, the strategy is not much different from the strategy of the big house, the writing is a bit rough.
2.前因When buying and selling digital currencies in bulk, the market price of the currency you want to buy/sell may be affected by the larger transaction amount.PullingI'm not going to sell it.The dishesI'm not sure. 1 pull: pull up the price, raise the currency 2 - Selling the coin directly, regardless of the price, causing the price to fall 3 Trading Currency Stocks: Currencies used for trading, such as the BTC/USDT trading pair,BTC is a trading currency.4 Value Currency Balance: The currency that the user charges, as in the example of BTC/USDT trading pairs, is the currency of the user.USDT is a currency
Ice Mountain commissioned:Operations: This is the process of automatically breaking down large orders intoMultiple assignmentsIn addition to the above, you can also set up an automated ordering system based on the latest buy/sell price and the price policy set by the customer.Automatic re-commissioning when the previous order is fully traded or the latest price deviates significantly from the current orderEffect: Reduce the impact of bulk buy/sell orders on the market price, making bulk purchases more affordableAvoid increasing your purchasing costs by paying large amounts to increase pricesIf you sell in bulk, you can.Avoid reducing your selling profit due to low prices caused by large sales orders
The data parameters are compared:
The rules:
The main parameters:
I thought:
Suggestions
The tactics are not perfect, and the buzzards who want to pass point to one or two.
import random def main(): # 获取账户所有未成交订单 Log("取消所有未成交订单") orders = _C(exchange.GetOrders) if len(orders) > 0: for i in range(len(orders)): exchange.CancelOrder(orders[i]["Id"]) Sleep(priceInterval*1000) # 对比账户余额 Log("获取用户初始化账户") initAccount = _C(exchange.GetAccount) if initAccount["Balance"] < buyAmount: Log("账户余额不足") return #比较单笔购买数量均值*市场买一价是否大于账户余额 ticker = _C(exchange.GetTicker) if (ticker['Last'] * buyNum) > initAccount['Balance']: Log("单次购买均值价格大于账户余额,请调整参数") return lastBuyPrice = 0 while (True): Sleep(priceInterval*1000) #获取账户信息 account = _C(exchange.GetAccount) #获取当下行情 ticker = _C(exchange.GetTicker) # 上次购买价格不为空,查看订单是否完成,没有完成则取消 if lastBuyPrice > 0: orders1 = exchange.GetOrders() if len(orders1) > 0: for j in range(len(orders1)): #计算实际市场委托深度 if ticker["Last"] > lastBuyPrice and ((ticker["Last"] - lastBuyPrice)/lastBuyPrice) > (2* (depthStatus/100)): Log("委托价格偏离过多,最新成交价:",ticker["Last"],"委托价",lastBuyPrice) exchange.CancelOrder(orders1[j]["Id"]) lastBuyPrice = 0 continue else: Log("买单完成, 累计花费:", _N(initAccount["Balance"] - account["Balance"]), "平均买入价:", _N((initAccount["Balance"] - account["Balance"]) / (account["Stocks"] - initAccount["Stocks"]))) lastBuyPrice = 0 continue else: Log("剩余余额:",account["Balance"]) #委托价格 = 最新买一价*(1-委托深度/100) entrustPrice = _N(ticker["Buy"]*(1-depthStatus/100)) Log("委托价格:",entrustPrice) #判断委托价格是否大于最高价格限定 if entrustPrice > highPrice: continue #随机购买数量 = 单次购买数量均值 * ((100-单次均值浮点数)/100)+(单次均值浮点数*2 /100* 单次购买数量均值 *随机数0~1) randomBuyNum = (buyNum*((100-buyOncePoint)/100))+(buyOncePoint*2/100 *buyNum*random.random()) #可用数量金额 useMoney = min(account["Balance"],randomBuyNum,buyAmount - (initAccount["Balance"] - account["Balance"])) #购买数量 orderBuyNum = _N(useMoney/entrustPrice) Log("交易数量:",orderBuyNum) #判断是否小于最小交易量 if orderBuyNum < minBuyNum: break #因为要扣手续费,所以大概为账户99.7% if (entrustPrice*orderBuyNum)>(account["Balance"]*0.997): Log("金额为",(entrustPrice*orderBuyNum)) Log("账户余额为",(account["Balance"])) continue #更新上次购买价格 lastBuyPrice = entrustPrice #下单 exchange.Buy(entrustPrice,orderBuyNum) account = _C(exchange.GetAccount) Log("冰山委托买单完成,共计花费:",_N(initAccount["Balance"]-account["Balance"]),"平均单价为:",_N((initAccount["Balance"]-account["Balance"])/(account["Stocks"]-initAccount["Stocks"])))