API Support Forum
OEC API > API Support > New to the API, need some guidance
Author Topic: New to the API, need some guidance
(5 messages, Page 1 of 1)
Moderators: VPfau
JAstrahan
Posts: 3
Joined: Sep 01, 2020


Posted: Nov 19, 2020 @ 07:48 PM             Msg. 1 of 5
I'm looking to trade with the API for trading futures. I have found a library here (https://pypi.org/project/gcapi-python/), since I prefer to use Python.

1.) Will this library allow me to trade futures? (I'm not sure since it mentions forex only)

2.) If not, what can I use to trade futures?

3.) I was told that when I'm doing testing that it will NOT trigger against the live server until I'm approved? How does this approval process work exactly? Do I start by programming something using their demo servers? What are the demo servers? How do I know what credentials to use for the demo servers? I have a developer account, which is what I'm using to connect to this forum, is this the credentials I use?

4.) I have a live trading account currently that is funded. Currently I am using Tradingview to do my strategies. I set alerts there which trigger http requests to an API server on Microsoft Azure. From there I have it processing whether to do orders or not, hopefully with the API in python, but if need be I can write a Serverless function in c# as well. My goal is to have Tradingview alerts trigger buy/sell's against my gain futures account automatically. Are there any problems with this that you foresee?.

4a.) To be crystal clear since there was a lot of confusion when I talked to support about this, I already have the Tradingview connected to my gain for MANUAL trading. I do this all the time daily. My goal is to sidestep this entirely and let the automated strategies I wrote in Tradingview (pinescript) trigger alerts that then run code on a Microsoft Serverless Function which in turn calls the gain API to place orders buy or sell etc...

Let me know if I'm even in the right place for doing this, what downfalls I may run into or if this seems like an okay strategy to pursue?

Thank you for taking the time to respond back. I apologize about all the questions. I greatly appreciate any help you can give me!
VPfau
Moderator
Posts: 154
Joined:


Posted: Nov 20, 2020 @ 08:36 AM             Msg. 2 of 5
Hello JAstrahan,

We do not support python. I would recommend to contact the library's authors

Thank you
Vitaliy Pfau
JAstrahan
Posts: 3
Joined: Sep 01, 2020


Posted: Nov 20, 2020 @ 02:32 PM             Msg. 3 of 5
Can you please help with the other points, I want to be clear, python is NOT required. I can program in C# just fine. As for that library I should not have started the question off with that, I will contact their authors. The other questions are critically important to find answers.
Edited by JAstrahan on Nov 20, 2020 02:33 PM
Edited by JAstrahan on Nov 20, 2020 02:39 PM
VPfau
Moderator
Posts: 154
Joined:


Posted: Nov 20, 2020 @ 02:40 PM             Msg. 4 of 5
I don't see any issue to do automated trading thru the API. The only thing - you need to specify automated trades.
I'll ask our customer service answer the rest of questions

Thanks
Vitaliy Pfau
JAstrahan
Posts: 3
Joined: Sep 01, 2020


Posted: Nov 21, 2020 @ 05:22 AM             Msg. 5 of 5
Alright, please let me know as soon as you can. I'm programming this for myself but also a group of investors. The entire process to get started has been quite complicated for me.

With other API's you simply supply an API key and you can call a command like place.order(symbol_id,contract_amount) and an order would be placed.

To place an order here, it looks like I need to do something like this:

gfClient.Connection.Aggregate.Connect(
new ConnectionContextBuilder()
.WithUserName("username")
.WithPassword("password")
.WithPort(9210)
.WithHost("api.gainfutures.com")
.WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86")
.WithForceLogin(true)
.Build());


The username and password to use her is not very clear though as I mentioned in my previous question, and how can I test my automated strategy if I'm now allowed to test on the live OR demo server?

To eventually place an order once I figure out how the login details work, looks like I'll do something like below, correct?

private static void PlaceOrder(GF.Api.IGFClient client, GF.Api.Contracts.IContract contract, OrderSide orderSide, double limitPrice, string comments)
{
if (client.Orders.Get().Count == 0 || client.Orders.Get().Last().IsFinalState)
{
OrderDraft orderDraft = new OrderDraftBuilder()
.WithAccountID(client.Accounts.Get().First().ID)
.WithContractID(contract.ID)
.WithSide(orderSide)
.WithOrderType(OrderType.Limit)
.WithPrice(limitPrice)
.WithQuantity(1)
.WithEnd(DateTime.UtcNow.AddMinutes(1))
.WithComments(comments)
.Build();
IReadOnlyList validationErrors = client.Orders.Drafts.Validate(orderDraft);
if (validationErrors.Any())
{
Console.WriteLine($"ERROR. Order {orderSide} {orderDraft.Quantity} {contract.Symbol} @ {contract.PriceToString(limitPrice)} Limit is invalid:");
foreach (var error in validationErrors)
Console.WriteLine($"\t{error.Message}");
}
else
{
GF.Api.Orders.IOrder order = client.Orders.SendOrder(orderDraft);
Console.WriteLine($"Order {order} was sent");
}
}
}


Hopefully this is the equivalent of me calling an API to do the buy/sell orders. Please let me know thanks!