exchange.Buy

exchange.Buy()函数用于下买单。Buy()函数是交易所对象{@var/EXCHANGE exchange}的成员函数。Buy()函数操作交易所对象exchange绑定的交易所账户,exchange对象的成员函数(方法)的用途仅与exchange相关,文档后续不再赘述。

下单成功返回订单Id,下单失败返回空值。FMZ平台的订单{@struct/Order Order}结构的属性Id由交易所品种代码和交易所原始订单Id组成,以英文逗号间隔。例如OKX交易所的现货交易对ETH_USDT订单的属性Id格式为:ETH-USDT,1547130415509278720。调用exchange.Buy()函数下单时,返回值订单Id与订单{@struct/Order Order}结构的Id属性一致。 string / 空值

exchange.Buy(price, amount) exchange.Buy(price, amount, …args)

price参数用于设置订单价格。 price true number amount参数用于设置订单数量。 amount true number 扩展参数,可以将附加信息输出到此条下单日志中,arg参数可以传递多个。 arg false string / number / bool / object / array / any (平台支持的任意类型)


function main() {
    var id = exchange.Buy(100, 1);
    Log("id:", id);
}

def main():
    id = exchange.Buy(100, 1)
    Log("id:", id)

void main() {
    auto id = exchange.Buy(100, 1);
    Log("id:", id);
}
exchange.Buy()返回的订单编号,可用于查询订单信息和取消订单。 “`javascript // 以下为错误调用 function main() { exchange.SetContractType(“quarter”)

// 设置做空方向
exchange.SetDirection("sell")
// 下买单,会报错,做空只能卖出
var id = exchange.Buy(50, 1)

// 设置做多方向
exchange.SetDirection("buy")
// 下卖单,会报错,做多只能买入
var id2 = exchange.Sell(60, 1)

// 设置平多方向
exchange.SetDirection("closebuy")
// 下买单,会报错,平多只能卖出
var id3 = exchange.Buy(-1, 1)

// 设置平空方向
exchange.SetDirection("closesell")
// 下卖单,会报错,平空只能买入
var id4 = exchange.Sell(-1, 1)

} python

以下为错误调用

def main(): exchange.SetContractType(“quarter”) exchange.SetDirection(“sell”) id = exchange.Buy(50, 1) exchange.SetDirection(“buy”) id2 = exchange.Sell(60, 1) exchange.SetDirection(“closebuy”) id3 = exchange.Buy(-1, 1) exchange.SetDirection(“closesell”) id4 = exchange.Sell(-1, 1) cpp // 以下为错误调用 void main() { exchange.SetContractType(“quarter”); exchange.SetDirection(“sell”); auto id = exchange.Buy(50, 1); exchange.SetDirection(“buy”); auto id2 = exchange.Sell(60, 1); exchange.SetDirection(“closebuy”); auto id3 = exchange.Buy(-1, 1); exchange.SetDirection(“closesell”); auto id4 = exchange.Sell(-1, 1); }“` 加密货币期货合约下单时必须注意交易方向是否设置正确,如果交易方向与交易函数不匹配将会报错:

```log

direction is sell, invalid order type Buy

direction is buy, invalid order type Sell

direction is closebuy, invalid order type Buy

direction is closesell, invalid order type Sell

```


// 例如交易对:ETH_BTC ,市价单买入
function main() {
    // 下市价单买入,买入0.1个BTC(计价币)金额的ETH币
    exchange.Buy(-1, 0.1)
}

def main():
    exchange.Buy(-1, 0.1)

void main() {
    exchange.Buy(-1, 0.1);
}
现货市价单。

期货合约下单时必须注意交易方向是否设置正确,如果交易方向与交易函数不匹配将会报错。加密货币期货合约交易所的下单数量如无特殊说明则为合约张数。 参数price设置为-1用于下市价单,需要交易所的下单接口支持市价单。加密货币现货的市价单方式下单,下买单时,下单数量参数amount是以计价币为单位的金额数量。加密货币期货合约的市价单方式下单,下单数量参数amount的单位为合约张数。实盘时,少数加密货币交易所不支持市价单接口。个别现货交易所的市价单买单的下单数量为交易币数,具体查看「用户指南」中的交易所特殊说明。 如使用较旧版本的托管者,exchange.Buy()函数的返回值订单Id可能与当前文档中描述的返回值订单Id存在差异。 需要注意,以下三家交易所的下单接口比较特殊。对于现货市价单的买单,下单数量是币数,而非金额。

  • AscendEx

  • BitMEX

  • Bitfinex

{@fun/Trade/exchange.Sell exchange.Sell}, {@fun/Futures/exchange.SetContractType exchange.SetContractType}, {@fun/Futures/exchange.SetDirection exchange.SetDirection}