示例#1
0
def TransactionsTransactionDetails(access_token, accountID, transactionID):
    'Get the details of a single Account Transaction.'
    r = transactions.TransactionDetails(accountID=accountID,
                                        transactionID=transactionID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#2
0
def InstrumentsPositionBook(access_token, instrument, params):  # check
    'Get positionbook data for a specified Instrument.'
    r = instruments.InstrumentsPositionBook(instrument=instrument,
                                            params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#3
0
def TradesTradeClientExtensions(access_token, accountID, tradeID, data=None):
    'Update the Client Extensions for a Trade. Do not add, update or delete the Client Extensions if your account is associated with MT4.'
    r = trades.TradeClientExtensions(accountID=accountID,
                                     tradeID=tradeID,
                                     data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#4
0
def TransactionsTransactionIDRange(access_token,
                                   accountID,
                                   params=None):  # check
    'Get a range of Transactions for an Account based on Transaction IDs.'
    r = transactions.TransactionIDRange(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#5
0
def TransactionsTransactionsSinceID(access_token,
                                    accountID,
                                    params=None):  # check
    'Get a range of Transactions for an Account starting at (but not including) a provided Transaction ID.'
    r = transactions.TransactionsSinceID(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#6
0
def PositionsPositionClose(access_token, accountID, instrument, data=None):
    'Closeout the open Position regarding instrument in an Account.'
    r = positions.PositionClose(accountID=accountID,
                                instrument=instrument,
                                data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#7
0
    def trade(self, prediction, latest_value):
        """
        Perform a trade, using the prediction given by the predictor.
        Calls prepare_trade method to make decisions, then uses API
        to request trade.
        Args:
            prediction: Predicted value that target currency of instrument
                will have in the future. How much time in the future is defined 
                by predictor.
            latest_value: Latest value of instrument.            
        """
        self.update_position(latest_value)
        buy_or_sell_allowed, amount = self.prepare_trade(
            latest_value, prediction)
        if buy_or_sell_allowed:
            units = self.to_units(amount)
        else:
            print(
                f"Can not buy or sell {amount} of {self.instrument}. Returning.."
            )
            return

        data = MarketOrder
        data['order']['units'] = units
        data['order']['instrument'] = self.instrument
        data['order']['timeInForce'] = "FOK"

        filter_dict(data)

        print(readable_output(data))
        try:
            OrdersOrderCreate(self.access_token, self.accountID, data=data)
            print("Bought ", units, " ", self.instrument, " value of trade: ",
                  units * latest_value)
        except Exception as e:
            print("Order was NOT accepted, value of trade: ",
                  units * latest_value)
            print("Error: ", e)
示例#8
0
def TransactionsTransactionList(access_token, accountID, params=None):  # check
    'Get a list of Transactions pages that satisfy a time-based Transaction query.'
    r = transactions.TransactionList(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#9
0
def OrdersOrderCreate(access_token, accountID, data=None):
    'Create an Order for an Account.'
    r = orders.OrderCreate(accountID=accountID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#10
0
def OrdersOrdersPending(access_token, accountID):
    'List all pending Orders in an Account.'
    r = orders.OrdersPending(accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#11
0
def OrdersOrderDetails(access_token, accountID, orderID):
    'Get details for a single Order in an Account.'
    r = orders.OrderDetails(accountID=accountID, orderID=orderID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#12
0
def AccountList(access_token):  # check
    'Get a list of all Accounts authorized for the provided token.'
    r = accounts.AccountList()
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#13
0
def ForexlabsAutochartist(access_token, params=None):  # check
    'Get the ‘autochartist data’.'
    r = forexlabs.Autochartist(params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#14
0
def OrdersOrderReplace(access_token, accountID, orderID, data=None):
    'Replace an Order in an Account by simultaneously cancelling it and creating a replacement Order.'
    r = orders.OrderReplace(accountID=accountID, orderID=orderID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#15
0
def AccountDetails(access_token, accountID):  # check
    'Get the full details for a single Account that a client has access to. Full pending Order, open Trade and open Position representations are provided.'
    r = accounts.AccountDetails(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#16
0
def TradesOpenTrades(access_token, accountID):  # check
    'Get the list of open Trades for an Account.'
    r = trades.OpenTrades(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#17
0
def TradesTradeCRCDO(access_token, accountID, tradeID, data=None):
    'Trade Create Replace Cancel Dependent Orders.'
    r = trades.TradeCRCDO(accountID=accountID, tradeID=tradeID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#18
0
def PricingPricingInfo(access_token, accountID, params=None):
    'Get pricing information for a specified list of Instruments within an account.'
    r = pricing.PricingInfo(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#19
0
def PositionsPositionList(access_token, accountID):  # check
    'List all Positions for an Account. The Positions returned are for every instrument that has had a position during the lifetime of the Account.'
    r = positions.PositionList(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#20
0
def PositionsPositionDetails(access_token, accountID, instrument):
    'Get the details of a single instrument’s position in an Account. The position may be open or not.'
    r = positions.PositionDetails(accountID=accountID, instrument=instrument)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#21
0
def AccountChanges(access_token, accountID, params=None):  # check
    'Endpoint used to poll an Account for its current state and changes since a specified TransactionID.'
    r = accounts.AccountChanges(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#22
0
def OrdersOrderClientExtensions(access_token, accountID, orderID, data=None):
    'Update the Client Extensions for an Order in an Account. Warning: Do not set, modify or delete clientExtensions if your account is associated with MT4.'
    r = orders.OrderClientExtensions(accountID, orderID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#23
0
def AccountConfiguration(access_token, accountID, data=None):  # check
    'Set the client-configurable portions of an Account.'
    r = accounts.AccountConfiguration(accountID=accountID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#24
0
def TradesTradeDetails(access_token, accountID, tradeID):
    'Get the details of a specific Trade in an Account.'
    r = accounts.TradeDetails(accountID=accountID, tradeID=tradeID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#25
0
def AccountInstruments(access_token, accountID, params=None):  # check
    'Get the list of tradable instruments for the given Account. The list of tradeable instruments is dependent on the regulatory division that the Account is located in, thus should be the same for all Accounts owned by a single user.'
    r = accounts.AccountInstruments(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#26
0
def TradesTradesList(access_token, accountID, params=None):
    'Get a list of trades for an Account.'
    r = trades.TradesList(accountID=accountID, params=params)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#27
0
def AccountSummary(access_token, accountID):  # check
    'Get a summary for a single Account that a client has access to.'
    r = accounts.AccountSummary(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#28
0
def OrdersOrderList(access_token, accountID):
    'Get a list of orders for an account'
    r = orders.OrderList(accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#29
0
def TradesTradeClose(access_token, accountID, tradeID, data=None):
    'Close (partially or fully) a specific open Trade in an Account.'
    r = trades.TradeClose(accountID=accountID, data=data)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)
示例#30
0
def PositionsOpenPosition(access_token, accountID):  # check
    'List all open Positions for an Account. An open Position is a Position in an Account that currently has a Trade opened for it.'
    r = positions.OpenPositions(accountID=accountID)
    client = API(access_token=access_token)
    client.request(r)
    return readable_output(Munch(r.response)), Munch(r.response)