Trade
This tutorial will demonstrate how to complete the entire buying and selling process
Place Order
We want to buy 2 lot of TXF at a point of 20000, you can execute program as the example
- Python
- Node.js
- C#
from fubon_neo.sdk import FubonSDK, FutOptOrder
from fubon_neo.constant import TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType, BSAction
sdk = FubonSDK()
accounts = sdk.login("Your ID", "Your password", "Your Cert Path", "Your Cert Password") #If there is consolidation, multiple account information will be returned
#Create order object
order = FutOptOrder(
buy_sell = BSAction.Buy,
symbol = "TXFD4",
price = "20000",
lot = 2,
market_type = FutOptMarketType.Future,
price_type = FutOptPriceType.Limit,
time_in_force= TimeInForce.ROD,
order_type = FutOptOrderType.Auto,
user_def = "From_Py" # optional field
)
sdk.futopt.place_order(accounts.data[0], order) #place order
const { FubonSDK, BSAction, TimeInForce, FutOptOrderType, FutOptPriceType, FutOptMarketType } = require('fubon-neo');
const sdk = new FubonSDK();
const accounts = sdk.login("Your ID","Your password", "Your cert path", "Your cert password");
const order = {
buySell: BSAction.Buy,
symbol: "2881",
price: "66",
lot: 2000,
marketType: FutOptMarketType.Future,
priceType: FutOptPriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: FutOptOrderType.Auto,
userDef: "from Js"
};
sdk.futopt.placeOrder(accounts.data[0],order);
using FubonNeo.Sdk;
var sdk = new FubonSDK();
var accounts = sdk.Login("Your ID","Your password", "Your cert path", "Your cert password"); // If there is consolidation, multiple account information will be returned
var order = new FutOptOrder(
BsAction.Buy,
"TXFD4",
null, // Spread Order Buy / Sell
null, // Spread Order Symbol
"20000",
1,
FutOptMarketType.Future,
FutOptPriceType.Limit,
TimeInForce.ROD,
FutOptOrderType.Auto,
null
);
sdk.FutOpt.PlaceOrder(accounts.data[0],order); // To place an block order
Confirm the order and trade notifications
If you want to confirm the status of that order, you can query the specified order using the example below: ( Need to specify the market type for the query. : Future, Option, FutureNight, OptionNight )
- Python
- Node.js
- C#
orderResults = sdk.futopt.get_order_results(accounts.data[0], FutOptMarketType.Future)
print(orderResults)
const orderResults = sdk.futopt.getOrderResults(accounts.data[0], FutOptMarketType.Future)
console.log(orderResults)
var orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0], FutOptMarketType.Future);
foreach (var results in orderResults)
{
Console.WriteLine(results);
}
Based on the result, we can determine whether this order has been executed and the lot that has been filled:
- Python
- Node.js
- C#
[
{
...
buy_sell: Buy, #Transaction direction. (BSAction)
price: 20000, #The original order price (float)
lot: 2, #The original order lot (int)
after_price: 20000, #The Valid order price (float)
after_lot: 2, #The Valid order lot (int)
filled_lot: 0, #Filled lot (int)
filled_money: 0, #Filled Vaule (float)
symbol: "TXFD4", #symbol (string)
order_no: "bA888", #The order number(string)
last_time: "10:10:10.123", #The last modification time (string)
...
}
]
[
{
...
"buySell": "Buy", //Transaction direction. (string)
"price": 20000, //The original order price (number)
"lot": 2, //The original order lot (number)
"afterPrice": 20000, //The Valid order price (number)
"afterLot": 2, //The Valid order lot (number)
"filledLot": 0, //Filled lot (number)
"filledMoney": 0, //Filled Vaule (number)
"symbol": "TXFD4", //symbol (string)
"orderNo": "bA888", //The order number (string)
"lastTime": "10:10:10.123", //The last modification time (string)
...
}
]
{
...
buySell = Buy, // Transaction direction. (BsAction)
price = 20000, //The original order price (double)
lot = 2, //The original order lot (int)
afterPrice = 20000, //The Valid order price (double)
afterLot = 2, //The Valid order lot (int)
filledLot = 0, //Filled lot (int)
filledMoney = 0, //Filled Vaule (float)
symbol = "TXFD4", //symbol (string)
orderNo = "bA888", //The order number(string)
lastTime = "10:10:10.123", //The last modification time (string)
...
}
Modified order price
Since the original price was unable to execute, we adjusted the original order price and changed it to 20100 for the purchase:
- Python
- Node.js
- C#
orderResults = sdk.futopt.get_order_results(accounts.data[0], FutOptMarketType.Future)
modified_pirce = sdk.futopt.make_modify_price_obj(orderResults.data[0],"20100")
sdk.futopt.modify_price(accounts.data[0], modified_pirce)
orderResults = sdk.futopt.getOrderResults(accounts.data[0])
const modified_pirce = sdk.futopt.makeModifyPriceObj(orderResults.data[0],"20100")
sdk.futopt.modifyPrice(accounts.data[0],modified_pirce)
orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0]);
var modified_pirce = sdk.FutOpt.MakeModifyPriceObj(orderResults.data[0],"20100", null);
sdk.FutOpt.ModifyPrice(accounts.data[0],modified_pirce);
"A few minutes later, we queried the order status again and found that it had been executed.
- Python
- Node.js
- C#
orderResults = sdk.futopt.get_order_results(accounts.data[0], FutOptMarketType.Future)
print(orderResults.data[0])
[
{
...
buy_sell: Buy, # Transaction direction. (BSAction)
price: 20000, #The original order price (number)
lot: 2, #The original order lot (number)
after_price: 20100, #The Valid order price (number)
after_lot: 2, #The Valid order lot (number)
filled_lot: 1, #Filled lot (number)
filled_money: 20100, #Filled Vaule (number)
symbol: "TXFD4", #symbol (string)
order_no: "bA888", #The order number (string)
last_time: "10:13:12.123", #The last modification time (string)
...
}
]
orderResults = sdk.futopt.getOrderResults(accounts.data[0], FutOptMarketType.Future)
console.log(orderResults.data[0])
{
...
"buySell" : "Buy", // Transaction direction. (BSAction)
"price" : 20000, //The original order price (number)
"lot" : 2, //The original order lot (number)
"afterPrice" : 20100, //The Valid order price (number)
"afterLot" : 2, //The Valid order lot (number)
"filledLot" : 1, //Filled lot (number)
"filledMoney" : 20100, //Filled Vaule (number)
"symbol" : "TXFD4", //symbol (string)
"orderNo" : "bA888", //The order number (string)
"lastTime" : "10:13:12.123", //The last modification time (string)
...
}
orderResults = sdk.FutOpt.GetOrderResults(accounts.data[0], FutOptMarketType.Future);
Console.WriteLine(orderResults.data[0]);
{
...
buySell = Buy, // Transaction direction. (BsAction)
price = 20000, //The original order price (double)
lot = 2, //The original order lot (int)
afterPrice = 20100, //The Valid order price (double)
afterLot = 2, //The Valid order lot (int)
filledLot = 1, //Filled lot (int)
filledMoney = 20100, //Filled Vaule (double)
symbol = "TXFD4", //symbol (string)
orderNo = "bA888", //The order number (string)
lastTime = "10:13:12.123", //The last modification time (string)
...
}
Sell Position
Before the close, we decided to Sell 1 lot of TXF.
- Python
- Node.js
- C#
#Create order object
order = FutOptOrder(
buy_sell = BSAction.Sell,
symbol = "TXFD4",
price = "20100",
lot = 1,
market_type = FutOptMarketType.Future,
price_type = FuturePriceType.Limit,
time_in_force= TimeInForce.ROD,
order_type = FutureOrderType.Auto,
user_def = "From_Py" # optional field
)
sdk.futopt.place_order(accounts.data[0], order) #Place Order
order = {
buySell: BSAction.Sell,
symbol: "TXFD4",
price: "20100",
lot: 1,
marketType: FutOptMarketType.Future,
priceType: FuturePriceType.Limit,
timeInForce: TimeInForce.ROD,
orderType: FutureOrderType.Auto,
userDef: "from Js"
};
sdk.futopt.placeOrder(accounts.data[0],order)
order = new FutOptOrder(
BsAction.Sell,
"TXFD4",
null,
null,
"20100",
1,
FutOptMarketType.Common,
FutOptPriceType.Limit,
TimeInForce.ROD,
FutOptOrderType.Auto,
null
);
sdk.FutOpt.PlaceOrder(accounts.data[0],order); // To place an block order