LogoLogo
Back to HaasOnline.comSwitch to Trade Platform
3.x
3.x
  • Welcome
  • Getting Started
    • Using Local API Server
    • Authentication
    • Response
      • Error Codes
  • HaasScript
    • Using HaasScript
      • HaasScript Facts
      • Charting
      • Order Handling
      • Interval
      • Input Fields
      • Positions Handling
        • Fee correction
      • Position Information
      • Memory Management
      • Optimizations
      • Signal Handling
      • Trading
    • Script Editor
      • Syntax
      • Parameters
      • Interaction
    • Visual Editor
      • Blocks
      • Parameters
      • Flow Control
      • Interaction
    • Custom Commands
    • Tutorials
      • Trade Bot Guide
        • Creating A Trade Bot
          • Visual Editor Guide
          • Script Editor Guide
          • Custom Containers
        • Customizing Indicators
        • Customizing Safeties
        • Customizing Insurances
        • Creating Easy Indicators
      • Unmanaged Trading Guide
        • Executing Orders
        • Managing Orders
        • Managing Positions
        • Managing Wallet
      • Script Editor
        • Classes
        • MadHatter BBands
        • Percentage Price Change
      • Visual Editor
        • Importing Scripts
        • SmoothRSI
        • Scalper Bot
    • Commands
      • Array Helpers
      • Charting
      • Constants
      • Custom Commands Helpers
      • Easy Indicators
      • Easy Insurances
      • Easy Safeties
      • Equations
      • Flow Control
      • Input Fields
      • Input Settings
      • Mathematical
      • Memory Helpers
      • Miscellaneous
      • Order Handling
      • Order Information
      • Position Information
      • Position Prices
      • Price Data
      • Price Market Information
      • Profit Information
      • Settings
      • Signal Helpers
      • String Helpers
      • Technical Analysis
      • Technical Analysis Helpers
      • Time Information
      • Trade Actions (Managed)
      • Trade Actions (Unmanaged)
      • Trade Bot
      • Trade Market Information
      • Wallet
  • API Endpoints
    • Software API
    • Market Data API
    • Account Data API
    • Trade Data API
    • Advanced Order API
    • Trade Bot API
    • Custom Trade Bot API
    • ENUMS
    • Data Objects
  • Examples
    • Script Bots (C#)
      • Scalper Trade Bot
      • Flash Crash Trade Bot
    • Script Indicators (C#)
      • Indicator Script
      • Technical Analysis Library
    • Pshai Scripts (C#)
      • BBands Ext
      • BBands Ext v2
      • Chaikin A/D Line
      • Calibrator
      • Pshai's RVI
    • Scripted Driver
  • Other Resources
    • YouTube
    • Guides & Tutorials
    • Questions & Answers
    • Community Projects
  • Need Help?
    • Ask on Discord
    • Submit Support Ticket
Powered by GitBook
On this page
  • To Long Didn't Read
  • Fees?
  • Consequences
  • Solving the issue
  • Examples
  • Implementation
  • Good
  • Bad

Was this helpful?

  1. HaasScript
  2. Using HaasScript
  3. Positions Handling

Fee correction

Correct the sell/exit order amount

PreviousPositions HandlingNextPosition Information

Last updated 5 years ago

Was this helpful?

To Long Didn't Read

Call PlaceExitPositionOrder in order to close your position to prevent overselling due to fees.

Fees?

When using unmanaged trade signals it good to think about the fee. When we buy 1 BTC, it doesn't mean we get 1 BTC. The exchange will deduct its portion of the fees from either your traded amount or your wallet, leaving us with a little less than 1 BTC. Let's say we pay 0.2% fee. After buying 1 BTC, we get 0.998 BTC and the exchange takes 0.002. Now, if we execute a sell order of 1 BTC, it might not execute if we didn't have a little extra BTC already.

Consequences

Not taking fee in consideration can have a domino effect. Let's say we are scripting a market making bot. The bot has 3 slots. It places 3 buy orders of 1 BTC each and they are all filled. The exchange deducts the fees of 0.006 BTC and we are left with 2.994 BTC. The scripts executes 3 sell orders. After the first sell order, the position is 1.994 BTC, after the second order, 0.994 BTC. Once the third order is completed the open position is closed and we are left with 0.006 BTC - 0.002 BTC the exchange takes. At this moment the bot has sold 0.004 BTC more than it has bought. It has an unintended short position. If this cycle happens again, the bot has an open short position of 0.008 BTC.

Solving the issue

Although this is a very inconvenient issue, it's also very easily solved. When we want to exit the position (sell what we have bought) we use the PlaceExitPositionOrder command. This will place an order with the exact amount as your open position, keeping fees into consideration.

Examples

Implementation

The Marking Making Slot is a perfect example on how this can be applied

Good

Bad

Trade Actions (Unmanaged)