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:1. commission price = last buy 1 price X ((1- commission depth) 2. Actual market commission depth = (final transaction price - last commission price) / last commission price 3. Random number of single purchases = average number of single purchases X ((100 - number of single average floating points) % + (number of single average floating points X2) % X average number of single purchases X random number 0 to 1 4. Available Amount = Accounting Currency, Random Number of One-time Purchases, Minimum Number of Total Amounts Left to Buy 5. Quantity of purchases = Available amount / commission price 6. Total amount of remaining purchases = Total amount of purchases - (currency of initial accounting - currency of accounting)
The rules:1. Automatic withdrawal if the latest transaction price is more than the depth of the order X2 (indicate too large deviation) 2. Stop commissioning when the total amount of strategy transactions is equal to the total number of assignments 3. The latest transaction price is higher than the maximum limit for the purchase price stop order 4. Restore the order at the latest transaction price below the maximum purchase price limit
The main parameters:1. The amount of the purchase Number of purchases 3. Depth of delegation 4. The highest price 5. Price rounding intervals 6. Average floating point number of single purchases 7. Minimum number of transactions
I thought:1. Get all outstanding orders and cancel orders 2. Acquire the balance of the initialization account to determine if it is greater than the total purchase amount 3. Calculate the commission price 4. Calculate the number of single purchases 5. Calculate the amount available 6. Calculate the number of purchases 7. Execute the purchase 8. Designated time for rest 9. Judge whether the last order was successful 10. Successful log output 11. Failure to determine whether the deviation is too large and too large to reverse
Suggestions1. It is recommended to retest using ETH_USDT
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"])))