Ujian Grid Python

Penulis:Injil Pengguna Modal Kecil, Dicipta: 2018-10-12 11:53:06, Dikemas kini: 2018-10-12 11:59:21

'''backtest
start: 2018-09-30 00:00:00
end: 2018-10-11 19:00:00
period: 15m
exchanges: [{"eid":"OKCoin_EN","currency":"ETC_USD"}]
'''
	
def main():
	first()
	while True:
		get_information = _C(exchange.GetTicker)
		#get_order = exchange.GetOrder() 
		btc_price_last = get_information.Last
		#account = exchange.GetAccount()
		
		for j in range(0,len(Grid_price_list)):
			if(Grid_price_list[j-1] < btc_price_last < Grid_price_list[j]):   # 判断价格所在的网格区间
				if(btc_price_last < exchange.GetOrder(buy_id).AvgPrice and btc_price_last <= Grid_price_list[j-1]): # !!!需要进一步完善针对卖单情况的逻辑!!!,现价小于买入价,且现价小于等于网格下值,继续买入。
					buy()
				else:
					main()
				if(btc_price_last > exchange.GetOrder(buy_id).AvgPrice and btc_price_last >= Grid_price_list[j]): # !!!需要进一步完善针对卖单情况的逻辑!!!,现价大于买入价,且现价大于等于网格上值,继续卖出。
					sell()
				else:
					main()
			
		order_stock_rate = 0.05 * j # 仓位比例
		
	Sleep(300 * 1000)
	
def buy():
	buy_price = Grid_price_list[j-1]
	buy_id = exchange.Buy(buy_price, 500 * (j - 1) / buy_price)

def sell():
	sell_price = Grid_price_list[j]
	sell_id = exchange.Sell(sell_price, 500 * j / sell_price)


def first():

	get_information = _C(exchange.GetTicker)
	#get_order = exchange.GetOrder() 
	btc_price_last = get_information.Last
	global account
	account = _C(exchange.GetAccount)

	global Grid_price_list
	Grid_price_list = [] # 给最低网格价格赋值,算出每个价格
	btc_price_bottom = 7
	for i in range(1,20):
		btc_price_bottom = btc_price_bottom * 1.05
		Grid_price_list.append(btc_price_bottom)
	Log(Grid_price_list)

	global j
	for j in range(0,len(Grid_price_list)):
		if(Grid_price_list[j-1] < btc_price_last < Grid_price_list[j]):   # 判断价格所在的网格区间
			buy()
			Log("初始买入",exchange.GetOrder(buy_id)
		#order_stock_rate = 0.05 * j # 仓位比例

Lebih lanjut

Injil Pengguna Modal KecilTolong buat saya buta.

Injil Pengguna Modal KecilMembalas laporan ralat, Traceback (most recent call last): File "", line 1292, in Run File "", line 63 if 'init' in locals() and callable(init): ^ SyntaxError: invalid syntax

Mimpi kecil

Mimpi kecilAnda boleh melihat status pesanan adalah 0, masih dalam keadaan terhad, iaitu pesanan tidak ditukar, jadi jumlah duit tidak berubah. Anda menyesuaikan harga pesanan dengan besar. Cuba, ia akan ditukar, jumlah duit berubah.

Injil Pengguna Modal KecilJika anda melihat kod dan log di bawah, maklumat dalam exchange.GetOrder ((buy_id) jumlah adalah 368.3512, maklumat stok adalah sama dengan nilai yang saya set semula adalah 20. Log (("pembelian awal", exchange.GetOrder ((buy_id), account.Stocks) 2018-09-30 00:00:00 Maklumat pembelian awal {'Status': 0L, 'Price': 10.8592, 'AvgPrice: 0.0, 'Amount: 368.3512, 'DealAmount: 0.0, 'ContractType': 'ETC_USDT_Huobi', 'Type': 0L, 'Id: 1L} 20.0 2018-09-30 00:00:00 Maklumat 1 20.0 2018-09-30 00:00:00 Huobi membeli 10.8592 368.351259761308

Mimpi kecilAnda harus membayar dengan menggunakan Balance dan menjual dengan menggunakan Saham.

Injil Pengguna Modal Kecil 还请教一下,回测系统里面account.Stocks的值不会变吗?怎么下了买入单,Balance减小了,Stocks没变呢?

Mimpi kecil### Sila panggil saya DEBUG Master~ `` global j for j in range ((0, len ((Grid_price_list)): if ((Grid_price_list[j-1] < btc_price_last < Grid_price_list[j]): # Menentukan julat grid di mana harga berada Beli (() Log (("pembelian awal", exchange.GetOrder ((buy_id) # tempat ini kurang menulis satu ) Oh, T_T. Masalah pengekodan seperti ini harus diperhatikan!!!!!! #order_stock_rate = 0.05 * j # nisbah kedudukan ``