question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Puzzled by setting order Size on futures

See original GitHub issue

Hi there - got a small issue which could be down to my understanding of how to work with the various parameters required for creating a Futures order. On reading the documents, it would appear that i must first query the Contract in order to get the metadata related to min/max leverage allowed, plus data related to the Multiplier used. on querying this data, i receive a payload that has all of this metadata :

// symbol = “UNIUSDTM” var contract = await _clientFutures.FuturesApi.ExchangeData.GetContractAsync(symbol);

all good. However, I’m not entirely sure which data elements I should use as I’ve been getting varied results when applying the Multiplier found in the contract data. Below is my crude attempt to calculate the resulting size required for a fixed currency amount:

// dollarFunds =100m // bidPrice = 95.6 quantity = (dollarFunds / bidPrice / (contract.Data.Multiplier * leverageRate));

I also tried the simpler version of the below which worked in some cases, but like the other version, not all:

quantity = (dollarFunds / bidPrice * leverageRate);

I then use it as thus:

var orderBuy = await _clientFutures.FuturesApi.Trading.PlaceOrderAsync(
    symbol,
    orderSideAdd,
    Kucoin.Net.Enums.NewOrderType.Limit, leverageRate, quantity, bidPrice,
    Kucoin.Net.Enums.TimeInForce.GoodTillCanceled, remark: remark);

The above calc is obviously way wrong as it is fine for some contracts and wildly out for others.

I feel such an idiot, but what on earth am I doing wrong (either in terms of logic, or in terms of the data I’m using).

This is the final piece in a nice little leverage play that I’ve been working on successfully with minimum contract size, the missing puzzle piece now comes when applying hard scalable $$.

Hope you can help. jim

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
jimtollancommented, Mar 24, 2022

I figured it out. it was down to using the Multiplier in a particular way 😉

        quantity = Math.Round((dollarFunds / bidPrice * (leverageRate / contract.Data.Multiplier)),
            decimalPlaces, MidpointRounding.AwayFromZero);

hope this helps someone else. will add more detail later.

0reactions
jimtollancommented, Mar 30, 2022

Sometimes you just gotta go with what works in the moment. Good work on getting it rolling and appreciate the additional info. I contacted the KuCoin API dev team and for posterity and any future folks here’s what I got:

SIZE
The size must be no less than the lotSize for the contract and no larger than the maxOrderQty. It should be a multiple number of lotSize, or the system will report an error when you place the order. Size indicates the amount of contract to buy or sell. Size is the number or lot size of the contract. Eg. the lot size of XBTUSDTM is 0.001 Bitcoin, the lot size of XBTUSDM is 1 USD.

"lotSize": 1,
"multiplier": 

All 1 is normal, because there is a multiplier field.

so the order value = lotSize * multiplier

We have to add more explanation about this to help doc  which we will do soon

well, if you happen to arrive at a nice little extension method or extended library that works against the Kucoin.Net library, then ping me the link if you share it. My version is definitely pretty ropey and too embarrassing to publicly expose!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "size" parameter in Kucoin futures API refer to?
Size indicates the amount of contract to buy or sell. Size is the number or lot size of the contract. Eg. the lot...
Read more >
Change Think or Swim (ToS) Order Defaults | Trading Tutorials
To change think or swim order defaults navigate to the top setup tab, navigate to application settings, order defaults, options, and change ...
Read more >
How to Setup Futures Trader on ThinkorSwim - YouTube
Timestamps 0:00 Intro 0:42 Setting up Futures Trader 3:17 Initial Margin ... for Tick Size 7:05 Placing Futures Trades 8:56 Trading Futures ......
Read more >
Solving the Commodity Markets' Non-Convergence Puzzle
When the market fails to converge, a commodity's expiring futures price lies somewhere above or below its corresponding price in the cash market ......
Read more >
Tips for Getting Into Futures Trading
The futures markets can seem daunting, but these explanations and strategies will help.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found