Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/SimpleSamples/AskBidACCInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from tradelocker import TLAPI
import pandas as pd
from datetime import datetime

# Initialize the TradeLocker API client with your credentials
tl_api = TLAPI(
environment="https://demo.tradelocker.com",
username="[email protected]",
password="yourpassword",
server="yourBrokerPropFirm"
)

pair = input('Pair: ').strip().upper()

# Get the instrument ID
pair_id = tl_api.get_instrument_id_from_symbol_name(pair)

# Get price information
price = tl_api.get_latest_asking_price(pair_id)
acc_info = tl_api.get_account_state()
balance = acc_info['balance']
actual_balance = acc_info['availableFunds']
ask = tl_api.get_latest_asking_price(pair_id)
bid = tl_api.get_latest_bid_price(pair_id)


def acc_info():
print('Pair Price: ', str(price), '\nBalance: ', str(balance), '\nActual Balance: ', actual_balance, '\nAsk: ', str(ask), 'Bid: ', str(bid))


def main():
acc_info()

if __name__ == "__main__":
main()
58 changes: 58 additions & 0 deletions examples/SimpleSamples/lastCandleInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from tradelocker import TLAPI
import pandas as pd
from datetime import datetime

def get_last_candle_details():
# Initialize the API client with your credentials
tl = TLAPI(environment="https://demo.tradelocker.com",
username="[email protected]",
password="somepassword",
server="yourBrokerProfirm")

# Specify the instrument you're interested in
instrument_name = "BTCUSD" # Change this to your desired instrument

# Get the instrument ID
instrument_id = tl.get_instrument_id_from_symbol_name(instrument_name)

# Fetch the price history for the instrument
price_history = tl.get_price_history(instrument_id, resolution="1D", start_timestamp=0, end_timestamp=0, lookback_period="5D")

# Convert the price history to a DataFrame for easier manipulation
df = pd.DataFrame(price_history)

# Rename the first column to 'unix_timestamp_millis' for clarity
df.rename(columns={df.columns[0]: 'unix_timestamp_millis'}, inplace=True)

# Convert the millisecond timestamps to datetime objects
df['datetime'] = pd.to_datetime(df['unix_timestamp_millis'], unit='ms')

# Sort the DataFrame by the new 'datetime' column in descending order
df_sorted = df.sort_values(by='datetime', ascending=False)

# Access the first row of the sorted DataFrame, which should now be the last candle
last_candle_row = df_sorted.iloc[0]

# Extracting the candle details
timestamp = last_candle_row['datetime']
date_time = timestamp.strftime('%Y-%m-%d %H:%M:%S') # Format the datetime object as a string
open_price = last_candle_row['o']
close_price = last_candle_row['c']
low_price = last_candle_row['l']
high_price = last_candle_row['h']

return {
"Date": date_time,
"Time": date_time.split(' ')[1], # Extract just the time part
"Open": open_price,
"Close": close_price,
"Low": low_price,
"High": high_price
}

# Print the last candle details
result = get_last_candle_details()
if result:
print(result)
else:
print("Failed to retrieve the last candle details.")