def main():
IFsign()
SimSign()
while True:
SimGo()
IFsignFunction initialization environment, loaded only once at run time, used to create variablesSimSignFunction embedded in objectSimGoFunction calculates the number of simulated accounts that need to run in a loop
OrderOrder structure, which is returned by the exchange[0].GetOrder() function.
{
Id : 123456, // 交易单唯一标识
Price : 1000, // 下单价格
Amount : 10, // 下单数量
DealAmount : 10, // 成交数量
AvgPrice : 1000, // 成交均价
Side : "BUY" // 订单方向,常量里的订单类型有:BUY,SELL
Type : "LONG", // 订单类型,常量里的订单类型有: LONG,SHORT,NULL
profit : 0, // 订单收益,现货均返回NULL
feeCcy : 1, // 订单手续费
}
AccountThe account information is returned by the exchange[0].GetAccount() function.
{
Balance : 1000, // 可用计价币数量
FrozenBalance : 0, // Balance表示的资产用于挂单的冻结数量
Stocks : 1, // 可用交易币数量
FrozenStocks : 0 // Stocks表示的资产用于挂单的冻结数量
}
PositionThe position information held in a futures transaction is returned by the exchange[0].GetPosition () function, which returns an array of this Position structure.
{
MarginLevel : 10, // 持仓杆杠大小
Amount : 100, // 持仓量
FrozenAmount : 0, // 仓位冻结量,用于平仓挂单时的临时冻结仓位数量
Price : 10000, // 持仓均价
Profit : 0, // 持仓浮动盈亏
Type : "LONG", // LONG为多头仓位,SHORT为空头仓位
Margin : 1 // 仓位占用的保证金
}
The following functions need to pass:exchange[交易对序号]
Object calls
The buy function is used belowPayment, called, returns an order ID. The parameter value: Price is the order price, numerical type. Amount is the order quantity, numerical type.
def main():
id = exchange[0].Buy(100, 1)
Log("id:", id)
Sell function is used belowThe sale, called, returns an order ID. The parameter value: Price is the order price, numerical type. Amount is the order quantity, numerical type.
def main():
id = exchange[0].Sell(100, 1)
Log("id:", id)
The CancelOrder function is usedCancellation of order, called to cancel an order for an Id. The parameter value: Id is the order number.
def main():
id = exchange[0].Sell(99999, 1)
exchange[0].CancelOrder(id)
The GetOrder function is usedObtaining completed orders, which returns the order information of an Id after being called, without entering the parameter returns all the order information. Parameter value:Id is the order number to be obtained, parameterId is the integer type.
def main():
order = exchange[0].GetOrder()
The GetOrders function is usedObtaining outstanding orders, which returns the order information of an Id after being called, without entering the parameter returns all the order information. Parameter value:Id is the order number to be obtained, parameterId is the integer type.
def main():
orders = exchange[0].GetOrders()
GetAccount is usedAccess account information◦ Returns the value: Account structure structure.
def main():
account = exchange[0].GetAccount()
The GetPosition function is usedGet current holdings▽ return value: position constructor array. ▽ return empty array without holding, i.e. []。
def main():
exchange[0].SetContractType("swap")
exchange[0].SetMarginLevel(10)
exchange[0].SetDirection("buy")
exchange[0].Buy(10000, 2)
position = exchange[0].GetPosition()
SetMarginLevel is used forSet the barrel size▽ Parameter value: numerical value type.
def main():
exchange[0].SetMarginLevel(10)
SetDirection is used to set up exchange[0].Buy or exchange[0].Sell is used to set up exchange[0].Subscription of futuresThe direction of the string.
Subscript functions | Direction of parameter setting of SetDirection | Notes |
---|---|---|
exchange[0].Buy | “buy” | Buy and hold |
exchange[0].Buy | “closesell” | Buying an empty warehouse |
exchange[0].Sell | “sell” | Selling an empty warehouse |
exchange[0].Sell | “closebuy” | Selling at a low price |
Direction can take buy, closebuy, sell, closeesell four parameters.
def main():
exchange[0].SetContractType("swap")
exchange[0].SetMarginLevel(5)
exchange[0].SetDirection("buy")
exchange[0].Buy(10000, 2)
exchange[0].SetMarginLevel(5)
exchange[0].SetDirection("closebuy")
exchange[0].Sell(1000, 2)
The SetContractType function is usedSet the type of contract▽ Parameter value: String type. ContractType can be any string
def main():
exchange[0].SetContractType("this_week")
SetServiceCharge is usedSetting up fees▽ Parameter value: numerical value type.
def main():
# 设置0.25%手续费
exchange[0].SetServiceCharge(0.00025)
SetBalance is used forSetting the Balance▽ Parameter value: numerical value type.
def main():
# 设置余额为10000
exchange[0].SetBalance(10000)
SetSpread is usedSet the error▽ Parameter value: numerical value type.
def main():
# 设置点差为0.005%
exchange[0].SetSpread(0.005)