Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Delphi unit for NinjaTrader

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Delphi unit for NinjaTrader

    Probably anybody that needs the following, already has it. But, if it is of use to anybody, I am posting my Delphi conversion of the DLL NinjaTrader interface. I used PAnsiChar, instead of PChar, so that it should work with all Delphi versions including 2009, although I am personally only using 2007 at the moment:



    unit NinjaTrader;

    interface

    const
    NT_NO_SHOW_DIALOG = 0;
    NT_LAST = 0;
    NT_BID = 1;
    NT_ASK = 2;
    NT_SUCCESS = 0;
    NT_ERROR = -1;
    NT_CONFIRM_ON = 1;
    NT_CONFIRM_OFF = 0;


    //Sets the ask price and size for the specified instrument. A return value of
    //0 indicates success and -1 indicates an error.
    FUNCTION Ask(instrument : pAnsiChar; price : double; size : integer) :
    integer; stdcall; external 'NtDirect.dll';


    //Sets the ask price and size for the specified instrument for use when
    //synchronizing NinjaTrader playback with an external application playback.
    //A return value of 0 indicates success and -1 indicates an error. The
    //timeStamp parameter format is "yyyyMMddhhmmss".
    FUNCTION AskPlayback(instrument : pAnsiChar; price : double; size :
    integer; timestamp : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets the average entry price for the specified instrument/account
    //combination.
    FUNCTION AvgEntryPrice(instrument : pAnsiChar; account : pAnsiChar) :
    double; stdcall; external 'NtDirect.dll';


    //Gets the average entry price for the specified orderId.
    FUNCTION AvgFillPrice(orderId : pAnsiChar) : double;
    stdcall; external 'NtDirect.dll';


    //Sets the bid price and size for the specified instrument. A return value of
    //0 indicates success and -1 indicates an error.
    FUNCTION Bid(instrument : pAnsiChar; price : double; size : integer) :
    integer; stdcall; external 'NtDirect.dll';


    //Sets the bid price and size for the specified instrument for use when
    //synchronizing NinjaTrader playback with an external application playback.
    //A return value of 0 indicates success and -1 indicates an error. The
    //timeStamp parameter format is "yyyyMMddhhmmss".
    FUNCTION BidPlayback(instrument : pAnsiChar; price : double;
    size : integer; timestamp : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets the buying power for the specified account. *Not all brokerage
    //technologies support this value.
    FUNCTION BuyingPower(account : pAnsiChar) : double;
    stdcall; external 'NtDirect.dll';


    //Gets the cash value for the specified account. *Not all brokerage //technologies support this value.
    FUNCTION CashValue(account : pAnsiChar) : double;
    stdcall; external 'NtDirect.dll';


    //Function for submitting, cancelling and changing orders, positions and
    //strategies. Refer to the Commands and Valid Parameters section for
    //detailed information. A return value of 0 indicates success and -1
    //indicates an error.The Log tab will list context sensitive error information.
    FUNCTION Command(command : pAnsiChar; account : pAnsiChar;
    instrument : pAnsiChar; action : pAnsiChar; quantity : integer;
    orderType : pAnsiChar; limitPrice : double; stopPrice : double;
    timeInForce : pAnsiChar; oco : pAnsiChar; orderId : pAnsiChar;
    strategy : pAnsiChar; strategyId : pAnsiChar ) : integer;
    stdcall; external 'NtDirect.dll';


    //The parameter confirm indicates if an order confirmation message will
    //appear. This toggles the global option that can be set manually via
    //NinjaTrader Control Center Tools-->Options, "Confirm order placement"
    //checkbox. A value of 1 sets this option to true, any other value sets this
    //option to false.
    FUNCTION ConfirmOrders(confirm : integer) : integer;
    stdcall; external 'NtDirect.dll';


    //Returns a value of zero if the DLL has established a connection to the
    //NinjaTrader server (application) and if the ATI is currently enabled or, -1
    //if it is disconnected. Calling any function in the DLL will automatically
    //initiate a connection to the server. The parameter showMessage indicates
    //if a message box is displayed in case the connection can not be
    //established. A value of 1 = show message box, any other value = don't
    //show message box.
    FUNCTION Connected(showMessage : integer) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets the number of contracts/shares filled for the orderId.
    FUNCTION Filled(orderId : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Sets the last price and size for the specified instrument. A return value of
    //0 indicates success and -1 indicates an error.
    FUNCTION Last(instrument : pAnsiChar; price : double; size : integer) :
    integer; stdcall; external 'NtDirect.dll';


    //Sets the last price and size for the specified instrument for use when
    //synchronizing NinjaTrader playback with an external application playback.
    //A return value of 0 indicates success and -1 indicates an error. The
    //timeStamp parameter format is "yyyyMMddhhmmss".
    FUNCTION LastPlayback(instrument : pAnsiChar; price : double;
    size : integer; timestamp : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets the most recent price for the specified instrument and data type.
    // 0 = last, 1 = bid, 2 = ask.
    // You must first call the SubscribeMarketData() function prior
    // to calling this function.
    FUNCTION MarketData(instrument : pAnsiChar; iType : integer ) : double;
    stdcall; external 'NtDirect.dll';


    //Gets the market position for an instrument/account combination. Returns
    // 0 for flat, negative value for short positive value for long.
    FUNCTION MarketPosition(instrument : pAnsiChar; account : pAnsiChar) :
    integer; stdcall; external 'NtDirect.dll';


    //Gets a new unique order id value.
    FUNCTION NewOrderId() : pAnsiChar;
    stdcall; external 'NtDirect.dll';


    //Gets a string of order ids of all orders of an account separated by '|'. *If
    //a user defined order id was not originally provided, the internal token id
    //value is used since it is guaranteed to be unique.
    FUNCTION Orders(account : pAnsiChar) : pAnsiChar;
    stdcall; external 'NtDirect.dll';


    //Gets the order state (see definitions) for the orderId. Returns an empty
    //string if the order id value provided does not return an order.
    FUNCTION OrderStatus ( OrderID: pAnsiChar ) : pAnsiChar;
    stdcall; external 'NtDirect.dll';


    //Gets the realized profit and loss of an account.
    FUNCTION RealizedPnL(account : pAnsiChar) : double;
    stdcall; external 'NtDirect.dll';

    //Optional function to set the host and port number. By default, host is set
    //to "localhost" and port is set to 36973. The default port number can be
    //set via the General tab under Options. If you change these default
    //values, this function must be called before any other function. A return
    //value of 0 indicates success and -1 indicates an error.
    FUNCTION SetUp(host : pAnsiChar; port : integer ) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets a string of order ids of all stop loss orders of an ATM strategy
    //separated by '|'. Internal token id value is used since it is guaranteed to
    //be unique.
    FUNCTION StopOrders(strategyId : pAnsiChar) : pAnsiChar;
    stdcall; external 'NtDirect.dll';


    //Gets a string of strategy ids of all ATM strategies of an account
    //separated by '|'. Duplicate ID values can be returned if strategies were
    //initiated outside of the ATI.
    FUNCTION Strategies(account : pAnsiChar) : pAnsiChar;
    stdcall; external 'NtDirect.dll';

    //Gets the position for a strategy. Returns 0 for flat, negative value for
    //short and positive value for long.
    FUNCTION StrategyPosition(strategyId : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Starts a market data stream for the specific instrument. Call the
    //MarketData() function to retrieve prices. Make sure you call the
    //UnSubscribeMarketData() function to close the data stream. A return
    //value of 0 indicates success and -1 indicates an error.
    FUNCTION SubscribeMarketData(instrument : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    //Gets a string of order ids of all profit target orders of an ATM strategy
    //separated by '|'. Internal token id value is used since it is guaranteed to
    //be unique.
    FUNCTION TargetOrders(strategyId : pAnsiChar) : pAnsiChar;
    stdcall; external 'NtDirect.dll';


    //Disconnects the DLL from the NinjaTrader server. A return value of 0
    //indicates success and -1 indicates an error.
    FUNCTION TearDown() : integer;
    stdcall; external 'NtDirect.dll';


    //Stops a market data stream for the specific instrument. A return value of
    //0 indicates success and -1 indicates an error.
    FUNCTION UnsubscribeMarketData(instrument : pAnsiChar) : integer;
    stdcall; external 'NtDirect.dll';


    implementation

    end.
    Last edited by Speedie6; 07-23-2010, 09:16 AM.

Latest Posts

Collapse

Topics Statistics Last Post
Started by cocoescala, 10-12-2018, 11:02 PM
7 responses
939 views
0 likes
Last Post Jquiroz1975  
Started by oviejo, Today, 12:28 AM
1 response
11 views
0 likes
Last Post NinjaTrader_Gaby  
Started by geddyisodin, Yesterday, 05:20 AM
7 responses
46 views
0 likes
Last Post NinjaTrader_Gaby  
Started by gbourque, Today, 06:39 AM
2 responses
5 views
0 likes
Last Post gbourque  
Started by cre8able, Yesterday, 07:24 PM
1 response
13 views
0 likes
Last Post NinjaTrader_ChelseaB  
Working...
X